optimize timer
#1

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

I think many people use AllInOneTimer
Reply
#3

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,
Reply
#4

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

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

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

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

Reply
#8

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)