Jump to content

getElementVelocity


proracer

Recommended Posts

So I was trying to make script which does, when you reach example 100 km/h it outputs some message.

But I don't know how to create that part, when some player reaches some speed.

I tried and this code, but ofcourse its not good.

function getVehicleSpeed() 
speedx, speedy, speedz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()) 
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) 
if (actualspeed) = 100 then -- i know this isn't good, if you know please tell me. 
outputChatBox ("Nice speed man.") 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource)) 

Link to comment

One possibility would be to check the speed every second:

function checkSpeed() 
    speedx, speedy, speedz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()) 
    actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) 
    if (actualspeed) >= 100 then 
        outputChatBox ("Nice speed man.") 
        killTimer ( timer1 ) 
    end 
end 
timer1 = setTimer(checkSpeed, 1000, 0) 

Link to comment

The actualspeed variable must still be multiplied by a factor greater than 1 in order to yield a useful value.

However there's no conclusive argument on what exactly is the unit of the getElementVelocity value. On scripts available at the community site, I've seen people multiply it by 100, 160 or even by 200.

Link to comment
One possibility would be to check the speed every second:
function checkSpeed() 
    speedx, speedy, speedz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()) 
    actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) * 100 * 1.61 
    if (actualspeed) >= 100 then 
        outputChatBox ("Nice speed man.") 
        killTimer ( timer1 ) 
    end 
end 
timer1 = setTimer(checkSpeed, 1000, 0) 

Use this one ^

Link to comment
However there's no conclusive argument on what exactly is the unit of the getElementVelocity value. On scripts available at the community site, I've seen people multiply it by 100, 160 or even by 200.

There is. It's number of GTA units per 1/50 seconds. I'm not sure about GTA units, maybe they're metres, so element velocity x50 is m/s, x180 is km/h.

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...