OnClientPlayerDamage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Replace with predefined variable.)
 
(11 intermediate revisions by 9 users not shown)
Line 2: Line 2:
{{Client event}}
{{Client event}}
This event is triggered whenever a player is damaged.
This event is triggered whenever a player is damaged.
 
{{Note|This event is only triggered for players that are streamed in}}
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element attacker, int weapon, int bodypart [, float loss ]
element attacker, int damage_causing, int bodypart [, float loss ]
</syntaxhighlight>  
</syntaxhighlight>  


*'''attacker''': A [[player]] [[element]] representing the attacker or [[vehicle]] [[element]] (when being run over or falling off a bike).
*'''attacker''': A [[player]] [[element]] representing the attacker or [[vehicle]] [[element]] (when being run over or falling off a bike).
*'''weapon''': An integer representing the weapon ID the attacker used
*'''damage_causing''': An [[int]] representing the cause of damage, either a [[Weapons|attacker weapon]], or some other [[Damage Types|types of damage]].
*'''bodypart''': An integer representing the bodypart the player was damaged
*'''bodypart''': An integer representing the bodypart the player was damaged.
{{BodyParts}}
{{BodyParts}}
{{New feature|3|1.0|
{{New feature/item|3|1.0||
*'''loss''': A float representing the percentage of health the player lost.
*'''loss''': A float representing the percentage of health the player lost.
}}
}}
Line 25: Line 25:
This example prevents any damage from the minigun.
This example prevents any damage from the minigun.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function stopMinigunDamage ( attacker, weapon, bodypart )
function stopMinigunDamage(attacker, weapon, bodypart)
if ( weapon == 38 ) then --if the weapon used was the minigun
if (weapon == 38) then --if the weapon used was the minigun
cancelEvent() --cancel the event
cancelEvent() --cancel the event
end
end
end
end
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), stopMinigunDamage )
addEventHandler("onClientPlayerDamage", localPlayer, stopMinigunDamage)
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 11:40, 2 May 2022

This event is triggered whenever a player is damaged.

[[{{{image}}}|link=|]] Note: This event is only triggered for players that are streamed in

Parameters

element attacker, int damage_causing, int bodypart [, float loss ]
  • attacker: A player element representing the attacker or vehicle element (when being run over or falling off a bike).
  • damage_causing: An int representing the cause of damage, either a attacker weapon, or some other types of damage.
  • bodypart: An integer representing the bodypart the player was 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 that got damaged. (Streamed in players only)

Cancel effect

If this event is canceled, then any damaging effects to the local player will cease.

Example

This example prevents any damage from the minigun.

function stopMinigunDamage(attacker, weapon, bodypart)
	if (weapon == 38) then --if the weapon used was the minigun
		cancelEvent() --cancel the event
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, stopMinigunDamage)

See Also

Client player events


Client event functions