Skip to content

Conversation

@FileEX
Copy link
Member

@FileEX FileEX commented Nov 3, 2024

Fixes #472

The crash was caused by the fact that for peds other than the local player, the current HP value wasn’t being updated. As a result, the code tried to kill a ped who still had 1 HP, which, due to an invalid pointer, caused a crash. However, this leads to another side effect: due to the ped being recreated, the ped pointer becomes invalid, so the ped never dies with such code.

addEventHandler('onClientPedDamage', root, function()
    setElementHealth(source, 1)
end)

For the local player, it works differently, and the player dies normally. For other players, they’re likely immortal in the same way as non-player peds but i'm not sure.

In any case, recreating the ped in setElementHealth causes a chain of additional bugs and unexpected behaviors. This PR aims to eliminate the crash but doesn’t address the underlying issue with ped recreation

return false;
}

if (pDamagedPed->IsLocalPlayer())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this check added to avoid possible desync issues?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, since HP will be synchronized when using setElementHealth in onClientPedDamage

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HP is synchronized, but a remote player can die locally. It can cause nasty issues potentially

@FileEX FileEX closed this Nov 17, 2024
@FileEX FileEX deleted the bugfix/onClientPedDamage-crash branch November 17, 2024 15:18
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.

setElementHealth in onClientPedDamage can cause crash

3 participants