×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Script Requests
« ‹ 160 / 160
Script Requests
Tiizuxz
« Citoyen »
1645135260000
    • Tiizuxz#3506
    • Profil
    • Derniers messages
    • Tribu
#3181
  0
Can you guys do it when I write !map it gives me a random map?
King_seniru
« Censeur »
1645168620000
    • King_seniru#5890
    • Profil
    • Derniers messages
    • Tribu
#3182
  1
Documentation
Documentation a dit :

tfm.exec.newGame( mapCode, flipped )

    - mapCode (String) : the map code (default value = nil)
    - nil (a random map)
    - 6 (vanilla map)
    - @42583 (editor map)
    - #4 (perm category map)
    - anything beginning with '<' (xml map)




You can do this
Code Lua

1
2
3
4
5
eventChatCommand = function(name, command)
if command == "map" then
tfm.exec.newGame() -- same as doing tfm.exec.newGame(nil) which would give you a random map
end
end
Tiizuxz
« Citoyen »
1645223280000
    • Tiizuxz#3506
    • Profil
    • Derniers messages
    • Tribu
#3183
  0
King_seniru a dit :
Documentation
Documentation a dit :

tfm.exec.newGame( mapCode, flipped )

    - mapCode (String) : the map code (default value = nil)
    - nil (a random map)
    - 6 (vanilla map)
    - @42583 (editor map)
    - #4 (perm category map)
    - anything beginning with '<' (xml map)




You can do this
Code Lua

1
2
3
4
5
eventChatCommand = function(name, command)
if command == "map" then
tfm.exec.newGame() -- same as doing tfm.exec.newGame(nil) which would give you a random map
end
end

It doesn't work it gives me just the map #0.
King_seniru
« Censeur »
1645258440000
    • King_seniru#5890
    • Profil
    • Derniers messages
    • Tribu
#3184
  1
Sorry I forgot it doesn't really work in tribe houses. The script below will load a random map from a random category instead. Not sure if there's a better way for it, but if so tell me :P
Code Lua

1
2
3
4
5
6
7
local permCats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 18, 19, 21, 22, 23, 24, 32, 38, 41, 42, 87 }

eventChatCommand = function(name, command)
if command == "map" then
tfm.exec.newGame("#" .. permCats[math.random(#permCats)])
end
end

Dernière modification le 1645287900000
Missdilan
« Citoyen »
1645443840000
    • Missdilan#3234
    • Profil
    • Derniers messages
#3185
  0
How to make mouse speedometer?
King_seniru
« Censeur »
1645457760000
    • King_seniru#5890
    • Profil
    • Derniers messages
    • Tribu
#3186
  1
Use tfm.get.room.playerList[name].vx and tfm.get.room.playerList[name].vy and update the display in event loop
Kerberos
« Censeur »
1650716940000
    • Kerberos#4278
    • Profil
    • Derniers messages
    • Tribu
#3187
  0
Hi! I have three questions:
1) How can I make an event happen if a key is pressed double?
2) How can I set time to use a command?
3) How can I make someone use a command once a day or only once?
King_seniru
« Censeur »
1650789420000
    • King_seniru#5890
    • Profil
    • Derniers messages
    • Tribu
#3188
  2
a dit :
1) How can I make an event happen if a key is pressed double?


Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
do
local keyPresses = {}

function eventKeyboard(name, key, down, x, y)
if down then -- should avoid dealing with key releases to detect double presses
if not keyPresses[name] then -- setting up data if not present
keyPresses[name] = { [key] = os.time() }
elseif not keyPresses[name][key] then
keyPresses[name][key] = os.time()
else -- a press happened after registering another press
-- so we check if that press happened within a short time period so we can classify it as a double press
if os.time() - keyPresses[name][key] < 300 then
keyPresses[name][key] = nil
_G["eventKeyDoublePressed"](name, key, down, x, y)
else
-- if not just register it as the latest press
keyPresses[name][key] = os.time()
end
end
end
end
end

function eventKeyDoublePressed(name, key, down, x, y)
print({name, key, x, y, down})
-- your TODOs
end


a dit :

2) How can I set time to use a command?

Can you specify more with an example scenario

a dit :

3) How can I make someone use a command once a day or only once?

Not sure how you used to handle commands usually, but I think this would need a more sophisticated way to deal with stuff with ease later. Here's something I'd do


Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local string_split = function(s, delimiter)
result = {}
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end

local chatCmds = {} -- this is our table with all the metadata about our commands

-- you can register a command by simply doing
--[[
chatCmds.cmdName = {
f = function()
-- command's function body
end,
limitOnce = true -- set this to true if it's one use, false otherwise
}
]]

