SA-MP Forums Archive
Help with Format(...) - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with Format(...) (/showthread.php?tid=204759)



Help with Format(...) - [NWA]Hannes - 30.12.2010

Hello, I have this piece of code:

pawn Код:
//Above GameModeInit
new Uptime:
//OnGameModeInit:
Uptime = GetTickCount();
//In a command
{
    new timestr[20], uptimeex;
    uptimeex = GetTickCount() - Uptime;
    format(timestr, sizeof(timestr), "%d", uptimeex);
    SendClientMessage(playerid, 0xFFFFFFFF, timestr);
    return 1;
}
And if my server has been on for 10.5 seconds, i get 10500 when i type the command. (I know its milliseconds.)
And if i do this instead:
format(timestr, sizeof(timestr), "%d", uptimeex/1000);
I get 105.

Wich i want to change to 10.5, any idea how to do this?


Re: Help with Format(...) - _rAped - 30.12.2010

pawn Код:
format(timestr, sizeof(timestr), "%d.1", uptimeex/1000);



Re: Help with Format(...) - MadeMan - 30.12.2010

pawn Код:
format(timestr, sizeof(timestr), "%.1f", floatdiv(uptimeex, 1000));



Re: Help with Format(...) - _rAped - 30.12.2010

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
pawn Код:
format(timestr, sizeof(timestr), "%.1f", floatdiv(uptimeex, 1000));
Oups, yeah that would be the correct format. I should concider going to bed soon.


Re: Help with Format(...) - [NWA]Hannes - 30.12.2010

Ok i changed it to this:
pawn Код:
new timestr[20], uptimeex;
uptimeex = GetTickCount() - Uptime;
if(uptime < 60000) format(timestr, sizeof(timestr), "%.1f seconds", floatdiv(uptimeex, 1000));
if(uptime > 60000) format(timestr, sizeof(timestr), "%d minutes and %.1f seconds", uptimeex/1000/60, floatdiv(uptimeex, 1000));
SendClientMessage(playerid, 0xFFFFFFFF, timestr);
return 1;
But if server has been on for 10 minutes and 10 seconds it shows:
10 minutes and 610 seconds.
Wich is correct but i want seconds to reset evry minute so it shows in 0-59 format.


Re: Help with Format(...) - MadeMan - 30.12.2010

pawn Код:
if(uptime > 60000) format(timestr, sizeof(timestr), "%d minutes and %d seconds", uptimeex/1000/60, uptimeex/1000%60);



Re: Help with Format(...) - [NWA]Hannes - 30.12.2010

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
pawn Код:
if(uptime > 60000) format(timestr, sizeof(timestr), "%d minutes and %d seconds", uptimeex/1000/60, uptimeex/1000%60);
Ok if i had server on for 10 minutes and 10.3 seconds it shows like this:
10 minutes and 10 seconds
and i want
10 minutes and 10.3 seconds


Re: Help with Format(...) - MadeMan - 30.12.2010

pawn Код:
if(uptime > 60000) format(timestr, sizeof(timestr), "%d minutes and %d.%d seconds", uptimeex/1000/60, uptimeex/1000%60, uptimeex%1000);



Re: Help with Format(...) - [NWA]Hannes - 30.12.2010

Thanks


Re: Help with Format(...) - [NWA]Hannes - 30.12.2010

When i raced for 31.631 seconds i get
"31.6 seconds" as i want.
But when i race for 1 minute and 31.631 seconds i get
"1 minute and 31.631 seconds", but i want "1 minute 31.6 seconds"
if its possible.