Race time help
#1

Hello

I need help with something

I have a race timer:

Код:
RaceInfo[raceid][racetimer] = SetTimerEx("RaceTime", 100, true, "dd", raceid,i);
And the timer function:

Код:
function RaceTime(raceid,playerid)
{
RaceInfo[raceid][racetime] ++;
if(floatround((RaceInfo[raceid][racetime] / 10), floatround_floor) >= RaceInfo[raceid][racetimeout]) StopRace(raceid);
new string[512];
format(string, sizeof(string),"%s~n~Time:%s~n~Checkpoints:%d/%d",RaceInfo[raceid][racename],ReturnTime(RaceInfo[raceid][racetime]),RaceCheckpoint[playerid]-2,RaceInfo[raceid][cpnum] - 1);
PlayerTextDrawSetString(playerid,RaceTextDraw[playerid][0],string);
return 1;
}

Now how do I make that it will show me numbers like: 1:19:289 Now it shows me just 1:19:200



I have this converter:

Код:
stock ReturnTime(timevariable)
{
new milliseconds = timevariable, seconds, minutes, string[20];
while(milliseconds > 9)
{
seconds ++;
milliseconds = milliseconds - 10;
}
while(seconds > 59)
{
minutes ++;
seconds = seconds - 60;
}
format(string, sizeof(string), "%d:0%d:%d00", minutes, seconds, milliseconds);
return string;
}
Now:

Reply
#2

Unless you visually update the race time during the race, don't rely on timers. Timers are roughly 20% off and this deviation will only increase the more iterations you do. They're completely unreliable when it comes to measuring any amount of time.

Use GetTickCount() and/or gettime() for the most accurate results. Save the timestamp at the beginning and get a new one whenever you need to show the time. Subtract them to find out the difference.

Using loops to convert time is also reinventing the wheel, because the modulo operator exists. This should do. Could probably be written a little shorter, but I just wrote this up of the top of my head.
PHP код:
ms_to_time(input, &hours, &minutes, &seconds, &milliseconds)
{
    
milliseconds input 1000;
    
    
input -= milliseconds;
    
input /= 1000
    
    
seconds input 60;
    
input -= seconds;
    
input /= 60
    
    
minutes input 60;
    
input -= minutes;
    
input /= 60
    
    
hours input;

Reply
#3

Hmm ok I will do it Thanks for advice VINCE!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)