GetPlayerHealth(playerid, fHealth);
format(string, sizeof(string), "(OnPlayerTakeDamage) Health before: %.1f (%f) | Health after: %.1f (%f)", fHealth, fHealth, fHealth-amount, fHealth-amount); |
format(string, sizeof(string), "ID: %d | Server-side health: %.1f (%f) | Client-side health: %.1f (%f)", playerid, ValidHealth[playerid], ValidHealth[playerid], fHealth, fHealth); |
(OnPlayerTakeDamage) ID: 1 | IssuerID: 0 | Amount: 1.3 (1.320000) | WeaponID: 0 | Bodypart: 3 (OnPlayerTakeDamage) Health before: 100.0 (100.000000) | Health after: 98.6 (98.680000) |
ID: 1 | Server-side health: 98.6 (98.680000) | Client-side health: 98.0 (98.000000) |
(OnPlayerTakeDamage) ID: 1 | IssuerID: 0 | Amount: 8.2 (8.250000) | WeaponID: 22 | Bodypart: 3 (OnPlayerTakeDamage) Health before: 100.0 (100.000000) | Health after: 91.7 (91.750000) |
ID: 1 | Server-side health: 91.7 (91.750000) | Client-side health: 91.0 (91.000000) |
(OnPlayerTakeDamage) ID: 1 | IssuerID: 0 | Amount: 8.2 (8.250000) | WeaponID: 29 | Bodypart: 3 (OnPlayerTakeDamage) Health before: 100.0 (100.000000) | Health after: 91.7 (91.750000) |
(ID: 1 | Server-side health: 91.7 (91.750000) | Client-side health: 91.0 (91.000000) |
(OnPlayerTakeDamage) ID: 1 | IssuerID: 0 | Amount: 49.5 (49.500003) | WeaponID: 25 | Bodypart: 3 (OnPlayerTakeDamage) Health before: 100.0 (100.000000) | Health after: 50.4 (50.499996) |
ID: 1 | Server-side health: 50.4 (50.499996) | Client-side health: 50.0 (50.000000) |
(OnPlayerTakeDamage) ID: 1 | IssuerID: 0 | Amount: 46.2 (46.200000) | WeaponID: 24 | Bodypart: 3 (OnPlayerTakeDamage) Health before: 100.0 (100.000000) | Health after: 53.7 (53.799999) |
ID: 1 | Server-side health: 53.7 (53.799999) | Client-side health: 53.0 (53.000000) |
ID: 1 | IssuerID: 0 | Amount: 39.6 (39.600002) | WeaponID: 27 | Bodypart: 3 Health before: 100.0 (100.000000) | Health after: 60.3 (60.399997) |
ID: 1 | Server-side health: 60.3 (60.399997) | Client-side health: 60.0 (60.000000) |
(OnPlayerTakeDamage) ID: 1 | IssuerID: 0 | Amount: 41.2 (41.250000) | WeaponID: 34 | Bodypart: 3 (OnPlayerTakeDamage) Health before: 100.0 (100.000000) | Health after: 58.7 (58.750000) |
ID: 1 | Server-side health: 58.7 (58.750000) | Client-side health: 58.0 (58.000000) |
The reason for this is that both GTA and the SA-MP server deal with the health as a float (4 bytes), but it's actually synced from the player to the server 1 byte in order to save bandwidth. So what you are seeing is basically a rounding problem.
This really should be fixed at some point. What I can say is that the player's health and armour does match what you have there as the server-sided version, you just can't see it accurately with GetPlayerHealth/GetPlayerArmour. SetPlayerHealth and SetPlayerArmour do send full floats, so the player will get those changes without any rounding problems. |
The reason for this is that both GTA and the SA-MP server deal with the health as a float (4 bytes), but it's actually synced from the player to the server 1 byte in order to save bandwidth. So what you are seeing is basically a rounding problem.
This really should be fixed at some point. What I can say is that the player's health and armour does match what you have there as the server-sided version, you just can't see it accurately with GetPlayerHealth/GetPlayerArmour. SetPlayerHealth and SetPlayerArmour do send full floats, so the player will get those changes without any rounding problems. |
I have a scripted health system and I do round down values of HP unless weapons used are not those where the damage is below 1. Just in case, but it's great to know this.
|
new iHealth = 1.0, iHealthEx, Float: fHealth = 1.4;
iHealthEx = floatround(fHealth, floatround_round);
if(iHealth != iHealthEx) { return false; } // It doesn't match
else if(iHealth == iHealthEx) { return true; } // It does match