Sign in to follow this  
proracer

getElementVelocity

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

Share this post


Link to post

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) 

Share this post


Link to post

How does it not work? :roll:

Say what you did, how you tested it, how you put it in your scripts, what errors appeared in debugscript, etc.

Share this post


Link to post

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.

Share this post


Link to post
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 ^

Share this post


Link to post
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.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.