## 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.")

```

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

I tested but it doesn't work. How does it not work? Say what you did, how you tested it, how you put it in your scripts, what errors appeared in debugscript, etc.

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.

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 ^

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.

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.

Thank you. GTA's distance unit is indeed equal to one meter (http://gta.wikia.com/Unit#GTA3.2C_GTAVC_.26_GTASA), I was just not aware of the 1/50 quirk.