open.mp forum
[Pawn] Nice and easy way to script a countdown? - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Nice and easy way to script a countdown? (/showthread.php?tid=1518)



Nice and easy way to script a countdown? - M.D. - 2021-01-12

What do you reckon that would be an efficient method of implementing a countdown (a few minutes long), including both a timer and an updating TextDraw or GameText?



Afterwards, how would you be able to script something to happen at the end of it?



Cheers!


RE: Nice and easy way to script a countdown? - Pinch - 2021-01-12

I've been doing it like this:

Code:
timer Countdown[1000](playerid, seconds)
{
    if (seconds) {
        defer Countdown(playerid, --seconds);
        // Update GameText, be aware that seconds is already subtracted by 1
    }
    else {
        // Timer finished, code;
    }
}
Dunno if it's the best way but I hope that I gave you a good idea how :3


RE: Nice and easy way to script a countdown? - M.D. - 2021-01-13

Thank you, Pinch. Please take into account that I am quite new to scripting and frankly the first line of your code is unclear to me. Is that basically a function that I should call whenever I will want to initiate a countdown?


RE: Nice and easy way to script a countdown? - Pinch - 2021-01-14

Yes, if you're using y_timers just do Countdown(playerid, seconds);


RE: Nice and easy way to script a countdown? - aaapcgames - 2024-05-15

(2021-01-14, 02:44 PM)Pinch Wrote: Yes, if you're using y_timers just do Countdown(playerid, seconds);

If I don't use y_timers then will this works like this?:
Countdown(playerid, 11); 
or this:
Countdown[1000](playerid, 11);