Help with Format(...)
#1

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

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

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

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

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

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

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

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

Thanks
Reply
#10

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


Forum Jump:


Users browsing this thread: 3 Guest(s)