Vehicle Speed [SOLVED]
#1

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)
Reply
#2

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
Reply
#3

yeap thank you very much
Reply
#4

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)
Reply
#5

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));
Reply
#6

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
Reply
#7

Yes, you have to multiply it with 200.0.
Reply
#8

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
Reply
#9

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)