OnClientVehicleCollision: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Scaled marker + made it only for local players vehicle)
mNo edit summary
Line 4: Line 4:
{{Client event}}
{{Client event}}
__NOTOC__  
__NOTOC__  
This event is triggered when a vehicle collides with something.
This event is triggered when a vehicle collides with peds/vehicles/objects but not buildings.


Note: collidedWith will be false if it's a default SA object and it will trigger twice for vehicles because one vehicle hit another and one got hit by another.
==Parameters==  
==Parameters==  
collidedWith, force, bodyPart, collisionX, collisionY, collisionZ,
collidedWith, force, bodyPart, collisionX, collisionY, collisionZ,

Revision as of 10:26, 11 January 2012

Added in MTA SA 1.3

This event is triggered when a vehicle collides with peds/vehicles/objects but not buildings.

Note: collidedWith will be false if it's a default SA object and it will trigger twice for vehicles because one vehicle hit another and one got hit by another.

Parameters

collidedWith, force, bodyPart, collisionX, collisionY, collisionZ, velocityX, velocityY, velocityZ

Source

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

Example

addEventHandler("onClientVehicleCollision", getRootElement(),
    function(collider,force, bodyPart, x, y, z, vx, vy, vz)
         if ( source == getPedOccupiedVehicle(getLocalPlayer() ) 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 delt
             local fDamageMultiplier = getVehicleHandling(source).collisionDamageMultiplier
             -- Create a marker (I've scaled this down to 1% of the actual damage as we get huge markers else)
             local m = createMarker(x, y, z, "corona", force * fDamageMultiplier * 0.01, 0, 9, 231)
             -- Destroy the marker in 2 seconds
             setTimer(destroyElement, 2000, 1, m)
         end
    end
)

See Also

Client vehicle events


Client event functions