SA-MP Forums Archive
KM/H to MPH. - 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: KM/H to MPH. (/showthread.php?tid=152519)



KM/H to MPH. - IcyBlight - 04.06.2010

Alright look, the GetPlayerSpeed function returns a value in KM/H. I wanted it in MPH, so I divide the result with 1.621 (1,621) to make it MPH. However, this gives me fucked up results like multiple millions. I know math isn't my strongest side but seriously, I thought this was simple enough?

pawn Код:
forward GetPlayerSpeed(playerid);
stock GetPlayerSpeed(playerid)
{
  new Float:ST[4];
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]); else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
  ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 253.3;
  return floatround(ST[3]);
}


forward UpdateSpeed(playerid);
public UpdateSpeed(playerid)
{
    new speed = GetPlayerSpeed(playerid);
    new speedstring[16];
    format(speedstring, sizeof speedstring, "%d MPH", speed/1.621); // Check this <--------
    TextDrawSetString(SpeedoSpeed, speedstring);
}



Re: KM/H to MPH. - Conroy - 04.06.2010

Try dividing in the stock.


Re: KM/H to MPH. - IcyBlight - 04.06.2010

Quote:
Originally Posted by Conroy
Try dividing in the stock.
Dividing in the second last line gave me an error, I'm gonna try it in the 'return'.


Re: KM/H to MPH. - IcyBlight - 04.06.2010

Yup, that did the trick.

pawn Код:
return floatround(ST[3]/1.621);
But the returned value seems way too large(and was before too).

Says my speed by tapping W is 85 MPH, and that the max speed of the Infernus is like 160-200.

Perhaps they are doubled.

If someone with some knowledge in speedometers could help me, it's appreciated.