onClientVehicleCollision | Multi Theft Auto: Wiki Skip to content

onClientVehicleCollision

Client-side
Server-side
Shared

This event is triggered when a vehicle collides with an element or a world object.

This event is only triggered for vehicles that are streamed in

Parameters

element theHitElement, float damageImpulseMag, int bodyPart, float collisionX, float collisionY, float collisionZ, float normalX, float normalY, float normalZ, float hitElementForce, int model
  • theHitElement: the other entity, or nil if the vehicle collided with the world
  • damageImpulseMag: the impact magnitude (Note: this is NOT the damage it is a force value which is then multiplied by the vehicles collision damage multiplier. for an example of this see below)
  • bodyPart: the bodypart that hit the other element 0: Frame 2: Trunk 3: Hood 4: Rear 5: Front left door 6: Front right door 7: Rear left door 8: Rear right door 13: Front Left tyre 14: Front Right tyre 15: Back Left tyre 16: Back Right tyre
  • collisionX: the X coordinate of the position the collision took place
  • collisionY: the Y coordinate of the position the collision took place
  • collisionZ: the Z coordinate of the position the collision took place
  • normalX: the X coordinate of the surface normal of the hit object
  • normalY: the Y coordinate of the surface normal of the hit object
  • normalZ: the Z coordinate of the surface normal of the hit object
  • hitElementForce: 0 for non vehicles or the force of the other vehicle
  • model: model of the hit element (useful to detect building collisions as hitElement will be nil)

Source

element: The source of this event is the vehicle that collided with something.

Code Examples

client
addEventHandler("onClientVehicleCollision", root,
function(collider, damageImpulseMag, bodyPart, x, y, z, nx, ny, nz)
if ( source == getPedOccupiedVehicle(localPlayer) ) then
-- force does not take into account the collision damage multiplier (this is what makes heavy vehicles take less damage than banshees for instance) so take that into account to get the damage dealt
local fDamageMultiplier = getVehicleHandling(source).collisionDamageMultiplier
-- Create a marker (Scaled down to 1% of the actual damage otherwise we will get huge markers)
local m = createMarker(x, y, z, "corona", damageImpulseMag* fDamageMultiplier * 0.01, 0, 9, 231)
-- Destroy the marker in 2 seconds
setTimer(destroyElement, 2000, 1, m)
end
end
)

See Also

Vehicle Functions