SA-MP Forums Archive
Armour and Health - 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: Armour and Health (/showthread.php?tid=441019)



Armour and Health - Stefand - 01.06.2013

Quick Question how do I only show health and armour as 64 or 100 and not 64.00000

pawn Code:
new Float: SH, Float: SA;
                GetPlayerHealth(id, SH);
                GetPlayerArmour(id, SA);
                format(string, sizeof(string), "Name: %s, ID: %d, Health: %f, Armour: %f, Money: %d", RPName(id), id, SH, SA, GetPlayerMoney(id));
Do I need to change the %f to %d or will it bug since health is a float?


Re: Armour and Health - mahdi499 - 01.06.2013

Yes,Just switch from float to an integer switch the %f to %d


Re: Armour and Health - DetoNater - 01.06.2013

%f would be correct for it, no need to change it to %d


Re: Armour and Health - nmader - 01.06.2013

pawn Code:
new Float:fMyFloat = 1.3;
new nSomeInt = _:fMyFloat;
 
//nSomeInt is now 1.
This should help, it converts floats into integers.


Re: Armour and Health - Stefand - 01.06.2013

Quote:
Originally Posted by nmader
View Post
pawn Code:
new Float:fMyFloat = 1.3;
new nSomeInt = _:fMyFloat;
 
//nSomeInt is now 1.
This should help, it converts floats into integers.
Not working..

pawn Code:
new Float: SH, Float: SA;
                GetPlayerHealth(id, SH);
                GetPlayerArmour(id, SA);
                new SpecHealth = _:SH;
                new SpecArmour = _:SA;
                format(string, sizeof(string), "Name: %s, ID: %d, Health: %d, Armour: %d, Money: %d", RPName(id), id, SpecHealth, SpecArmour, GetPlayerMoney(id));
returns health in 1120403456


Re: Armour and Health - Konstantinos - 01.06.2013

Leave it as it is (float) and format it with the below placeholder.
pawn Code:
%.0f



Re: Armour and Health - DaRk_RaiN - 01.06.2013

Quote:
Originally Posted by _Zeus
View Post
Leave it as it is (float) and format it with the below placeholder.
pawn Code:
%.0f
Or you could just use floatround
pawn Code:
new Float: SH, Float: SA;
                GetPlayerHealth(id, SH);
                GetPlayerArmour(id, SA);
                //new SpecHealth = _:SH;
                //new SpecArmour = _:SA;
                format(string, sizeof(string), "Name: %s, ID: %d, Health: %d, Armour: %d, Money: %d", RPName(id), id, floatround(SpecHealth), floatround(SpecArmour), GetPlayerMoney(id));



Re: Armour and Health - Vince - 01.06.2013

Why go through that extra hassle when the placeholder works just as good (and faster)? That makes no sense at all.