Strange problem with string
#1

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....
Reply
#2

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
Reply
#3

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.
Reply
#4

ok thanks, now it shows 99.00000 how can i make it only 99 ?
Reply
#5

You could also use floatround(health), then the script rounds the value automatically for you to an integer
Reply
#6

try as i told you: %0.1f
that will do 99.1
Reply
#7

pawn Код:
format(string, sizeof(string), " %s ,remaining health:%0.2f ", RPN(i), health);
Reply
#8

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 )
Reply
#9

Or just:
pawn Код:
format(string, sizeof(string), " %s ,remaining health:%d", RPN(i), floatround(health));
Reply
#10

Quote:
Originally Posted by bustern
Посмотреть сообщение
ok thanks, now it shows 99.00000 how can i make it only 99 ?
Use: %.0f
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)