[Tutorial] Using Timers
#1

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
pawn Code:
forward 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;
pawn Code:
public Restart()
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
Reply
#2

who want to restart their server for every hour lol
btw nice tutorial
Reply
#3

Nice tut easy to understand. Helped me!
Reply
#4

Quote:
Originally Posted by newbienoob
View Post
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
View Post
Nice tut easy to understand. Helped me!
Any time!
Reply
#5

+rep mate that was really handy and simple
Reply
#6

Nice and short tutorial.
Well, one suggestion : add SetTimerEx to the tutorial.
Reply
#7

Quote:
Originally Posted by Basicz
View Post
add SetTimerEx to the tutorial.
4 char.
Reply
#8

I'd have to test TimerEx and learn it. Ive never used it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)