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.3k stars 412 forks source link

Fix #414 Using setElementHealth on a dead ped makes it invincible #3507

Closed FileEX closed 4 days ago

FileEX commented 4 days ago

Fixed #414

My previous PR "fixing" this bug was a long time ago, when I had no experience. Now I have solved this problem and I know what causes it.

Ped has locked health and armor when he dies. When the ped is re-created (ReCreateModel), health and armor are not unlocked. This is proven by the fact that when we move away from the invincible ped and come back again (stream out & stream in), the ped has unlocked health and armor and receives damage. This is because when stream in with ped, his health and armor are unlocked.

https://github.com/multitheftauto/mtasa-blue/blob/2c4e23211346248c836bbcac57baa2d5cf74be1b/Client/mods/deathmatch/logic/CPedSync.cpp#L134-L135

Additionally, the "isDead" state is now also set correctly after recreating a ped.

I don't think this should cause any synchronization problems.