SA-MP Forums Archive
Calculate vehicle's speed in KM/h - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Calculate vehicle's speed in KM/h (/showthread.php?tid=345273)



Calculate vehicle's speed in KM/h - Verbal - 24.05.2012

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 !


Re: Calculate vehicle's speed in KM/h - Mandrakke - 24.05.2012

https://sampwiki.blast.hk/wiki/Useful_Fu...GetPlayerSpeed


Re: Calculate vehicle's speed in KM/h - Verbal - 24.05.2012

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


Re: Calculate vehicle's speed in KM/h - JaTochNietDan - 24.05.2012

Код:
(((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.


Re: Calculate vehicle's speed in KM/h - Mandrakke - 24.05.2012

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


Re: Calculate vehicle's speed in KM/h - Verbal - 24.05.2012

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


Re: Calculate vehicle's speed in KM/h - spedico - 24.05.2012

Float, convert to INT if needed.

floatval()


Re: Calculate vehicle's speed in KM/h - milanosie - 24.05.2012

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.


Re: Calculate vehicle's speed in KM/h - Verbal - 24.05.2012

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.


Re: Calculate vehicle's speed in KM/h - spedico - 24.05.2012

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