SA-MP Forums Archive
Strange problem with string - 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: Strange problem with string (/showthread.php?tid=510230)



Strange problem with string - bustern - 30.04.2014

CMD:
PHP код:
CMD:listpt(playeridparams[])
{
    new 
onlinestring[128];
    new 
Float:health;
    if(!
IsPlayerLoggedIn(playerid)) return SendClientMessage(playeridCOLOR_GREY"You need to login first before using any command.");
    if(!
IsMedic(playerid)) return SendClientMessage(playeridCOLOR_GREY"You are not an Medic.");
    foreach(
Playeri)
    {
        if(
IsDead[i])
        {
            
online ++;
        }
    }
    
format(stringsizeof(string), "|_____ Patients waiting for trasport _____|");
    
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
    foreach(
Playeri)
    {
    
GetPlayerHealth(i,health);
        if(
IsDead[i])
        {
            
format(stringsizeof(string), " %s ,remaining health:%d "RPN(i), health);
            
SendClientMessage(playeridCOLOR_LIMEstring);
        }
    }
    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