Race time
#1

Hello guys,

I have a question.
Does anybody have a function that counts up the time, and gives it out when the player finished a race?
Like this:

•/race
•The timer starts counting up
•Player drives troght last checkpoint
•Time that he needed for the race will be shown.

Can anyone help me?

Jeffry
Reply
#2

GetTickCount();


You would save it to a variable at the beginning of a race, and then compare it with the current GetTickCount() at the end of the race.

pawn Code:
BeginRace(playerid)
{
  Timer[playerid]=GetTickCoun();
}
EndRace(playerid)
{
  Timer[playerid]=GetTickCount()-Timer[playerid]; //That will be how long the player was in the race in milliseconds
}
Reply
#3

Okay, this works, but I get 6295 as result.
How do I give it out as: minec:milisec ?
Reply
#4

Could create a function

pawn Code:
stock ConvertTime(Milliseconds,&rMin,&rS,&rMS)
{
  rMin=Milliseconds/60000;
  Milliseconds-=rMin*60000;
  rS=Milliseconds/1000;
  Milliseconds-=rS*1000
  rMS=Milliseconds;
}
pawn Code:
new Min,Sec,MS;
  ConvertTime(Timer[playerid],Min,Sec,MS);
  printff("%02d:%02d.%01d",Min,Sec,MS/100);
will print
Code:
01:32.5
Reply
#5

WOORKS!!! YUHUU!

Thank you so much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)