Minutes, seconds, miliseconds -
MP2 - 23.02.2011
I need to show a racer's laptime when they finish a race, and some races can be several minutes long so I need something like
'1 minute, 2.55 seconds'
Thanks in advance.
AW: Minutes, seconds, miliseconds -
Kmitska - 23.02.2011
You just need a timer for this like:
//At the top of your script
new sec,min,hour,time;
forward Counter();
main()
{
time = SetTimer("Counter",1000,1);
}
public Counter()
{
sec ++;
if(sec == 60) { sec=0; min++; }
if(min == 60) { min=0; h++; }
return 1;
}
/*
and if the player ends the race you just need to kill the timer like this: KillTimer(time);
*/
Re: Minutes, seconds, miliseconds -
MP2 - 23.02.2011
I need miliseconds. Don't suggest using a timer please, I don't want that.
Re: Minutes, seconds, miliseconds -
Momo5000 - 23.02.2011
use GetTickCount().
Example:
Код:
new RaceTimeMS;
Public StartRace()
{
RaceTimeMS = GetTickCount();
}
public StopRace()
{
return (GetTickCount() - RaceTimeMS);
}
Use StartRace() if the race starts and StopRace() to stop the race.
StopRace() will return the time elapsed time since the start in milliseconds.
Re: Minutes, seconds, miliseconds -
maramizo - 23.02.2011
pawn Код:
new ms,sec,min,hour,time;
pawn Код:
main()
{
time = SetTimer("Counter",1,1);
}
public Counter()
{
ms ++;
if(ms == 1000) { ms=0; sec++; }
if(sec == 60) { sec=0; min++; }
if(min == 60) { min=0; h++; }
return 1;
}
But yeah that would probably fuck up your server with lag, dunno though lol.
Re: Minutes, seconds, miliseconds -
Momo5000 - 23.02.2011
GetTickCount() will do the job without using a timer set to 1 millisecond lol.
Re: Minutes, seconds, miliseconds -
maramizo - 23.02.2011
Quote:
Originally Posted by Momo5000
GetTickCount() will do the job without using a timer set to 1 millisecond lol.
|
I was just kidding lol.
Btw epic signature
Re: Minutes, seconds, miliseconds -
Momo5000 - 23.02.2011
*epic facepalm is epic*
Re: Minutes, seconds, miliseconds -
MP2 - 23.02.2011
Quote:
Originally Posted by Momo5000
use GetTickCount().
Example:
Код:
new RaceTimeMS;
Public StartRace()
{
RaceTimeMS = GetTickCount();
}
public StopRace()
{
return (GetTickCount() - RaceTimeMS);
}
Use StartRace() if the race starts and StopRace() to stop the race.
StopRace() will return the time elapsed time since the start in milliseconds.
|
Can you tell me how to convert that into mins, seconds and miliseconds? So it's like '3 minutes 6.33 seconds'?
I know how to do minutes and seconds like this:
pawn Код:
new minutes, seconds;
minutes = (seconds % 60);
seconds = (seconds / 60);
Re: Minutes, seconds, miliseconds -
(SF)Noobanatior - 24.02.2011
yes i can like this
pawn Код:
// code from Dabombber
timeconvert(playerid)
{
timetotal[playerid] = floatdiv(timetotal[playerid], 60000);
minutes[playerid] = floatround(timetotal[playerid], floatround_tozero);
seconds[playerid] = floatround(floatmul(timetotal[playerid] - minutes[playerid], 60), floatround_tozero);
mseconds[playerid] = floatround(floatmul(floatmul(timetotal[playerid] - minutes[playerid], 60) - seconds[playerid], 1000), floatround_tozero);
}