Race times.. Linux server
#1

I've searched around and read some thing about GetTickCount not working on linux, not sure if its still returns minus or not.

So i'd like to know how i can do the times on races using minutes, seconds and milliseconds.

So it would be like this.. MM:SS.ms or 01:42.54

One minute Fourty Two seconds and 54 milliseconds.

If GetTickCount works in linux, how could i convert the ms into the format above?


Reply
#2

anyone?
Reply
#3

You'd have to make a 10 ms timer that adds to a server wide variable. Then when the rae starts you save a player specific variable with the value that the time variable has, then at the end, you take the current time and subtract it from the player's held time, and you'd get how many 10ths of a second it took for them to finish.
Reply
#4

Cant i jsut use GetTickCount? I tried and it gives a positive value, i just dont know how to convert it to mms.ms
Reply
#5

Well 1 second is 1000 milliseconds... and 1 minute is 60 seconds... Ahh the power of Arithmetic.
Reply
#6

pawn Код:
ConvertTime(time, &minutes, &seconds, &milliseconds) {

  for(new i; i<1000; i++) {
    if(time >= 1000) {
      time = time-1000;
      seconds++;
      if(seconds == 60) {
        seconds = 0;
        minutes++;
      }
    }else{
      milliseconds = time;
      break;
    }
  }
}
Have fun SAFC
Reply
#7

pawn Код:
converttime(time,&h,&m,&s,&ms)
{
    ms=time;
    s=ms/1000;
    ms-=second*1000;
    m=s/60;
    s-=m*60;
    h=m/60;
    m-=h*60;
}
Much much faster, no use of loops.
Reply
#8

Thanks guys, i checked it against a real life timer and its pretty accurate.

How do i get it to show 2minutes 10 seconds or 1 second and 54 ms as 2:10:54 / 2:01:54 and not 2:1:54

BTW, the guy who called me SAFC... what name would i know you by?
Reply
#9

You can change how format displays the numbers, I believe it's in the wiki in explicit detail.

Example:
pawn Код:
format(string,sizeof(string),"%d:%02d.%02d",minute,second,millisecond);
This would display something like
2:05.02
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)