SA-MP Forums Archive
Floats. "xx.0000000000" - 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: Floats. "xx.0000000000" (/showthread.php?tid=194339)



Floats. "xx.0000000000" - TaMeD - 29.11.2010

Alright, so, I hate asking for help sometimes.. but I don't know what's happening.

pawn Код:
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)) * 180;
    return floatround(ST[3]);
}
I'm using this stock (credits to who made it) and Im' trying to make a simple speedo;
pawn Код:
new Float:speed = GetPlayerSpeed(playerid);
        format(string,sizeof(string), "%f KM/H", speed);
        TextDrawSetString(Speed[playerid], string);
However, in game, I get xx.00000000 KM/H. If someone could tell me how to limit the 0's, that'd be really fantastic! Thanks


Re: Floats. "xx.0000000000" - JaTochNietDan - 29.11.2010

Simply because you are defining the speed as a float, when in fact the function you have posted actually returns an integer and not a float. So instead of speed being a float, it should be an integer, which means your code should be this:

pawn Код:
new speed = GetPlayerSpeed(playerid);
format(string,sizeof(string), "%d KM/H", speed);
TextDrawSetString(Speed[playerid], string);