Jump to content

onClientVehicleCollision problem


Recommended Posts

I got my other scripts to work, so I think it should be okay if I asked for some help here.

I want to get vehicle's speed before he hits another vehicle, the problem is, it always returns the same speed (180 or 179kph), no matter how fast or slow I'm going. What I'm doing wrong here?

http://wiki.multitheftauto.com/wiki/OnC ... eCollision

function collision(collider,force, bodyPart, x, y, z, vx, vy, vz) 
if (getElementType (collider) == "vehicle") and (source == getPedOccupiedVehicle (getLocalPlayer())) then 
    actualspeed = (vx^2 + vy^2 + vz^2)^(0.5)  
    kmh = actualspeed * 180 
    outputChatBox(kmh) 
    end 
end 
addEventHandler("onClientVehicleCollision", root, collision) 

Link to comment
But that event is triggered on collision, how do you expect to get the speed before hit on the event that is triggered on collision?

read the wiki, it says :

velocityX: the X velocity of the source before the collision took place

velocityY: the Y velocity of the source before the collision took place

velocityZ: the Z velocity of the source before the collision took place

Link to comment

Forget about what I said.

function collision ( collider, force, bodyPart, x, y, z, vx, vy, vz ) 
    if (getElementType (collider) == "vehicle") and (source == getPedOccupiedVehicle (getLocalPlayer())) then 
        actualspeed = ( vx ^ 2 + vy ^ 2 + vz ^ 2 ) ^ 0.5 * 1.61 * 100 
        outputChatBox ( actualspeed ) 
    end 
end 
addEventHandler("onClientVehicleCollision", root, collision) 

I copied how getElementSpeed function works, try it.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...