OnPedDamage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(slight improvements)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server event}}
{{Server event}}
This event is triggered when a ped is killed or dies. It is not triggered for players.
{{Needs Checking|There might be more parameters to this event, and the cancel effect hasn't been tested.}}
This event is triggered when a ped is damaged. For player damage, use [[onPlayerDamage]] instead.


==Parameters==
==Parameters==
<syntaxhighlight lang="lua">float deltaHealth</syntaxhighlight>
<syntaxhighlight lang="lua">float loss</syntaxhighlight>
 
*'''deltaHealth''': an [[int]] representing the delta between old ped health and new health (oldHealth - newHealth).


*'''loss''': an [[int]] representing the percentage of health the ped lost.


==Source==
==Source==
The [[event system#Event source|source]] of this event is the [[ped]] that got damaged.
The [[event system#Event source|source]] of this event is the [[ped]] that got damaged.
==Cancel Effect==
Canceling this event has no effect. Cancel the client-side event [[onClientPedDamage]] instead.


==Example==
==Example==
This example outputs to the console that the ped is now dead.
This example outputs a message to the console when a specific ped is damaged.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ped1 = createPed(112, 0, 0, 0) --Create our Ped
local ped1 = createPed(112, 0, 0, 0) -- create our ped
function onDamaged(deltaHealth)
 
     outputConsole("Your ped is damaged!")
function pedDamaged(loss)
    outputConsole("delta was: " .. tostring(deltaHealth))
     outputConsole("ped1 damaged! loss: " .. tostring(loss))
end
end
addEventHandler("onPedDamage", ped1, onDamaged) --Add the Event when ped1 dies
 
addEventHandler("onPedDamage", ped1, pedDamaged) -- triggered only when ped1 gets damaged
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Ped events}}
{{See also/Server event|Ped events}}

Revision as of 14:58, 20 August 2021

Dialog-information.png This article needs checking.

Reason(s): There might be more parameters to this event, and the cancel effect hasn't been tested.

This event is triggered when a ped is damaged. For player damage, use onPlayerDamage instead.

Parameters

float loss
  • loss: an int representing the percentage of health the ped lost.

Source

The source of this event is the ped that got damaged.

Cancel Effect

Canceling this event has no effect. Cancel the client-side event onClientPedDamage instead.

Example

This example outputs a message to the console when a specific ped is damaged.

local ped1 = createPed(112, 0, 0, 0) -- create our ped

function pedDamaged(loss)
    outputConsole("ped1 damaged! loss: " .. tostring(loss))
end

addEventHandler("onPedDamage", ped1, pedDamaged) -- triggered only when ped1 gets damaged

See Also

Ped events


Event functions