Calculate vehicle's speed in KM/h
#1

Hey, what's up?
I'm having troubles with calculation a vehicle's speed in KM/h.. I really can't do it :S
I'd appreciate if you'd help me, or give me a function/stock that calculates it.
Thanks !
Reply
#2

https://sampwiki.blast.hk/wiki/Useful_Fu...GetPlayerSpeed
Reply
#3

I'm not going to include this whole include for just a textdraw..
Reply
#4

Код:
(((x ^ 2) + (y ^ 2) + (z ^ 2)) * 100) * 1.6)
That's the formula for calculating speed in kilometers, where x,y,z is the current velocity of the player in each direction.
Reply
#5

You could download the include and see in the source the calculation, but JatochNietDan already post it.
Reply
#6

Thanks. It should return it as an int or float?
Reply
#7

Float, convert to INT if needed.

floatval()
Reply
#8

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Код:
(((x ^ 2) + (y ^ 2) + (z ^ 2)) * 100) * 1.6)
That's the formula for calculating speed in kilometers, where x,y,z is the current velocity of the player in each direction.
Actually, * 1.6 Isn't working the right way.

*187.666667 would work better.
Reply
#9

I did this:
pawn Код:
format(str, sizeof(str), "KM/h: %d", GetVehicleSpeed(0));
SendClientMessage(playerid, 0xFFFFFFAA, str);

stock GetVehicleSpeed(vehicleid)
{
    new Float:v[3];
    GetVehicleVelocity(vehicleid, v[0], v[1], v[2]);
    return (((v[0] ^ 2) + (v[1] ^ 2) + (v[2] ^ 2)) * 100) * 187.666667;
}
But it gives me those errors:
Код:
vb-livecam.pwn(229) : warning 213: tag mismatch
vb-livecam.pwn(229) : warning 213: tag mismatch
vb-livecam.pwn(229) : warning 213: tag mismatch
vb-livecam.pwn(229) : warning 213: tag mismatch
Line 229 is this:
pawn Код:
return (((v[0] ^ 2) + (v[1] ^ 2) + (v[2] ^ 2)) * 100) * 187.666667;
But if I won't use the "format" I won't get any warnings.
Reply
#10

Try this:
pawn Код:
stock GetVehicleSpeed(vehicleid)
{
    new Float:V[3];
    GetVehicleVelocity(vehicleid, V[0], V[1], V[2]);
    return floatround(floatsqroot(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) * 180.00);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)