OnPlayerDamage: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This event is | This event is triggered when a player is damaged, in any way. | ||
''It should be noted that this | * ''It should be noted that this event is not triggered when attacked by a team member if friendly fire is enabled.'' | ||
==Syntax== | ==Syntax== | ||
Line 9: | Line 7: | ||
void onPlayerDamage ( player attacker, int attackerweapon, int bodypart, float loss ) | void onPlayerDamage ( player attacker, int attackerweapon, int bodypart, float loss ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Variables== | |||
*'''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 died. | |||
{{BodyParts}} | |||
*'''loss''': A float representing the percentage of health the player lost. | |||
==Example== | ==Example== | ||
This example does... | This example does... | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | --add an event handler for the onPlayerDamage event | ||
addEventHandler ( "onPlayerDamage", getRootElement (), "playerDamage_text" ) | |||
-- | 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 | |||
killPlayer ( source, attacker, weapon, bodypart ) -- and kill the player | |||
end | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 23:28, 17 November 2006
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.
Syntax
void onPlayerDamage ( player attacker, int attackerweapon, int bodypart, float loss )
Variables
- 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 died.
- 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.
Example
This example does...
--add an event handler for the onPlayerDamage event addEventHandler ( "onPlayerDamage", getRootElement (), "playerDamage_text" ) 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 killPlayer ( source, attacker, weapon, bodypart ) -- and kill the player end end