Timer minutes
#1

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: "minuteseconds". 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.
Reply
#2

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
pawn Код:
0%d:0%d
,so the textdraw won't look like:
Код:
09:10.....09:9
but like
Код:
09:09
.Also when S is 0,then decrement M to M-1 and reset S to 59 while M!=0.
Reply
#3

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
pawn Код:
0%d:0%d
,so the textdraw won't look like:
Код:
09:10.....09:9
but like
Код:
09:09
.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
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)