SA-MP Forums Archive
vehicle health rounding - 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)
+--- Thread: vehicle health rounding (/showthread.php?tid=433556)



vehicle health rounding - horsemeat - 27.04.2013

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


AW: vehicle health rounding - HurtLocker - 27.04.2013

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.


Re: AW: vehicle health rounding - horsemeat - 27.04.2013

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


Re: vehicle health rounding - Chenko - 27.04.2013

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.


Re: vehicle health rounding - Pottus - 27.04.2013

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