Timer minutes - 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 minutes (
/showthread.php?tid=366983)
Timer minutes -
Dan. - 08.08.2012
I have a timer for 10 minutes (600 seconds), that I want to count down to 0 minutes 0 seconds. How to show it in a textdraw like: "minutes
econds". I know how to show seconds in the textdraw, but how can I show left minutes and then seconds? Like 6 min, 42 secs. Basically, how to convert seconds to minutes and seconds.
Re: Timer minutes -
Cjgogo - 08.08.2012
Make a timer of 1 second,and then just define 2 variables name M and S(minutes and second).Define them in your gamemode like M=9,S=59;.Then change the timer to 1 second,and update the textdraw every seconds,the format is of course[pawn]0%d:%d[pawn].But you have to check when the variable S,when it's a single digit so the format woould change to
,so the textdraw won't look like:
but like
.Also when S is 0,then decrement M to M-1 and reset S to 59 while M!=0.
Re: Timer minutes -
Sinner - 08.08.2012
Quote:
Originally Posted by Cjgogo
Make a timer of 1 second,and then just define 2 variables name M and S(minutes and second).Define them in your gamemode like M=9,S=59;.Then change the timer to 1 second,and update the textdraw every seconds,the format is of course[pawn]0%d:%d[pawn].But you have to check when the variable S,when it's a single digit so the format woould change to ,so the textdraw won't look like: but like .Also when S is 0,then decrement M to M-1 and reset S to 59 while M!=0.
|
No? What if the seconds or minutes are more then 10? it'll look like 015:036 (example).
Here's how you do it:
pawn Код:
new time = TIME_IN_MILLI_SECONDS; // Fill in yourself (time in milliseconds)
SetTimer("CountDown", 1000, false); // Start timer somewhere
forward CountDown();
public CountDown() {
if(time > 0) {
new
szString[9],
minute, second
;
while(time > 1000 * 60) {
time -= (1000 * 60);
minute++;
}
second = (time/1000);
format(szString, sizeof(szString), "%02d:%02d", minute, second);
// Use szString somewhere (for example a GameText message)
// szString will hold the time (example: 03:55)
time -= 1000; // Decrease time by 1000 (1 second)
SetTime("CountDown", 1000, false); // Run again until time is 0
}
}