SHOW:
|
|
- or go back to the newest paste.
1 | - | local CooldownTimer = 10 |
1 | + | local CooldownTimer = 10 -- seconds |
2 | - | local str = {}; |
2 | + | local ChatCommand = "#tele" |
3 | - | local ChatPrefix = "#tele" |
3 | + | |
4 | - | function Command(event, pPlayer, msg, _, _) |
4 | + | local CD = {} -- Cooldown store |
5 | - | if (msg:find(ChatPrefix.." ") == 1) then |
5 | + | local function Command(event, pPlayer, msg, _, _) |
6 | - | if str[plr:GetName()] ~= nil and ((os.clock()-str[plr:GetName()])) <= CooldownTimer then |
6 | + | if (msg == ChatCommand) then -- check that the message is our command |
7 | - | pPlayer:SendAreaTriggerMessage("|cFFFF0000You must wait "..CooldownTimer.." Seconds before teleporting again!") |
7 | + | local sPlayer = tostring(pPlayer) -- convert player to a string |
8 | - | else |
8 | + | if CD[sPlayer] and os.clock()-CD[sPlayer] <= CooldownTimer then -- Check if the player has a cooldown and if he has waited enough |
9 | - | str[plr:GetName()] = os.clock() |
9 | + | pPlayer:SendAreaTriggerMessage("|cFFFF0000You must wait "..CooldownTimer.." seconds before teleporting again!") |
10 | - | for _, v in pairs(GetPlayersInWorld()) do |
10 | + | else |
11 | - | pPlayer:Teleport(map, x, y, z) |
11 | + | CD[sPlayer] = os.clock() -- re set the time to the store for the player |
12 | - | end |
12 | + | pPlayer:Teleport(map, x, y, z) |
13 | - | end |
13 | + | end |
14 | - | return false |
14 | + | return false -- prevent the player from saying #tele ingame |
15 | - | end |
15 | + | end |
16 | - | return true |
16 | + | |
17 | ||
18 | RegisterServerHook(16, Command) |