Fix dead peds replaying their death animation on stream in - #5144
Open
TheCrazy17 wants to merge 2 commits into
Open
Fix dead peds replaying their death animation on stream in#5144TheCrazy17 wants to merge 2 commits into
TheCrazy17 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The client recreates a ped's game entity every time it streams in. When the ped was already dead,
CClientPed::Killrefused to give the new entity its dead task, so the ped came back alive at zero health and the game ran a death of its own, replaying the animation and shifting the ped forward on every stream in. The dead state is now restored directly on the recreated ped.Motivation
Resolves #965.
_CreateModelcallsKill(..., bSetDirectlyDead = true)to put the dead state back, guarded by!IsDead().IsDead()reads the game ped's task atTASK_PRIORITY_EVENT_RESPONSE_NONTEMPand falls back to the cachedm_bDeadwhen there is none. A freshly created game entity holds no tasks at all, so the guard read the stalem_bDeadleft over from the original death and skipped creating the dead task. That left a ped at zero health with no death task, so the game generated its own death, ranCTaskComplexDieand applied its root translation again on every stream in, which is where both the repeated animation and the drift came from.A ped that is already dead the first time it streams in was never affected, because the entity add path only calls
SetHealthand neverSetIsDead, som_bDeadis still false and the guard passes.Two further details, both confirmed against
CTaskSimpleDead::ProcessPed(0x630600): it only setsPEDSTATE_DEADon its first update a frame later, which left the game a window to start a death of its own first, and it does not pose a ped that died on foot. The ped state is now set immediately, andKillrecords the animation group and id from the real death so the restore can hold that animation on its last frame, which is what theTODOremoved here was asking for.Test plan
Stand next to the ped, then switch dimension away and back several times with
setElementDimension(localPlayer, 1)andsetElementDimension(localPlayer, 0). Before this change the ped stood up, died again and crept forward on every switch. After it, the ped streams in already lying in its final pose and stays on the spot it died on.Also checked that a normal death still plays its full animation, that a ped which died while it was streamed out appears dead without animating.
Checklist