×

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
  • /
  • Cooldown logic
Cooldown logic
Bolodefchoco
« Sénateur »
1537562940000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#1
  5
Just helping people out, i wrote this simple topic to demonstrate a simple cooldown logic
- One cooldown for each player
- Press space

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
local playerData = { } -- Table that has the data of all the players in the room

eventNewPlayer = function(playerName)
-- It could be "playerData[playerName] = 0",
--but you wouldn't be able to use the table for other parts of your system

playerData[playerName] = {
cooldown = 0 -- Default value is 0.
}

system.bindKeyboard(playerName, 32, true, true) -- binds the key 32 (space)
end
-- Creates the table + bind space for the mice in the room
table.foreach(tfm.get.room.playerList, eventNewPlayer)

eventKeyboard = function(playerName, key)
-- Checks if the current time is higher than the cooldown time
if os.time() > playerData[playerName].cooldown then
-- Increase the cooldown time (current time + time you want)
playerData[playerName].cooldown = os.time() + 5000 -- 5000 means 5 seconds. Cooldown of 5 seconds.

print("You pressed space")
end
end

Now you can press space once per 5 seconds!
Bastlase
« Sénateur »
1537670760000
    • Bastlase#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  0
Nice !
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Cooldown logic
© Atelier801 2018

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

Version 1.27