OnPlayerDamage
Jump to navigation
Jump to search
This event is triggered when a player is damaged, in any way.
It should be noted that this event is not triggered when attacked by a team member if friendly fire is enabled.
It should also be noted that canceling this event has no effect. Cancel the client-side event onClientPlayerDamage instead.
Parameters
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 integer representing the weapon the attacker used to kill the player
- bodypart: An integer representing the bodypart ID the player was hit on when he got damaged.
- 3: Torso
- 4: Ass
- 5: Left Arm
- 6: Right Arm
- 7: Left Leg
- 8: Right Leg
- 9: Head
- loss: A float representing the percentage of health the player lost.
Source
The source of this event is the player who was damaged.
Example
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 )
See Also
Player events
- onPlayerACInfo
- onPlayerBan
- onPlayerChangeNick
- onPlayerChat
- onPlayerClick
- onPlayerCommand
- onPlayerConnect
- onPlayerContact
- onPlayerDamage
- onPlayerJoin
- onPlayerLogin
- onPlayerLogout
- onPlayerMarkerHit
- onPlayerMarkerLeave
- onPlayerModInfo
- onPlayerMute
- onPlayerNetworkStatus
- onPlayerPickupHit
- onPlayerPickupLeave
- onPlayerPickupUse
- onPlayerPrivateMessage
- onPlayerQuit
- onPlayerScreenShot
- onPlayerSpawn
- onPlayerStealthKill
- onPlayerTarget
- onPlayerUnmute
- onPlayerVehicleEnter
- onPlayerVehicleExit
- onPlayerVoiceStart
- onPlayerVoiceStop
- onPlayerWasted
- onPlayerWeaponFire
- onPlayerWeaponSwitch
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled