SA-MP Forums Archive
Timers or OnPlayerUpdate for the sync? - 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: Timers or OnPlayerUpdate for the sync? (/showthread.php?tid=447403)



Timers or OnPlayerUpdate for the sync? - Kyra - 29.06.2013

Hi, I have a question i want to improve the sync on my server and i divided my global timer on several timers for improve the server sync.
But if i put some function at this "timers divided" on OnPlayerUpdate it's better ? A lot of code on OnPlayerUpdate its bad for the sync?

ps: I use a gettime() on OnPlayerUpdate for check all 1 second this function.


Re: Timers or OnPlayerUpdate for the sync? - DaRk_RaiN - 29.06.2013

****** you have won an infraction for double posting.
OT:
I'm doing the same for my server, a 750 ~ 550 ms interval timer would be hell lot better than OPU (for my sync method atleast).


AW: Timers or OnPlayerUpdate for the sync? - Saize - 29.06.2013

Do you wanna sync it like on an AAD-Server?


Re: Timers or OnPlayerUpdate for the sync? - Kyra - 30.06.2013

Quote:
Originally Posted by ******
Посмотреть сообщение
Have you tried and measured the performance impact of each option? You are asking us how code you've not posted will perform on hardware you've not specified - how should we know?
Hum i think the performance is not my problem, my server is strong only 2 - 5 % CPU with 30 players, but how measured what is the best for the sync or performance? (gettickcount?)

Quote:
Originally Posted by Saize
Посмотреть сообщение
Do you wanna sync it like on an AAD-Server?
AAD server is a server NO PING SHOT? (exemply server css at cessil?)

I use OnPlayerTakeDamage, i just want to improve the sync its really important. I always try to improve myself.

Quote:
Originally Posted by DaRk_RaiN
Посмотреть сообщение
****** you have won an infraction for double posting.
OT:
I'm doing the same for my server, a 750 ~ 550 ms interval timer would be hell lot better than OPU (for my sync method atleast).
So put a lot of code in OPU is the same as in timer for the sync?

Quote:
Originally Posted by AndreT
Посмотреть сообщение
While I do support the writing of tutorials, there are some huge issues that need to be addressed here.

1. Combining all timers into one or having less timers with more code is actually probably more problematic than having more times with less code. The statement I just made is valid in most cases, and the more code and the more timers combined into one there are, the more valid it becomes. Why? Due to the way SA-MP synchronization works. And if you think about it, it'll make sense.
Reading on the subject (more specifically, "Timers are efficient" paragraph)
This is the best topic I can find for this purpose right now.

2. You describe taking advantage of timestamps, yet there's a better way to do it rather than using timers. This comes with a little downside though - you will lose the messages like "You can use command ... now.", so the point I'm making is perhaps not very useful for you.
However what you've done can simply be solved by this:
pawn Код:
COMMAND:heal(playerid, params[])
{
    if((gettime() - heal_reload[playerid]) < 10)
        return SendClientMessage(playerid, 0xFF0000FF, "Please wait before using this command again!"), true;
    heal_reload[playerid] = gettime();

    SetPlayerHealth(playerid,100.0);
    SendClientMessage(playerid,0xFFFFFFFF,"You've healed yourself.");
    return 1;
}
There! No need for a timer, basically speaking.


I seriously hope that you take note of the 1st note that I wrote, because this is a serious misunderstanding by many many scripters. And while it does not make a difference with less code and less timers combined, there will be minor lag if there's a lot of code that takes a long time to execute per iteration or just many timers combined.

Hopefully you'll revise this tutorial. Thank you.
source: https://sampforum.blast.hk/showthread.php?tid=356005

I say "divided my global timer" because apparently this is the best solution for the sync.