Strange problem with string -
bustern - 30.04.2014
CMD:
PHP код:
CMD:listpt(playerid, params[])
{
new online, string[128];
new Float:health;
if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
if(!IsMedic(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an Medic.");
foreach(Player, i)
{
if(IsDead[i])
{
online ++;
}
}
format(string, sizeof(string), "|_____ Patients waiting for trasport _____|");
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
foreach(Player, i)
{
GetPlayerHealth(i,health);
if(IsDead[i])
{
format(string, sizeof(string), " %s ,remaining health:%d ", RPN(i), health);
SendClientMessage(playerid, COLOR_LIME, string);
}
}
return 1;
Everything works good but it shows :remaining health:1321321 and random numbers....
Re: Strange problem with string -
[WSF]ThA_Devil - 30.04.2014
health is a float
instead of %d use %f
if you want it shorter, like 5.14 use %0.2f
All you're trying to do there, is represent float ( a number with a dot in it: 0.4 / 0.8 / 50.00001 ) as Integer ( A whole number ) 1 / 2 / 500 / 10000
Re: Strange problem with string -
Galletziz - 30.04.2014
Quote:
Originally Posted by [WSF]ThA_Devil
health is a float
instead of %d use %f
if you want it shorter, like 5.14 use %0.2f
All you're trying to do there, is represent float ( a number with a dot in it: 0.4 / 0.8 / 50.00001 ) as Integer ( A whole number ) 1 / 2 / 500 / 10000
|
quote.
Re: Strange problem with string -
bustern - 30.04.2014
ok thanks, now it shows 99.00000 how can i make it only 99 ?
AW: Strange problem with string -
Macronix - 30.04.2014
You could also use floatround(health), then the script rounds the value automatically for you to an integer
Re: Strange problem with string -
[WSF]ThA_Devil - 30.04.2014
try as i told you: %0.1f
that will do 99.1
Re: Strange problem with string -
Galletziz - 30.04.2014
pawn Код:
format(string, sizeof(string), " %s ,remaining health:%0.2f ", RPN(i), health);
Re: Strange problem with string -
[WSF]ThA_Devil - 30.04.2014
Quote:
Originally Posted by Galletziz
pawn Код:
format(string, sizeof(string), " %s ,remaining health:%0.2f ", RPN(i), health);
|
The thing you did there will do 99.00 ( 2 units behind the dot )
AW: Strange problem with string -
Macronix - 30.04.2014
Or just:
pawn Код:
format(string, sizeof(string), " %s ,remaining health:%d", RPN(i), floatround(health));
Re: Strange problem with string -
Konstantinos - 30.04.2014
Quote:
Originally Posted by bustern
ok thanks, now it shows 99.00000 how can i make it only 99 ?
|
Use: %.0f