feat(server): add onPedHealthChanged and onPedDeath events - #4126
Open
xalva98 wants to merge 1 commit into
Open
Conversation
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
force-pushed
the
backport-pedevents-legacy
branch
from
August 17, 2026 18:25
45e20e9 to
66a3805
Compare
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.
Goal of this PR
Make the enhanced
onPedHealthChangedandonPedDeathserver 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, comparesthem 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.
onPedDeathfires on the transition to dead only, so a ped that stays dead does not report a seconddeath while a revived ped that dies again does.
Both events are only raised when a resource registered a handler for them.
ResourceEventManagerComponentgained an
OnResourceHandledEventnotification that fires when a resource subscribes to an eventname; 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:
pedandattackerare server-side entity handles, as inentityCreated. RedM needs the pedhealth 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