vehicle health rounding
#1

I have this command here

pawn Код:
public Gage()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInAnyVehicle(i))
            {
                new Float:health,Float:speedx,Float:speedy,Float:speedz,vehicleid = GetPlayerVehicleID(i),Float:editspeed,finalspeed,string[256];
                GetVehicleVelocity(vehicleid,speedx,speedy,speedz);
                editspeed = floatsqroot(((speedx*speedx)+(speedy*speedy))+(speedz*speedz))*136.666667;
                finalspeed = floatround(editspeed,floatround_round);
                format(string,sizeof(string),"Speed: %i",finalspeed);
                TextDrawSetString(Textdraw0[i],string);
                GetVehicleHealth(vehicleid,health);
                format(string,sizeof(string),"Health: %i",floatround(health));
                TextDrawSetString(Textdraw1[i],string);
                format(string,sizeof(string),"Fuel: %i",fuel[vehicleid]);
                TextDrawSetString(Textdraw2[i],string);
            }
        }
    }
    return 1;
}
on the health tab it displays as 1000 instead of 100 how would I round the number
Reply
#2

format(string,sizeof(string),"Health: %f",health/10);

But you ve got to make the i, f and remove the floartround so that values like 566 become 56.6.
Reply
#3

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
format(string,sizeof(string),"Health: %f",health/10);

But you ve got to make the i, f and remove the floartround so that values like 566 become 56.6.
ok I did what you said but now it is giveing me 100.0000000
Reply
#4

Don't change the %i to a %f. Since you rounded the health it turns it into an integer so you need to use %i.
Reply
#5

Well consider this vehicles catch fire when their HP reaches 250 then explode at 0.0, I would recommend doing this when calculating your vehicle health percentage....

health -= 250.0;
if(health <= 0.0) string = "Health: 0.00";
else format(string,sizeof(string),"Health: %0.2f",floatmul(floatdiv(health, 750.0), 100));
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)