Yunix Posted May 19, 2014 Share Posted May 19, 2014 Could somebody explain me how to make unique timers? Like, i want to create a timer but only for that person that goes trough the function, so if multiple people go trough that function and also are going to get that timer i can kill the timers separately. So when the timer is assigned to a variable i don't want to kill all the timers but only the one that i need to kill. Link to comment
csiguusz Posted May 19, 2014 Share Posted May 19, 2014 Store the timers in a table for example. local timers = {} function doSomething ( player ) if isTimer ( timers[ player ] ) then killTimer ( timers[ player ] ) end timers[ player ] = setTimer ( ... ) end Link to comment
Yunix Posted May 19, 2014 Author Share Posted May 19, 2014 Got a new question, is it possible to store multiple functions inside the table assigned to the player? Like vehicles, timers, colsphere's etc Link to comment
.:HyPeX:. Posted May 19, 2014 Share Posted May 19, 2014 This should answer your question: local PunishLevels = { function(player) --[[ Level 1 Punish (Just Warn) ]] outputChatBox("You have been warned for spamming, Please dont spam!", player, 255,255,255) end, function(player) --[[ Level 2 Punish (Second Warning) ]] outputChatBox("You have been warned for spamming again, Please dont spam!", player, 255,255,255) end, function(player) --[[ Level 3 Punish (Third Warning) ]] outputChatBox("You have been warned for spamming for the third time!, Please dont spam!", player, 255,255,255) end, function(player) --[[ Level 4 Punish (Mute Short time) ]] MutePlayer(player,600, "AntiSpam", "4th Level Punish") end } Then just calling the function with the assigned player in my case: PunishLevels[PunishLevel](player) --EG: PunishLevels[2](player) Link to comment
csiguusz Posted May 19, 2014 Share Posted May 19, 2014 Yes, every player can have his own table with his own datas of any kind. local data = {} addEventHandler ( "onPlayerJoin", root, function () data [ source ] = {} end ) function setThings ( player ) data[ player ].vehicle = createVehicle ( ... ) data[ player ].timer1 = setTimer ( ... ) data[ player ].timer2 = setTimer ( ...) data[ player ].likes = "Trains" end addEventHandler ( "onPlayerQuit", root, function () data [ source ] = nil -- don't forget to clear a player's data after quitting to save memory and even kill his timers if needed end ) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now