Skip to content

Fix dead peds replaying their death animation on stream in - #5144

Open
TheCrazy17 wants to merge 2 commits into
multitheftauto:masterfrom
TheCrazy17:fix/dead-peds-replay-death-animation
Open

Fix dead peds replaying their death animation on stream in#5144
TheCrazy17 wants to merge 2 commits into
multitheftauto:masterfrom
TheCrazy17:fix/dead-peds-replay-death-animation

Conversation

@TheCrazy17

Copy link
Copy Markdown
Contributor

Summary

The client recreates a ped's game entity every time it streams in. When the ped was already dead, CClientPed::Kill refused 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.

_CreateModel calls Kill(..., bSetDirectlyDead = true) to put the dead state back, guarded by !IsDead(). IsDead() reads the game ped's task at TASK_PRIORITY_EVENT_RESPONSE_NONTEMP and falls back to the cached m_bDead when there is none. A freshly created game entity holds no tasks at all, so the guard read the stale m_bDead left 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, ran CTaskComplexDie and 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 SetHealth and never SetIsDead, so m_bDead is still false and the guard passes.

Two further details, both confirmed against CTaskSimpleDead::ProcessPed (0x630600): it only sets PEDSTATE_DEAD on 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, and Kill records the animation group and id from the real death so the restore can hold that animation on its last frame, which is what the TODO removed here was asking for.

Test plan

local ped = createPed(192, 0, 0, 3)
killPed(ped)

Stand next to the ped, then switch dimension away and back several times with setElementDimension(localPlayer, 1) and setElementDimension(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

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit by commit.

@TheCrazy17 TheCrazy17 changed the title Fix dead peds replaying their death animation when they stream back in Fix dead peds replaying their death animation on stream in Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dead peds replay death animations when switching dimensions

1 participant