SA-MP Forums Archive
Best way to use 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: Best way to use timers? (/showthread.php?tid=421898)



Best way to use timers? - PaulDinam - 11.03.2013

I have about 7 timers for example:
when players gets ajailed a timer will start.
When player is pausing.
Paydaytimer
licenseexam timer and more..

Should I use the timers ongamemode?
I really hate timers because i've heard they're lagging the server..


Re: Best way to use timers? - LetsOWN[PL] - 11.03.2013

Hello.
A lotta players does the most stupid thing ever for me..
They makes invidual timers for everything..
SetTimer("pissing"..,
SetTimer("fapfaping..
And so on..

The best thing I could recommend you is to make ONE timer which will repeat EVERY ONE SECOND.

pawn Код:
SetTimer("GlobalTimer", 1000, 0);
Now you can do a lotta thing, such as:
pawn Код:
public GlobalTimer()
{
    for(new i = 0; i != MAX_PLAYERS; i++)
    {
        if(Player[i][Jailed] > 0)
            Player[i][Jailed]--;
        if(Player[i][Jailed] == 1)
            UnjailPlayer(i);
           
        new currentTime;
        currentTime = gettime();
        if(currentTime == Player[i][VIPExpired])
            unVIP(i);
    }
   
    if(Countdown > 0)
    {
        Countdown--;
        updateCountDownTD();
    }
   
    if(Countdown == 0)
    {
        sendStartMessage();
        Countdown = -1;
    }
}
And basically - everything you want.

Any problems? Text here.

Greetz,
LetsOWN



Re: Best way to use timers? - PaulDinam - 11.03.2013

But if this timer will include lot of stuff, it won't lag?
And if I want timer of 30 minutes? not 1 second


Re: Best way to use timers? - Sinner - 11.03.2013

@LetsOWN[PL]

That is possibly the worst thing you could do. If you check everyone every 1 seconds, given that there are enough players, the server will have a lag spike every 1 second because there is absolutely no load distribution.

Using a timer per-player will induce less lag, as long as they are not executed all at the same time.

Quote:
Originally Posted by PaulDinam
Посмотреть сообщение
Should I use the timers ongamemode?
I really hate timers because i've heard they're lagging the server..
Source? Don't blindly believe what people tell you. As long as you don't go crazy (very tiny intervals and very cpu-intensive code) I see no reason why timers would cause lag.


Re: Best way to use timers? - LetsOWN[PL] - 11.03.2013

Quote:

If you check everyone every 1 seconds, given that there are enough players, the server will have a lag spike every 1 second because there is absolutely no load distribution.

Unless there is not a lot of complicated stuff
Of course you can make 2 timers: one with refresh rate of 1 s and second with refresh rate of mby 30 seconds?
You can put more complicated stuff in this second one, and less complicated in 1 one.

It makes a sense now, doesnt it?

Greetz,
LetsOWN



Re: Best way to use timers? - mineralo - 11.03.2013

if you need timer for ony person/player then use
https://sampwiki.blast.hk/wiki/SetTimerEx


Re: Best way to use timers? - Sinner - 11.03.2013

Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение

Unless there is not a lot of complicated stuff
Of course you can make 2 timers: one with refresh rate of 1 s and second with refresh rate of mby 30 seconds?
You can put more complicated stuff in this second one, and less complicated in 1 one.

It makes a sense now, doesnt it?

Greetz,
LetsOWN
Now you will have lag spikes every 30 seconds. Problem solved? I don't think so.