SA-MP Forums Archive
OnPlayerTakeDamage called without OnPlayerUpdate - 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: OnPlayerTakeDamage called without OnPlayerUpdate (/showthread.php?tid=304356)



OnPlayerTakeDamage called without OnPlayerUpdate - Morion - 18.12.2011

Hi. Recently I have done some testing and found an odd sequence of callbacks. Before that I supposed that when a player is damaged, the update is sent to the server so OnPlayerUpdate is called first, OnPlayerTakeDamage then and only in that order (as a script works in a single thread).

But I have got very strange results from my tests - see the server log below. "OnPlayerUpdate" message is written in the very start of the callback with data from GetPlayerHealth. "OnPlayerTakeDamage_Tek" and "OnPlayerTakeDamage_Dal" are written in the start and end of the OnPlayerTakeDamage respectively.
Quote:
Originally Posted by Server log
[16:49:29] OnPlayerUpdate: Health:100.000000
[16:49:29] OnPlayerUpdate: Health:100.000000
[16:49:30] OnPlayerUpdate: Health:100.000000
[16:49:30] OnPlayerTakeDamage_Tek: 100.000000 hp, damage: 8.250000 hp
[16:49:30] OnPlayerTakeDamage_Dal: 100.000000 hp, damage: 8.250000 hp
[16:49:30] OnPlayerUpdate: Health:91.000000
[16:49:30] OnPlayerTakeDamage_Tek: 91.000000 hp, damage: 8.250000 hp
[16:49:30] OnPlayerTakeDamage_Dal: 91.000000 hp, damage: 8.250000 hp
[16:49:30] OnPlayerUpdate: Health:100.000000
[16:49:30] OnPlayerTakeDamage_Tek: 100.000000 hp, damage: 8.250000 hp
[16:49:30] OnPlayerTakeDamage_Dal: 100.000000 hp, damage: 8.250000 hp
...
[16:49:33] OnPlayerUpdate: Health:73.000000
[16:49:33] OnPlayerTakeDamage_Tek: 73.000000 hp, damage: 8.250000 hp
[16:49:33] OnPlayerTakeDamage_Dal: 73.000000 hp, damage: 8.250000 hp
[16:49:33] OnPlayerUpdate: Health:64.000000
[16:49:33] OnPlayerTakeDamage_Tek: 64.000000 hp, damage: 8.250000 hp
[16:49:33] OnPlayerTakeDamage_Dal: 64.000000 hp, damage: 8.250000 hp
[16:49:33] OnPlayerTakeDamage_Tek: 64.000000 hp, damage: 8.250000 hp
[16:49:33] OnPlayerTakeDamage_Dal: 64.000000 hp, damage: 8.250000 hp

...
[16:49:34] OnPlayerUpdate: Health:46.000000
[16:49:34] OnPlayerTakeDamage_Tek: 46.000000 hp, damage: 8.250000 hp
[16:49:34] OnPlayerTakeDamage_Dal: 46.000000 hp, damage: 8.250000 hp
[16:49:34] OnPlayerTakeDamage_Tek: 46.000000 hp, damage: 8.250000 hp
[16:49:34] OnPlayerTakeDamage_Dal: 46.000000 hp, damage: 8.250000 hp

...
[16:49:35] OnPlayerUpdate: Health:19.000000
[16:49:35] OnPlayerTakeDamage_Tek: 19.000000 hp, damage: 8.250000 hp
[16:49:35] OnPlayerTakeDamage_Dal: 19.000000 hp, damage: 8.250000 hp
[16:49:35] OnPlayerTakeDamage_Tek: 19.000000 hp, damage: 8.250000 hp
[16:49:35] OnPlayerTakeDamage_Dal: 19.000000 hp, damage: 8.250000 hp
[16:49:35] OnPlayerTakeDamage_Tek: 19.000000 hp, damage: 8.250000 hp
[16:49:35] OnPlayerTakeDamage_Dal: 19.000000 hp, damage: 8.250000 hp
[16:49:36] OnPlayerTakeDamage_Tek: 19.000000 hp, damage: 8.250000 hp
[16:49:36] OnPlayerTakeDamage_Dal: 19.000000 hp, damage: 8.250000 hp
[16:49:36] OnPlayerTakeDamage_Tek: 19.000000 hp, damage: 8.250000 hp
[16:49:36] OnPlayerTakeDamage_Dal: 19.000000 hp, damage: 8.250000 hp
[16:49:36] OnPlayerTakeDamage_Tek: 19.000000 hp, damage: 8.250000 hp
[16:49:36] OnPlayerTakeDamage_Dal: 19.000000 hp, damage: 8.250000 hp

...
So at the start everything is looking fine, we have some OnPlayerUpdate calls before getting shooted and then one OnPlayerTakeDamage call after each Update. But after some time OnPlayerTakeDamage is called twice with no OnPlayerUpdate between. And again. And then a whole six times! How this could happen? I'm confused.

Also wanted to note that there is SetPlayerHealth call between _Tek and _Dal, but I can't imagine how it could affect the sequence of callbacks.

So could someone explain me why this is happen please? Maybe I have suggested wrong and taken damage is sent separately from regular updates? Or something else I have missed?