Best way to use timers?
#1

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..
Reply
#2

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
Reply
#3

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

@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.
Reply
#5

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
Reply
#6

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)