Question about timers opitimization
#1

Hello for everyone, who is reading that.
Sorry for poor english, but I need to ask and get an answer.

Which one will be better for server, u think and why?
For every 1 player = 1 player timer (like SetTimerEx for every1)
Or for all = 1 global timer (SetTimer and there foreach( )
Thanks for answers.
Reply
#2

global timer + foreach, why? you dont need use KillTimer everytime when player disconnect
you dont need update in one time all players, you can use one array + gettime/gettick
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
global timer + foreach, why? you dont need use KillTimer everytime when player disconnect
you dont need update in one time all players, you can use one array + gettime/gettick
thanks. but I dont use SAVING in this timers. I use something like "- seconds for variable, checking if he is in car" and etc. For save all info I have other func when they disconnect. So, thanks for reply.
Reply
#4

I can't figure out anything at all that would need an active timer at all times for all players.

If you want to check if player is in car, use OnPlayerStateChange.
Reply
#5

Quote:
Originally Posted by introzen
Посмотреть сообщение
I can't figure out anything at all that would need an active timer at all times for all players.

If you want to check if player is in car, use OnPlayerStateChange.
Like variable how many seconds player already playing,
If player is muted - --seconds;,
and etc with seconds calculating.

or how I should do that calculation?
Reply
#6

Quote:
Originally Posted by BloodyRP
Посмотреть сообщение
Like variable how many seconds player already playing,
Save the unix-time when player enters the server and save it when he disconnects. Then calculate how many seconds were played and add to a total variable which you store in INI or SQL.

Quote:
Originally Posted by BloodyRP
Посмотреть сообщение
If player is muted - --seconds;,
You can use a timer for this.

More efficient though would be to set the actual timer for as long as the player needs to be muted, and then create a player command which a player can use you check how much is left of their mute, you then have to store the time in an array as above with gettime();.
Reply
#7

Quote:
Originally Posted by introzen
Посмотреть сообщение
Save the unix-time when player enters the server and save it when he disconnects. Then calculate how many seconds were played and add to a total variable which you store in INI or SQL.


You can use a timer for this.

More efficient though would be to set the actual timer for as long as the player needs to be muted, and then create a player command which a player can use you check how much is left of their mute, you then have to store the time in an array as above with gettime();.
Thanks.
But what if I need to do something when seconds gone? I think its not good to create 1 more timer, if I have already 1 global timer, where I can do this.
Reply
#8

Per player timer would be lot faster. Make sure you have the proper RAM to run that much of timers or otherwise use the second option.
Reply
#9

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Per player timer would be lot faster. Make sure you have the proper RAM to run that much of timers or otherwise use the second option.
500 player timers would be faster than 1 global timer with foreach ?
Reply
#10

Yes, because the foreach loop has to loop all the codes 500 times anyways.
Using SetTimerEx when the player connects means that the code gets executed at different times, and therefore does not have to loop all the code 500 times at the same time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)