PDA

View Full Version : One timer or loop?


TwinkiDaBoss
30/07/2015, 03:05 AM
Alright so Ive got a question, what behaves better
SetTimerEx (bound to player) or SetTimer (using to loop thru players) ?

Lets say for example im using Health check, well simply I want a timer to run every few seconds to check players health and if they are above like 99 they will be banned, now my question remains, is it better to set 1 timer (SetTimerEx) or use SetTimer and use foreach with it to check all players that have possibly over 99 health?

My issue is that SetTimerEx that would loop every second could slow down the server a bit with some player base
Now the SetTimer with 1 second for example loop, im not sure

What would be better?

Note: Im using health hack check for example, im not really using a timer for it. Its basically just a simple codding question I need some explanations regarding it.

Mencent
30/07/2015, 08:05 AM
Hello! ;)

Use the SetTimer with a loop it is better because if you use SetTimerEx you can have (the maximum!) 500 timers at the same moment, and this is too much. Well, use SetTimer with a loop and do it like this:
That's the best way for a good performance:
public Timer()
{
for(new i,j=GetPlayerPoolSize();i<=j;i++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i))continue;
}
return 1;
}

dominik523
30/07/2015, 08:52 AM
Hello! ;)

Use the SetTimer with a loop it is better because if you use SetTimerEx you can have (the maximum!) 500 timers at the same moment, and this is too much. Well, use SetTimer with a loop and do it like this:
That's the best way for a good performance:
public Timer()
{
for(new i,j=GetPlayerPoolSize();i<=j;i++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i))continue;
}
return 1;
}

Sorry, but no.

OT: This has been discussed already.
http://forum.sa-mp.com/showthread.php?t=575349