KM/H to MPH.
#1

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

Try dividing in the stock.
Reply
#3

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'.
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)