Floats. "xx.0000000000"
#1

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)