SA-MP Forums Archive
Local & Global 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)
+--- Thread: Local & Global timers (/showthread.php?tid=589034)



Local & Global timers - xClown - 14.09.2015

I wonder,
When use a global timer, and when use a local timer?

What's a local timer? What's a global timer?


Re: Local & Global timers - xClown - 14.09.2015

Someone explain me this?


Re: Local & Global timers - sanamalik400 - 15.09.2015

..maybe no good scripters online now..i m also waiting for help :P


AW: Local & Global timers - Kaliber - 15.09.2015

...there exist no local timers...but i think i know what you mean.

Look you can run a timer for every player like:

PHP код:
//Under OnPlayerConnect:
SetTimerEx("PlayerTimer",999,1,"i",playerid); 
This timer would run for every player...

A global timer is sth like this:

PHP код:
//Under OnGameModeInit
SetTimer("ForAll",999,1);
forward ForAll();
public 
ForAll()
{
    for(new 
ii<MAX_PLAYERSi++)
    {
         
//here the code
    
}

So you see..the global timer handels all players in one timer..so you dont need 500 timers..only 1


Re: Local & Global timers - Scenario - 15.09.2015

Just remember that if you run too many timers, it's going to cause some optimization problems. Don't have a global timer that runs every 5 seconds and does a MAX_PLAYERS or MAX_VEHICLES loop. And if for some stupid reason you ARE doing that- use y_iterate (foreach) and y_timers. I use y_timers on my own mode and while switching to that as opposed to SetTimer() may be daunting at first- don't fret; it's a lot better!