[Tutorial] Using Timers - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Using Timers (
/showthread.php?tid=324311)
Using Timers -
SnG.Scot_MisCuDI - 09.03.2012
Okay, so at first I was a little confused with timers. But soon i figured it out. They are actually really simple.
Lets say you want the server to restart by itself every 1 hour. This is how you would do it.
1. Forward the timer. At the top of your script put forward
timerName(); So i will name it Restart
2. Now under OnGameModeInit we will start the timer when the GM starts.
SetTimer("name", time, repeating);
repeating; true = repeat, false = dont repeat
(the time is in milliseconds)
(Remember capitalization matters)
So in our case it would be;
pawn Code:
SetTimer("Restart",3600000,true);
3600000 milliseconds = 1 hour
true means it will repeat the timer (in this case it wont matter since the timer restarts with the Gamemode)
Ok so the timer is set up. Now we need to tell the timer what to do when it gets to 0.
Any where in the script you have to put public timerName() So;
Now under this you want it to send the Rcon CMD.
pawn Code:
public Restart()
{
SendRconCommand("gmx");
}
After 1 hour the server should restart the GM and then the next hour it will do the same and so on. Any questions/errors? Post a message
Re: Using Timers -
newbienoob - 09.03.2012
who want to restart their server for every hour lol
btw nice tutorial
Re: Using Timers -
HDFord - 09.03.2012
Nice tut easy to understand. Helped me!
Re: Using Timers -
SnG.Scot_MisCuDI - 09.03.2012
Quote:
Originally Posted by newbienoob
who want to restart their server for every hour lol
btw nice tutorial
|
Well it doesnt have to be an hour :P
Quote:
Originally Posted by HDFord
Nice tut easy to understand. Helped me!
|
Any time!
Re: Using Timers -
ninjahippie - 20.03.2012
+rep mate that was really handy and simple
Re: Using Timers -
Basicz - 20.03.2012
Nice and short tutorial.
Well, one suggestion : add SetTimerEx to the tutorial.
Re: Using Timers -
Vince - 20.03.2012
Quote:
Originally Posted by Basicz
add SetTimerEx to the tutorial.
|
4 char.
Re: Using Timers -
SnG.Scot_MisCuDI - 22.03.2012
I'd have to test TimerEx and learn it. Ive never used it