Converting Milliseconds into Minutes and Seconds?
#1

hey guys, i have a command for the racing system that i use that allows me to view the current record of the active race.

it works perfectly well, it tells me the players name and also their time, but the thing is, their time is displayed in milliseconds and it just looks ugly saying "Their Time: 87111".

I was wondering how I could possibly convert that to say "Their Time: 1:37.111" instead.

here is my entire command

PHP Code:
CMD:racerecorddebug(playeridparams[])
{
    new 
rFile[256];
    new 
string[64];
    new 
string2[64];
    new 
string3[64];
    new 
string4[64];
    
format(rFilesizeof(rFile), "/rRaceSystem/%s.RRACE"RaceName);
    
format(stringsizeof(string), "BestRacer_0");
     
format(string2sizeof(string2), "BestRacerTime_0");
     
format(string3sizeof(string3), "Current Race Record held By: %s. "dini_Get(rFilestring));
     
format(string4sizeof(string4), "Their Time: %s"dini_Get(rFilestring2));
     
    
SendClientMessage(playeridGREENstring3);
    
SendClientMessage(playeridGREENstring4);
    return 
1;

Reply
#2

Well i got the code for it, lemme find it out
Reply
#3

thanks but i'm not here showing it off lol.

I'm wondering how I can convert the milliseconds into Minutes/Seconds/Milliseconds instead.
Reply
#4

This might give you an idea how to do it.
http://stackoverflow.com/questions/2...es-and-seconds
Reply
#5

gave it a look, not a clue. I'm actually terrible at conversions. I've tried something similar but keeps giving me some error about the string not being indexed. The difficulty I can see doing this is very hard.

Tryna turn 87111 into 1:37.111 into the chat for players to see, from a file, very hard (for me that is)

Anyone have any example scripts?
Reply
#6

pawn Code:
new minutes = time/60000;
new seconds = (time%60000)/1000;
new milliseconds = (time%1000);
new str[32];
format(str, sizeof(str), "Time: %02d:%02d.%03d", minutes, seconds, milliseconds);
SendClientMessage(playerid, -1, str);
Reply
#7

ok, this is what my command looks like now.

PHP Code:
CMD:racerecorddebug(playeridparams[])
{
    new 
time;
    new 
rFile[256];
    new 
string[64];
    new 
string2[64];
    new 
string3[64];
    new 
string4[64];
    
time dini_Int(rFilestring2);
    new 
minutes time/60000;
    new 
seconds = (time%60000)/1000;
    new 
milliseconds = (time%1000);
    
format(rFilesizeof(rFile), "/rRaceSystem/%s.RRACE"RaceName);
    
format(stringsizeof(string), "BestRacer_0");
     
format(string2sizeof(string2), "BestRacerTime_0");
     
format(string3sizeof(string3), "Current Race Record held By: %s. "dini_Get(rFilestring));
     
format(string4sizeof(string4), "Their Time: %02d:%02d.%03d"dini_Get(rFilestring2), minutessecondsmilliseconds);
     
    
SendClientMessage(playeridGREENstring3);
    
SendClientMessage(playeridGREENstring4);
    return 
1;

this is an image from ingame when i view the race record



this is the string from the file that BestRacerTimer_0 refers to



i'm not quite sure where I have gone wrong
Reply
#8

you forgot to format 'string2' before you get the value from the file.
So put
pawn Code:
format(string2, sizeof(string2), "BestRacerTime_0");
before
pawn Code:
time = dini_Int(rFile, string2);

Edit: Oh and you also shouldn't use that dini_function when you format the message.
...and you also don't need to format the string you want to get from the file. In this case you can get rid of string1 and string2

Here is how it should look:

pawn Code:
CMD:racerecorddebug(playerid, params[])
{
    new time;
    new rFile[256];
    new string3[64];
    new string4[64];
    format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", RaceName);  
    time = dini_Int(rFile, "BestRacerTime_0");
    new minutes = time/60000;
    new seconds = (time%60000)/1000;
    new milliseconds = (time%1000);  
    format(string3, sizeof(string3), "Current Race Record held By: %s. ", dini_Get(rFile, "BestRacer_0"));
    format(string4, sizeof(string4), "Their Time: %02d:%02d.%03d", minutes, seconds, milliseconds);
    SendClientMessage(playerid, GREEN, string3);
    SendClientMessage(playerid, GREEN, string4);
    return 1;
}
Edit 2:
Here's an even shorter version:

pawn Code:
CMD:racerecorddebug(playerid, params[])
{
    new rFile[32], string[64];
    format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", RaceName);  
    new time = dini_Int(rFile, "BestRacerTime_0");  
    format(string, sizeof(string), "Current Race Record held By: %s. ", dini_Get(rFile, "BestRacer_0"));
    SendClientMessage(playerid, GREEN, string);
    format(string, sizeof(string), "Their Time: %02d:%02d.%03d", time/60000, (time%60000)/1000, (time%1000));      
    SendClientMessage(playerid, GREEN, string);
    return 1;
}
Reply
#9

edit:


your last method worked perfectly, thanks for all the help !

i realised i said 1:38 instead of 1:28, god, i suck at maths D:

but thanks for the tips, repped.
Reply
#10

Try this:
Shorter code, but works the same:
pawn Code:
CMD:racerecorddebug(playerid, params[])
{
    new rFile[32], string[64];
    format(rFile, sizeof(rFile), "/rRaceSystem/%s.RRACE", RaceName);  
    new time = dini_Int(rFile, "BestRacerTime_0");  
    format(string, sizeof(string), "Current Race Record held By: %s. ", dini_Get(rFile, "BestRacer_0"));
    SendClientMessage(playerid, GREEN, string);
    format(string, sizeof(string), "Their Time: %02d:%02d.%03d", time/60000, (time%60000)/1000, (time%1000));      
    SendClientMessage(playerid, GREEN, string);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)