Vehicle Speed [SOLVED] - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicle Speed [SOLVED] (
/showthread.php?tid=150039)
Vehicle Speed [SOLVED] -
Sascha - 24.05.2010
Hi...how can I get the speed of a vehicle in a string or so...
(please do not send me the link of GetVehicleVelozity, I wanne show it as a single number like 120 km/h)
Re: Vehicle Speed -
Fj0rtizFredde - 24.05.2010
Use this function:
pawn Код:
stock GetPlayerSpeed(playerid, bool:kmh) // by misco
{
new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}
Then I think you can do the rest
Re: Vehicle Speed -
Sascha - 24.05.2010
yeap thank you very much
Re: Vehicle Speed -
Sascha - 25.05.2010
Quote:
Originally Posted by Fj0rtizFredde
Then I think you can do the rest 
|
tehe...seems as if I can't lol..
what is do I have to add as the "bool:kmh" on the textdraw?

... I got: GetPlayerSpeed(i, ButIDontKnowWhatHere

)
Re: Vehicle Speed [still need help:D] -
Fj0rtizFredde - 25.05.2010
You just put true for km/h or false for mph :P
Like:
pawn Код:
new str[128];
format(str,128,"My speed is %d km/h and %d mph !",GetPlayerSpeed(playerid,true),GetPlayerSpeed(playerid,false));
Re: Vehicle Speed [still need help:D] -
RyDeR` - 25.05.2010
If you don't understand how to get the speed here's a quick sketch:
1. Get players vehicle velocity.
2. Use this formula to get the speed then.
Код:
√((x * x) + (y * y) + (z * z))
However it can be done in an other way:
Код:
√((x ^ 2) + (y ^ 2) + (z ^ 2))
Note: √ = floatsqroot in PAWN language.
Note2: You will not get the exact speed so you have to multiply everything with a value you have to test out.
I know the solution is given above but this is just a sketch for people who don't know how
Regards
Re: Vehicle Speed [still need help:D] -
¤Adas¤ - 25.05.2010
Yes, you have to multiply it with 200.0.
Re: Vehicle Speed [still need help:D] -
Sascha - 25.05.2010
thank you guys very much

...I just tried to find out how to use the floatsqroot etc which fredde used in the script but the pages on wiki aren't finished yet
Re: Vehicle Speed [still need help:D] -
Sascha - 25.05.2010
well it works now, but it is only correct if I drive on angle 180/0 :P..it goes up/down if I drive on other angles..

<--solved