From Multi Theft Auto: Wiki
This event is triggered when a player is damaged, in any way.
- This event is not triggered when attacked by a team member if friendly fire is enabled.
- Canceling this event has no effect. Cancel the client-side event onClientPlayerDamage instead.
- onPlayerDamage doesn't trigger if the damage kills the player, onPlayerWasted is called instead.
player attacker, int attackerweapon, int bodypart, float loss
- attacker: a player element representing the player who was the attacker. If there was no attacker this returns false.
- attackerweapon: an int representing the attacker weapon or the damage type.
- bodypart: an int representing the bodypart ID the player was hit on when he got damaged.
- loss: a float representing the percentage of health the player lost.
This example causes an instant kill when a player is shot in the head, and announces it in the chatbox.
--add an event handler for the onPlayerDamage event function playerDamage_text ( attacker, weapon, bodypart, loss ) --when a player is damaged if ( bodypart == 9 ) then -- if the body part is 9, i.e. the head outputChatBox ( "Headshot!", getRootElement (), 255, 170, 0 ) --output "Headshot" into the chatbox killPed ( source, attacker, weapon, bodypart ) -- and kill the player end end addEventHandler ( "onPlayerDamage", getRootElement (), playerDamage_text )
|#6495||[Fixed in 1.3.3-5411] onPlayerDamage has wrong parameters if source on vehicle|
|#8082||Custom weapons & objects don't fully work with ped damage events|