Minutes, seconds, miliseconds
#1

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

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);
*/
Reply
#3

I need miliseconds. Don't suggest using a timer please, I don't want that.
Reply
#4

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

pawn Код:
new ms,sec,min,hour,time;
pawn Код:
forward Counter();
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.
Reply
#6

GetTickCount() will do the job without using a timer set to 1 millisecond lol.
Reply
#7

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

*epic facepalm is epic*
Reply
#9

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);
Reply
#10

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);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)