chatCmds.foo = { -- !foo fjaiofjioa fjaiofjaio fjaiofj fajiofja
f = function(name, args)
print(args)
end,
limitOnce = true,
_usedBy = {}
}

chatCmds.bar = { -- !bar fjaiofjqa fjiaofja fjiaof
f = function(name, args)
print("Not limited to one use")
end
}

function eventChatCommand(name, cmd)
local args = string_split(cmd, " ")
if chatCmds[args[1]] then
local cmd = chatCmds[args[1]]
if not cmd then return end
if not cmd._usedBy then cmd._usedBy = {} end
if cmd.limitOnce and cmd._usedBy[name] then return end
table.remove(args, 1)
if cmd.f then cmd.f(name, args) end
cmd._usedBy[name] = true
end
end


Like I said this is just a simple way I might use for something like this. All you need to do is to flag if a player used that command and check it the next time.
Feel free to use this same logic in the code you have rn without replacing the entire thing with this

Dernière modification le 1650789540000
Kerberos
« Censeur »
1650835740000
    • Kerberos#4278
    • Profil
    • Derniers messages
    • Tribu
#3189
  0
@King_seniru
Thanks for your answers ^^
And about the 2nd question, it is something like some Discord bots' vote command (which make us able to vote or do something else each 12 hours etc.) but what I had in my mind doesn't look nice at all anymore. I would like to learn how to set 30 seconds waiting time though
(Also sorry for my awful explanation lol)
King_seniru
« Censeur »
1650866520000
    • King_seniru#5890
    • Profil
    • Derniers messages
    • Tribu
#3190
  3
Oh I see, you can do something similar for what we did with one-time use commands. I'm just gonna extend my previous example a bit for this one. You can get the idea from that and implement it your own way I guess.


Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local string_split = function(s, delimiter)
result = {}
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end

local chatCmds = {} -- this is our table with all the metadata about our commands

-- you can register a command by simply doing
--[[
chatCmds.cmdName = {
f = function()
-- command's function body
end,
limitOnce = true -- set this to true if it's one use, false otherwise,
wait = 0 -- wait time in milliseconds
}
]]

chatCmds.foo = { -- !foo fjaiofjioa fjaiofjaio fjaiofj fajiofja
f = function(name, args)
print(args)
end,
_usedBy = {},
wait = 3000
}

function eventChatCommand(name, cmd)
local args = string_split(cmd, " ")
if chatCmds[args[1]] then
local cmd = chatCmds[args[1]]
if not cmd then return end
if not cmd._usedBy then cmd._usedBy = {} end
cmd._usedBy[name] = cmd._usedBy[name] or 0
if (cmd.limitOnce and cmd._usedBy[name]) or (cmd.wait and cmd._usedBy[name] < os.time()) then return end -- IMPORTANT
table.remove(args, 1)
if cmd.f then cmd.f(name, args) end
-- IMPORTANT v
cmd._usedBy[name] = os.time() + (cmd.wait or 0) -- we change this to timestamp, so we can handle it in the way you want
end
end


Didn't test this time, but it should work (please), even if didn't work, get the idea from the lines I have highlighted.
Mehdi
« Citoyen »
1678458300000
    • Mehdi#7317
    • Profil
    • Derniers messages
    • Tribu
#3191
  0
can you program a bot (the bot dont attractive with other player make it just stopped charachter)
and want it dressing that 251;0,0,0,73,0,0,0,0,0
if you can pls do it
Inkwaled
« Citoyen »
1679861100000
    • Inkwaled#4171
    • Profil
    • Derniers messages
    • Tribu
#3192
  0
Shamousey a dit :
If you want a certain script to be created but don't know how to do it yourself, feel free to ask for it in this thread, and make sure you specify exactly what you want. Someone who knows what they're doing will hopefully come to this thread and help develop it for you.

Please check that your request hasn't already been posted in this thread first. Topic-451991
Night_wolf
« Citoyen »
1681512180000
    • Night_wolf#8965
    • Profil
    • Derniers messages
    • Tribu
#3193
  0
Mehdi a dit :
can you program a bot (the bot dont attractive with other player make it just stopped charachter)
and want it dressing that 251;0,0,0,73,0,0,0,0,0
if you can pls do it

tfm.exec.addNPC("Name", { title = 1, x = 100, y = 305, look = "251;0,0,0,73,0,0,0,0,0", female = false, lookAtPlayer = true})

Dernière modification le 1706547300000
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Script Requests
« ‹ 160 / 160
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27