OnClientObjectDamage: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client event}} | {{Client event}} | ||
This event is fired before an object gets damaged | This event is fired before an object gets damaged. | ||
{{Note|This event is only triggered for objects that are streamed in}} | {{Note|This event is only triggered for objects that are streamed in.}} | ||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 8: | Line 8: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''loss:''' the health loss caused by the damage. This parameter contains the theoretical loss, which could be less than 0, if you substract it of the current health. If you want to get the real loss, you have to substract the new health of the old health (use a timer for this). | *'''loss:''' the health loss caused by the damage. This parameter contains the theoretical loss, which could be less than 0, if you substract it of the current health. If you want to get the real loss, you have to substract the new health of the old health (use a timer for this). | ||
*'''attacker:''' the vehicle/ped/player who is damaging the object | *'''attacker:''' the vehicle/ped/player who is damaging the object. | ||
==Source== | ==Source== | ||
The source of this event is the object which was damaged | The source of this event is the object which was damaged. | ||
==Cancel effect== | ==Cancel effect== | ||
Line 17: | Line 17: | ||
==Example== | ==Example== | ||
This example outputs the theoretical and real loss | This example outputs the theoretical and real loss: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function outputLoss(loss) | function outputLoss(loss) | ||
local oldHealth = getElementHealth(source) | local oldHealth = getElementHealth(source) | ||
setTimer(function() | setTimer(function(source) | ||
local newHealth = getElementHealth(source) | local newHealth = getElementHealth(source) | ||
outputChatBox("Real loss: "..(newHealth-oldHealth)) | outputChatBox("Real loss: "..(newHealth-oldHealth)) | ||
outputChatBox("Theoretical loss: "..loss) | outputChatBox("Theoretical loss: "..loss) | ||
end,100,1) | end,100,1,source) | ||
end | end | ||
addEventHandler("onClientObjectDamage", root, outputLoss) | addEventHandler("onClientObjectDamage", root, outputLoss) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== |
Latest revision as of 17:08, 7 November 2024
This event is fired before an object gets damaged.
Parameters
float loss, element attacker
- loss: the health loss caused by the damage. This parameter contains the theoretical loss, which could be less than 0, if you substract it of the current health. If you want to get the real loss, you have to substract the new health of the old health (use a timer for this).
- attacker: the vehicle/ped/player who is damaging the object.
Source
The source of this event is the object which was damaged.
Cancel effect
If this event is canceled, the object will not be damaged.
Example
This example outputs the theoretical and real loss:
function outputLoss(loss) local oldHealth = getElementHealth(source) setTimer(function(source) local newHealth = getElementHealth(source) outputChatBox("Real loss: "..(newHealth-oldHealth)) outputChatBox("Theoretical loss: "..loss) end,100,1,source) end addEventHandler("onClientObjectDamage", root, outputLoss)
See Also
Client object events
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled