Timer help? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Timer help? (
/showthread.php?tid=632416)
Timer help? -
Kruno88 - 13.04.2017
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
Re: Timer help? -
GangstaSunny. - 14.04.2017
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.
Re: Timer help? -
Kruno88 - 14.04.2017
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)
Re: Timer help? -
GangstaSunny. - 14.04.2017
Don't forget to DeletePVar just to be sure
Re: Timer help? -
DRIFT_HUNTER - 14.04.2017
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)
Re: Timer help? -
GangstaSunny. - 14.04.2017
I was thinking about the timestamp option too and i think its a better one.
Re: Timer help? -
Kruno88 - 14.04.2017
Hmmmm,can anybody send me an example?I can't get it to work,....
Re: Timer help? -
LEOTorres - 14.04.2017
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;
Re: Timer help? -
GangstaSunny. - 14.04.2017
PHP код:
//Start race
SetPVarInt(playerid,"RaceTime",gettime());
//End race
printf("you were %d seconds on the street.",gettime()-GetPVarInt(playerid,"RaceTime"));