Timer help?
#1

How do I set a simple timer that calculates the time it took you to go from place A to place B?
Like:
Код:
It took you 43 seconds to finish the race
Reply
#2

Just start a repeating 1 second timer and set a PVar. If he enters the last checkpoint kill the timer and show the PVar.

Simple as that.
Reply
#3

Quote:
Originally Posted by GangstaSunny.
Посмотреть сообщение
Just start a repeating 1 second timer and set a PVar. If he enters the last checkpoint kill the timer and show the PVar.

Simple as that.
Oh,nice idea.
I'll know how to make that (no sarcasm)
Reply
#4

Don't forget to DeletePVar just to be sure
Reply
#5

How about gettime() ? It returns timestamp in seconds. Save that, when race starts. Then when race ends get time stamp again and subtract the one you saved from it.
pawn Код:
new curTime = gettime();
new timeTaken = gettime() - curTime;
All you have to do now is convert that timeTaken from seconds to format you need (probably Minutes:Seconds)
Reply
#6

I was thinking about the timestamp option too and i think its a better one.
Reply
#7

Hmmmm,can anybody send me an example?I can't get it to work,....
Reply
#8

Quote:
Originally Posted by Kruno88
Посмотреть сообщение
Hmmmm,can anybody send me an example?I can't get it to work,....
You can also assign a timer to a callback which increments a variable by one every second.

Код:
new raceTimer[MAX_PLAYERS];
new raceTime[MAX_PLAYERS];

forward CountSeconds (playerid);

public CountSeconds (playerid)
{
	raceTime[playerid]++;
	return 1;
}
When the race starts, do the following:

Код:
raceTimer[playerid] = SetTimerEx("CountSeconds", 1000, true, "i", playerid);
When the race ends, do the following:

Код:
KillTimer (raceTimer[playerid]);
new string[256];
format (string, sizeof(string), "ID %i took %i seconds to complete the race!", playerid, raceTime[playerid]);
SendClientMessageToAll (-1, string);
raceTime[playerid] = 0;
Reply
#9

PHP код:
//Start race
SetPVarInt(playerid,"RaceTime",gettime());
//End race
printf("you were %d seconds on the street.",gettime()-GetPVarInt(playerid,"RaceTime")); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)