Hello there, i need some help. How can i make it when a function is ran that it will count time and then do something. For Example. When a player joins team ZOMBIE the server will count for 15 minutes then in 15 minutes the server will change the players team to SURVIVOR. <-- I just need to know how to do the 15 minute timer :)
I thought of using a timer.Create but i feel that will put to much pressure on the server of 32 players.
Just check against the server's current time. [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/CurTime]Global.CurTime[/url]
[lua]
local mins = CurTime() + 900
if CurTime() >= mins then
//do stuff
end
[/lua]
Something along those lines. Keep in mind the code I provided is just pseudo-code.
[code]
timer.Simple(60*15, function()
-- Do stuffs
end)
[/code]
Even simpler, this timer counts 60 seconds times 15, aka 15 minutes, and then runs the function.
[QUOTE=whitestar;48693348][code]
timer.Simple(60*15, function()
-- Do stuffs
end)
[/code]
Even simpler, this timer counts 60 seconds times 15, aka 15 minutes, and then runs the function.[/QUOTE]
It's better timer create beacouse you can destroy the timer.
Example: player disconnects before the timer is finished, so you destroy it, but if you don't it will give a lua error
[editline]16th September 2015[/editline]
But this method is still better
[QUOTE=Cheese_3;48692765]Hello there, i need some help. How can i make it when a function is ran that it will count time and then do something. For Example. When a player joins team ZOMBIE the server will count for 15 minutes then in 15 minutes the server will change the players team to SURVIVOR. <-- I just need to know how to do the 15 minute timer :)
I thought of using a timer.Create but i feel that will put to much pressure on the server of 32 players.[/QUOTE]
[QUOTE=geferon;48694535]Example: player disconnects before the timer is finished, so you destroy it, but if you don't it will give a lua error[/QUOTE]
No, you don't need to do that. All you need to do is wrap your code around an [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/IsValid]Global.IsValid[/url] check on the player.
Agreed, if the player leaves whilst the timer is running, the player is not valid anymore and therefore stops the function & kills the timer.
Sorry, you need to Log In to post a reply to this thread.