multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.36k stars 416 forks source link

Fractional health not fully synced with GTA SA HUD #561

Open ArranTuna opened 5 years ago

ArranTuna commented 5 years ago

Describe the bug Ped's health is not fully in sync with the health bar. See attached example picture. Note that this doesn't occur in SP.

To reproduce 1) Spawn with default healthstat (569, 100hp) and lose/set Hp until 96. The loss of 4hp, will not be synced to the healthbar, fractional loss will appear only from -5hp. 96hp ped health means its visible as full health bar.

2) Second example, set hpstat 1000 and 200 hp. The bar will start losing as soon as you reach under 176 hp, not earlier.

Second could be either the 569 =100hp 1000 (ca. 0.96x) math and relies on that, but then why can you set ped's health to 200hp, while infact 180hp is 100% possible health?

The last example also suffers from the minus -4hp desync. 180 hp could be full health for 1000stat, but the health bar also starts shrinking from 176 only here. (180 = 100% - 4hp syncfault)

Expected behaviour

Screenshots

image

Version Unstated at mantis.

Additional context

From https://bugs.mtasa.com/view.php?id=8105

AlexTMjugador commented 5 years ago

Adding to what I've previously said in the Mantis issue, I double-checked the fact I've stated with two different savegames in which I've maxed health by using GTA: SA Savegame Editor v3.2. It turned out my memory back then was correct:

First savegame showing 176 health with maxed-out health stat Second, different savegame showing 176 health with maxed-out health stat

I have also checked that the maximum health which is obtainable in singleplayer is 176 by using a ingame CLEO mod which shows the HP number on the HUD, in an attempt to minimize the threats to the validity of my conclusion, and the results that I highlighted in the image confirmed that my suspicion is correct:

Ingame CLEO mod showing 176 HP with maxed out health stat

Therefore, as MTA maximum health calculation seems to be inconsistent with GTA's, we would need to either modify GTA HUD health bar drawing behaviour to match MTA's (which could be more complex to do, but improve backward compatibility) or MTA maximum health calculation behaviour to match GTA's (this would be more simple to do, but it could introduce differences in gameplay due to scripters no longer being able to set a ped health to 200 as expected right now).

patrikjuvonen commented 5 years ago

According to @ccw:

Health is synced in 8 bits and I think that *1.25 /1.25 is (incorrectly) matching the sync quantization. Correct math is in SPlayerHealthSync::Write and SPlayerHealthSync::Read

Might have to do with this sync and tbh should be fixed while at it.