SA-MP Forums Archive
optimize timer - 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: optimize timer (/showthread.php?tid=366340)



optimize timers? - Kyra - 06.08.2012

Hello, I have a question for the timers i want optimize my timers for the players, I explain

I thought doing 1 timer for all the functions needed with timer. But the question is: Is it better to use a single timer with all or more timers?

Another question:
It is better to use timestamp to compare the time in a timer, or use a variable that increments?


Re: optimize timer - Jikesh - 06.08.2012

I think many people use AllInOneTimer


Re: optimize timer - SuperViper - 06.08.2012

Quote:
Originally Posted by Jikesh
Посмотреть сообщение
I think many people use AllInOneTimer
He didn't ask what many people do, he asked which would be the better way.

On topic:

Using separate timers which have a slight (or huge) time difference is better because in the time between the timers, other actions can be performed (sync).

@ Your second question, I'm not sure what you mean by that,


Re: optimize timer - ReneG - 06.08.2012

To answer the second question, yes. Use gettime().
pawn Код:
new gHealReload[MAX_PLAYERS];

CMD:healme(playerid, params[])
{
    if(gettime() < gHealReload[playerid]) {
        return SendClientMessage(playerid, -1, "You can only heal yourself every two minutes!");
    }
   
    else {
        gHealReload[playerid] = gettime() + 120; // Add 120 seconds to it (2 minutes)
        SetPlayerHealth(playerid, 100.0);
        SendClientMessage(playerid, -1, "You have healed yourself!");
    }
    return 1;
}
Tested


Re : optimize timer - Kyra - 06.08.2012

Thanks all !

But the second question I will explain with codes

1)

PHP код:
new Vtime;// On Top GM
1secondTimer()
{
     
VTime++;
     If(
Vtime >= 5)
     {
       
Vtime 0;
       
//code....
     
}
     return 
1;

2)
PHP код:
new VTime = -1;
Vtime gettime();
 
1secondTimer()
{
     if(
Vtime 0  && Vtime gettime() - 5)
     {
       
Vtime = -1;
       
// code....
     
}
     return 
1;

What is the best for optimize my timer? Or it is the same?

Sorry for my english


Re: optimize timer - Vince - 06.08.2012

More timers with different intervals with small bits of code is better than one big timer with lots of code in terms of sync. The server can only do one thing at a time, so while it is executing the timer it is not syncing players.


Re : optimize timer - Kyra - 06.08.2012

The CPU usage stays the same?

And for this question please

Quote:

Thanks all !

But the second question I will explain with codes

1)

PHP код:
new Vtime;// On Top GM
1secondTimer()
{
     
VTime++;
     If(
Vtime >= 5)
     {
       
Vtime 0;
       
//code....
     
}
     return 
1;

2)
PHP код:
new VTime = -1;
Vtime gettime();
 
1secondTimer()
{
     if(
Vtime 0  && Vtime gettime() - 5)
     {
       
Vtime = -1;
       
// code....
     
}
     return 
1;

What is the best for optimize my timer? Or it is the same?

Sorry for my english




Re : optimize timer - Kyra - 06.08.2012

UP

I have another question

If example, i use separate timers create a pickup for calculate the time to delete this. If i want optimize the timer it would be nice use on 1 timer for calculate the time with an array depending on pickup?

I want to use less CPU