OnClientObjectDamage

From Multi Theft Auto: Wiki
Revision as of 17:12, 13 January 2013 by Jusonex (talk | contribs) (Created page with "__NOTOC__ {{Client event}} This event is fired before an object gets damaged. Also note that this event is only triggered for players nearby the local player's camera. This is du...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This event is fired before an object gets damaged. Also note that this event is only triggered for players nearby the local player's camera. This is due to elements far away being streamed out.

Parameters

float loss
  • 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).

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

Click to collapse [-]
Client

This example outputs the theoretical and real loss.

function outputLoss(loss)
    local oldHealth = getElementHealth(source)
    setTimer(function()
        local newHealth = getElementHealth(source)
        outputChatBox("Real loss: "..(newHealth-oldHealth))
        outputChatBox("Theoretical loss: "..loss)
    end)
end
addEventHandler("onClientObjectDamage", root, outputLoss)

Requirements

Minimum server version n/a
Minimum client version 1.4-9.04924

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.4-9.04924" />

See Also

Client object events


Client event functions