SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 09/03/2012, 02:15 AM   #1
SnG.Scot_MisCuDI
Gangsta
 
SnG.Scot_MisCuDI's Avatar
 
Join Date: Mar 2011
Location: Gilbert, Arizona
Posts: 895
Reputation: 56
Default Using Timers

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
__________________

aka Googamalugafoo
[FS/Tool] Dynamic Biz - Dynamic Bank - FFA DM - Pawno Tool
[Tuts] Map Editor - Nuke - Using Pickups - Timers


SnG.Scot_MisCuDI is offline   Reply With Quote
Old 09/03/2012, 03:47 AM   #2
newbienoob
High-roller
 
newbienoob's Avatar
 
Join Date: Jan 2012
Location: Follow the moaning coming from your parents' bedroom
Posts: 1,562
Reputation: 265
Default Re: Using Timers

who want to restart their server for every hour lol
btw nice tutorial
__________________
Help me, please /a chat
newbienoob is offline   Reply With Quote
Old 09/03/2012, 10:28 AM   #3
HDFord
Big Clucker
 
HDFord's Avatar
 
Join Date: Aug 2011
Location: Grønvollfoss in Norway with a shotgun
Posts: 167
Reputation: 19
Default Re: Using Timers

Nice tut easy to understand. Helped me!
HDFord is offline   Reply With Quote
Old 09/03/2012, 12:39 PM   #4
SnG.Scot_MisCuDI
Gangsta
 
SnG.Scot_MisCuDI's Avatar
 
Join Date: Mar 2011
Location: Gilbert, Arizona
Posts: 895
Reputation: 56
Default Re: Using Timers

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!
__________________

aka Googamalugafoo
[FS/Tool] Dynamic Biz - Dynamic Bank - FFA DM - Pawno Tool
[Tuts] Map Editor - Nuke - Using Pickups - Timers


SnG.Scot_MisCuDI is offline   Reply With Quote
Old 20/03/2012, 10:17 AM   #5
ninjahippie
Big Clucker
 
Join Date: Sep 2011
Posts: 104
Reputation: 1
Default Re: Using Timers

+rep mate that was really handy and simple
__________________


Free apps for smart phones










[/CENTER]
ninjahippie is offline   Reply With Quote
Old 20/03/2012, 10:47 AM   #6
Basicz
Gangsta
 
Basicz's Avatar
 
Join Date: Aug 2010
Location: Indonesia, Surabaya.
Posts: 621
Reputation: 35
Default Re: Using Timers

Nice and short tutorial.
Well, one suggestion : add SetTimerEx to the tutorial.
__________________

- Quina, from the game " Final Fantasy IX "
Basicz is offline   Reply With Quote
Old 20/03/2012, 11:40 AM   #7
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,977
Reputation: 2649
Default Re: Using Timers

Quote:
Originally Posted by Basicz View Post
add SetTimerEx to the tutorial.
4 char.
__________________
Vince is offline   Reply With Quote
Old 22/03/2012, 10:06 PM   #8
SnG.Scot_MisCuDI
Gangsta
 
SnG.Scot_MisCuDI's Avatar
 
Join Date: Mar 2011
Location: Gilbert, Arizona
Posts: 895
Reputation: 56
Default Re: Using Timers

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

aka Googamalugafoo
[FS/Tool] Dynamic Biz - Dynamic Bank - FFA DM - Pawno Tool
[Tuts] Map Editor - Nuke - Using Pickups - Timers


SnG.Scot_MisCuDI is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timers farmer1710 Help Archive 2 22/04/2011 09:31 PM
Timers Czeladnik General 2 17/04/2011 09:54 AM
Timers RichyB Help Archive 2 24/11/2010 11:26 AM
Help with Timers GreenHammy Help Archive 7 03/01/2010 02:13 PM
timers Lajko1 Help Archive 6 09/12/2009 06:19 AM


All times are GMT. The time now is 11:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.