OnClientVehicleDamage: Difference between revisions
Jump to navigation
Jump to search
m (→Parameters) |
|||
(11 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client event}} | {{Client event}} | ||
{{New items| | {{New items|3.0135|1.3.5| | ||
This event is triggered when a vehicle is damaged. | This event is triggered when a vehicle is damaged. | ||
}} | }} | ||
{{Note|This event is only triggered for vehicles that are streamed in}} | |||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
element theAttacker, int theWeapon, float loss, float damagePosX, float damagePosY, float damagePosZ, int | element theAttacker, int theWeapon, float loss, float damagePosX, float damagePosY, float damagePosZ, int tireID | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''theAttacker''': An element if there was an attacker. | *'''theAttacker''': An element if there was an attacker. | ||
*'''theWeapon''': An integer specifying the weapon ID if a weapon was used. | *'''theWeapon''': An integer specifying the [[Weapons|weapon ID]] if a weapon was used. Otherwise [[Damage Types|Damage Type ID]] is used. | ||
*'''loss''': A float representing the amount of damage taken. | *'''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 X co-ordinate of where the damage took place. | ||
*''' | *'''damagePosY''': A float representing the Y co-ordinate of where the damage took place. | ||
*''' | *'''damagePosZ''': A float representing the Z co-ordinate of where the damage took place. | ||
*''' | *'''tireID''': A number representing the tire which took damage, if there is one. | ||
==Source== | ==Source== | ||
Line 22: | Line 22: | ||
==Cancel effect== | ==Cancel effect== | ||
If this event is [[Event system#Canceling|canceled]], the vehicle will | If this event is [[Event system#Canceling|canceled]], the vehicle health won't be reduced. Physical damage to the vehicle will remain. | ||
==Example== | ==Example== | ||
This example makes every SWAT tank immune from all weapon attacks. | This example makes every SWAT tank immune from all weapon attacks. | ||
<syntaxhighlight lang="lua"> | <section name="Client" class="client" show="true"><syntaxhighlight lang="lua"> | ||
function handleVehicleDamage(attacker, weapon, loss, x, y, z, | function handleVehicleDamage(attacker, weapon, loss, x, y, z, tire) | ||
if (weapon and getElementModel(source) == 601) then | 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. | -- A weapon was used and the vehicle model ID is that of the SWAT tank so cancel the damage. | ||
Line 34: | Line 34: | ||
end | end | ||
addEventHandler("onClientVehicleDamage", root, handleVehicleDamage) | addEventHandler("onClientVehicleDamage", root, handleVehicleDamage) | ||
</syntaxhighlight> | </syntaxhighlight></section> | ||
This example allows the Rhino to take damage from bullets even though they're bullet proof, this example doesn't work with explosions though. | 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"> | <section name="Client" class="client" show="true"><syntaxhighlight lang="lua"> | ||
-- Only let these weapons damage a Rhino | -- Only let these weapons damage a Rhino | ||
local weaponsToDamageRhino = { | local weaponsToDamageRhino = { | ||
Line 47: | Line 47: | ||
} | } | ||
function handleRhinoDamage(attacker, weapon, loss, x, y, z, | function handleRhinoDamage(attacker, weapon, loss, x, y, z, tire) | ||
if (weapon and getElementModel(source) == 432 and loss > 0) then | if (weapon and getElementModel(source) == 432 and loss > 0) then | ||
if (weaponsToDamageRhino[weapon]) then | if (weaponsToDamageRhino[weapon]) then | ||
Line 55: | Line 55: | ||
end | end | ||
addEventHandler("onClientVehicleDamage", root, handleRhinoDamage) | addEventHandler("onClientVehicleDamage", root, handleRhinoDamage) | ||
</syntaxhighlight> | </syntaxhighlight></section> | ||
This example will | This example will makes all vehicle Fireproof. | ||
<section name="Client" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function fireproofvehicle(theAttacker, theWeapon) | ||
if(theWeapon == 37) then | if(theWeapon == 37) then | ||
cancelEvent() | cancelEvent() | ||
end | end | ||
end | end | ||
addEventHandler("onClientVehicleDamage", getRootElement(), | addEventHandler("onClientVehicleDamage", getRootElement(), fireproofvehicle) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== |
Latest revision as of 13:51, 28 November 2019
This event is triggered when a vehicle is damaged.
Parameters
element theAttacker, int theWeapon, float loss, float damagePosX, float damagePosY, float damagePosZ, int tireID
- theAttacker: An element if there was an attacker.
- theWeapon: An integer specifying the weapon ID if a weapon was used. Otherwise Damage Type ID is used.
- loss: A float representing the amount of damage taken.
- damagePosX: A float representing the X co-ordinate of where the damage took place.
- damagePosY: A float representing the Y co-ordinate of where the damage took place.
- damagePosZ: A float representing the Z co-ordinate of where the damage took place.
- tireID: A number representing the tire 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 health won't be reduced. Physical damage to the vehicle will remain.
Example
This example makes every SWAT tank immune from all weapon attacks.
Click to collapse [-]
Clientfunction handleVehicleDamage(attacker, weapon, loss, x, y, z, tire) 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.
Click to collapse [-]
Client-- 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, tire) 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)
This example will makes all vehicle Fireproof.
Click to collapse [-]
Clientfunction fireproofvehicle(theAttacker, theWeapon) if(theWeapon == 37) then cancelEvent() end end addEventHandler("onClientVehicleDamage", getRootElement(), fireproofvehicle)
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