OnClientVehicleDamage: Difference between revisions
No edit summary |
(Added another, special example.) |
||
Line 25: | Line 25: | ||
==Example== | ==Example== | ||
This example makes | This example makes every SWAT tank immune from all weapon attacks. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function handleVehicleDamage(attacker, weapon, loss, x, y, z, tyre) | function handleVehicleDamage(attacker, weapon, loss, x, y, z, tyre) | ||
Line 35: | Line 35: | ||
addEventHandler("onClientVehicleDamage", root, handleVehicleDamage) | addEventHandler("onClientVehicleDamage", root, handleVehicleDamage) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This example allows the Rhino to take damage from bullets even though they're bullet proof, this example doesn't work with explosions though. | |||
<syntaxhighlight lang="lua"> | |||
-- Only let these weapons damage a Rhino | |||
local weaponsToDamageRhino = { | |||
[38] = true, -- minigun | |||
[33] = true, -- country rifle | |||
[34] = true, -- sniper rifle | |||
[30] = true, -- AK-47 | |||
[31] = true, -- M4 | |||
} | |||
function handleRhinoDamage(attacker, weapon, loss, x, y, z, tyre) | |||
if (weapon and getElementModel(source) == 432 and loss > 0) then | |||
if (weaponsToDamageRhino[weapon]) then | |||
setElementHealth(source, getElementHealth(source) - loss) | |||
end | |||
end | |||
end | |||
addEventHandler("onClientVehicleDamage", root, handleRhinoDamage) | |||
<syntaxhighlight lang="lua"> | |||
Revision as of 14:35, 5 March 2014
Parameters
element theAttacker, int theWeapon, float loss, float damagePosX, float damagePosY, float damagePosZ, int tyreID
- theAttacker: An element if there was an attacker.
- theWeapon: An integer specifying the weapon ID if a weapon was used.
- loss: A float representing the amount of damage taken.
- damagePosX: A float representing the X co-ordinate of where the damage took place.
- damagePosX: A float representing the Y co-ordinate of where the damage took place.
- damagePosX: A float representing the Z co-ordinate of where the damage took place.
- tyreID: A number representing the tyre which took damage, if there is one.
Source
The source of this event is the vehicle that got damaged.
Cancel effect
If this event is canceled, the vehicle will not be damaged.
Example
This example makes every SWAT tank immune from all weapon attacks.
function handleVehicleDamage(attacker, weapon, loss, x, y, z, tyre) if (weapon and getElementModel(source) == 601) then -- A weapon was used and the vehicle model ID is that of the SWAT tank so cancel the damage. cancelEvent() end end addEventHandler("onClientVehicleDamage", root, handleVehicleDamage)
This example allows the Rhino to take damage from bullets even though they're bullet proof, this example doesn't work with explosions though. <syntaxhighlight lang="lua"> -- Only let these weapons damage a Rhino local weaponsToDamageRhino = { [38] = true, -- minigun [33] = true, -- country rifle [34] = true, -- sniper rifle [30] = true, -- AK-47 [31] = true, -- M4 }
function handleRhinoDamage(attacker, weapon, loss, x, y, z, tyre) if (weapon and getElementModel(source) == 432 and loss > 0) then if (weaponsToDamageRhino[weapon]) then setElementHealth(source, getElementHealth(source) - loss) end end end addEventHandler("onClientVehicleDamage", root, handleRhinoDamage) <syntaxhighlight lang="lua">
See Also
Client vehicle events
- onClientTrailerAttach
- onClientTrailerDetach
- onClientVehicleCollision
- onClientVehicleDamage
- onClientVehicleEnter
- onClientVehicleExit
- onClientVehicleExplode
- onClientVehicleNitroStateChange
- onClientVehicleRespawn
- onClientVehicleStartEnter
- onClientVehicleStartExit
- onClientVehicleWeaponHit
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled