fix(es_extended/client/main): fix player death race condition #1509
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.
Description
The current spawn event flow for multicharacter is structured as follows:
playerSpawned
event during multichar setup.esx:playerLoaded
playerSpawned
esx:onPlayerSpawn
playerSpawned
(Redundant and removed by this PR)This PR addresses two key issues:
Redundant
playerSpawned
TriggerThe
playerSpawned
event was redundantly triggered in theESX.SpawnPlayer
function callback, even though the function itself already triggers this event. This PR eliminates the unnecessary duplication.Health & Armor Metadata Race Condition
Player metadata, such as health and armor, is now applied within the
esx:onPlayerSpawn
event instead ofesx:playerLoaded
. This resolves the following issue:esx:onPlayerSpawn
. This created a race condition where a player might be killed duringesx:playerLoaded
and then have their death state reset immediately afterward inesx:onPlayerSpawn
.Additionally, while not explicitly targeted, this PR also appears to fix a related issue where the death screen in
esx_ambulancejob
would fail to display after combat logging. Sinceesx:onPlayerSpawn
is used byesx_ambulancejob
to remove the death screen (the same event where metadata is applied and the player could potentially die), this change indirectly resolves that behavior.To fully address this issue, I will submit a separate PR to
esx_ambulancejob
to ensure the death screen logic ignores the first spawn event. This should eliminate any remaining race conditions in the handling of player states. This logic has been fragile for some time, and this PR is a step towards stabilizing it.