Skip to content

feat(server): add onPedHealthChanged and onPedDeath events - #4126

Open
xalva98 wants to merge 1 commit into
citizenfx:masterfrom
xalva98:backport-pedevents-legacy
Open

feat(server): add onPedHealthChanged and onPedDeath events#4126
xalva98 wants to merge 1 commit into
citizenfx:masterfrom
xalva98:backport-pedevents-legacy

Conversation

@xalva98

@xalva98 xalva98 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Goal of this PR

Make the enhanced onPedHealthChanged and onPedDeath server events available on legacy GTA5.

How is this PR achieving the goal

A ped only sends its health node when the game changed health, armour or damage state, so parsing it
is the detector: the clone sync path reads health and armour off the node before ParseSync, compares
them to what the node holds afterwards, and turns a difference into events. No state is added to the
node, nothing is polled, and the event rate can never exceed the sync rate.

onPedDeath fires on the transition to dead only, so a ped that stays dead does not report a second
death while a revived ped that dies again does.

Both events are only raised when a resource registered a handler for them. ResourceEventManagerComponent
gained an OnResourceHandledEvent notification that fires when a resource subscribes to an event
name; the game state caches its interest in an atomic bitmask from it, so the parse path costs a
relaxed atomic load and never touches the event registry.

Arguments match the enhanced API:

onPedHealthChanged(ped, oldHealth, health, oldArmour, armour, attacker, weaponHash)
onPedDeath(ped, attacker, weaponHash)

ped and attacker are server-side entity handles, as in entityCreated. RedM needs the ped
health node in its sync tree first (see #3508), after which
these events work there unchanged, minus armour, attacker and weapon.

This PR applies to the following area(s)

FiveM, FxServer

Successfully tested on

Game builds: 3258, FxServer
Platforms: Windows

Tested thoroughly with the test resource attached below, which runs a scripted damage protocol:
armour, damage, healing, death firing exactly once, damage on a corpse not repeating it, revival,
dying again, an idle server staying silent, and weapon damage reporting the attacker and weapon —
for players and for non-player peds. No issues found.
pedevents_test.zip

Checklist

  • Code compiles and has been tested successfully.
  • Code is properly formatted and follows the existing style.
  • Commit message is clear and follows the project conventions.
  • This PR introduces no new compilation warnings.

@github-actions github-actions Bot added triage Needs a preliminary assessment to determine the urgency and required action invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Aug 13, 2026
Peds only send their health node when the game changed health, armour or damage
state, so the node parse itself is the change signal: it keeps the previous
health/armour and flags whether they changed, and the clone sync path turns that
into events. No per-tick polling of entities is involved.

Both events are only raised when a resource registered a handler for them, using
the event subscriptions the resource event manager already tracks.
@xalva98
xalva98 force-pushed the backport-pedevents-legacy branch from 45e20e9 to 66a3805 Compare August 17, 2026 18:25
@github-actions github-actions Bot added triage Needs a preliminary assessment to determine the urgency and required action invalid Requires changes before it's considered valid and can be (re)triaged and removed invalid Requires changes before it's considered valid and can be (re)triaged triage Needs a preliminary assessment to determine the urgency and required action labels Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid Requires changes before it's considered valid and can be (re)triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant