SA-MP Forums Archive
Countdown of the gametime. Minutes and seconds - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Countdown of the gametime. Minutes and seconds (/showthread.php?tid=248314)



Countdown of the gametime. Minutes and seconds - Biesmen - 13.04.2011

I'm trying to create a function to note the time left, until the game ends, but it fails. The calculation to calculate the seconds works perfectly, but if the seconds are above 60, it will fail. Same for the minutes.

This is the code I am using to countdown.
A timer has been set every second on this 'callback'.
pawn Код:
public Timer()
{
    new time[6];
    Seconds--;
    Minute = Seconds/60;
    format(time, 6, "%d:%d",Minute, Seconds);
    if(Seconds == 0) return Seconds = 60;
    TextDrawSetString(TDraw, time);
    return 1;
}
And I'm using this to start the timer.
pawn Код:
Seconds = ((30000+time)/1000);
    SetTimer("Timer", 1000, true);
It's actually really easy to calculate this. But it's hard to calculate this for a script.

Thanks


Re: Countdown of the gametime. Minutes and seconds - Voldemort - 13.04.2011

if(Seconds > 0)
{
Seconds--;
}


Re: Countdown of the gametime. Minutes and seconds - Biesmen - 13.04.2011

Do you even understand my problem? What you're posting there isn't related to my problem at all.


Re: Countdown of the gametime. Minutes and seconds - (SF)Noobanatior - 13.04.2011

like this?
pawn Код:
new seconds = 1508;

new minutes,tempsec;
    tempsec = seconds;
    while(tempsec > 60){
        minutes++;
        tempsec = tempsec - 60;
    }
printf("%d:%d",minutes,tempsec);



Re: Countdown of the gametime. Minutes and seconds - Biesmen - 13.04.2011

Ah, I got it working now.
I used if before, instead of while.

Thanks