mtasa-blue
mtasa-blue copied to clipboard
onPlayerDamage bugged with onPlayerJoin and setHealth on spawn.
Describe the bug
I found a weird bug with onPlayerDamage and setting the player's health after spawn.
I found that if you have a onPlayerDamage event, this event is not triggered when you set the player's health on spawn through code, and that is the expected behaviour (I hope). However, if you join the server and then set the player's health at spawn all of a sudden the onPlayerDamage event is triggered.
Steps to reproduce
Try the code below and see the difference when you /kill the player and spawn vs. when you join the server and spawn. You will see that the damage event is only triggered when you join the server and spawn. The damageId and bodypart are also both 255 which is not listed in the wiki.
This is very odd behaviour!!
function spawn(player)
player:spawn(0,0,3)
fadeCamera(player, true)
setCameraTarget(player, player)
end
addEventHandler('onPlayerJoin', root, function()
spawn(source)
end)
addEventHandler('onPlayerWasted', root, function()
spawn(source)
end)
addEventHandler('onPlayerSpawn', root, function()
source:setHealth(60)
end)
addEventHandler('onPlayerDamage', root, function(attacker, damageId, bodypart, loss)
iprint(source, attacker, damageId, bodypart, loss)
end)
Version
Server v1.5.9-release-21244 Client v1.5.9-release-21244
Additional context
No response
Relevant log output
No response
Security Policy
- [X] I have read and understood the Security Policy and this issue is not security related.
onPlayerDamage doesn't trigger if the damage kills the player, onPlayerWasted is called instead
@TracerDS The player isn't killed in the example. I'm just setting the player's health and the event gets triggered when it shouldn't. It's an inconsistent behaviour because it doesn't happen normally.
@TracerDS The player isn't killed in the example. I'm just setting the player's health and the event gets triggered when it shouldn't. It's an inconsistent behaviour because it doesn't happen normally.
You cannot have negative health. Going below 0 will simply kill the player
@TracerDS again, the player isn't killed... see the example. It's all about source:setHealth(60) in the example, which triggers the onPlayerDamage event, but only after a reconnect.
The killing part is just so I can respawn, and only THEN I'm setting the health in the spawn event.
Please read the issue carefully.
Reproduced. AFAIK damage events shouldn't be triggered when health is set by script.
And if you do something like this:
addEventHandler('onPlayerSpawn', root, function()
source:setHealth(60)
source:setHealth(40)
source:setHealth(80)
end)
The event will be triggered with the loss 20.
onClientPlayerDamage is not being triggered.