Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es_extended/client/main): fix player death race condition #1509

Merged
merged 5 commits into from
Nov 27, 2024

Conversation

Kenshiin13
Copy link
Contributor

@Kenshiin13 Kenshiin13 commented Nov 26, 2024

Description

The current spawn event flow for multicharacter is structured as follows:

  1. The player loads into the server, triggering the playerSpawned event during multichar setup.
  2. On character selection, the following events are triggered in this order:
    1. esx:playerLoaded
    2. playerSpawned
    3. esx:onPlayerSpawn
    4. playerSpawned (Redundant and removed by this PR)

This PR addresses two key issues:

  1. Redundant playerSpawned Trigger
    The playerSpawned event was redundantly triggered in the ESX.SpawnPlayer function callback, even though the function itself already triggers this event. This PR eliminates the unnecessary duplication.

  2. Health & Armor Metadata Race Condition
    Player metadata, such as health and armor, is now applied within the esx:onPlayerSpawn event instead of esx:playerLoaded. This resolves the following issue:

    • The player's health, which could be set to 0 (causing death), was being applied before their death state was reset in esx:onPlayerSpawn. This created a race condition where a player might be killed during esx:playerLoaded and then have their death state reset immediately afterward in esx: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. Since esx:onPlayerSpawn is used by esx_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.

@Kenshiin13 Kenshiin13 merged commit 2bfd7ef into esx-framework:dev Nov 27, 2024
1 check passed
@Kenshiin13 Kenshiin13 deleted the fix-player-death branch November 27, 2024 22:06
@Kenshiin13 Kenshiin13 mentioned this pull request Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Published
Development

Successfully merging this pull request may close these issues.

2 participants