SA-MP Forums Archive
[SOLVED finaly :D] Really need help with countdown timer - 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: [SOLVED finaly :D] Really need help with countdown timer (/showthread.php?tid=125584)



[SOLVED finaly :D] Really need help with countdown timer - [HLF]Southclaw - 04.02.2010

Ok, I've posted this before but no one helped and it seemed to slip onto page 2 in about 20 minutes and no one else responded even after bumping

I have a countdown timer but it's buggered up, it's really annoying because this is vital for 2 of my deathmatch modes
What happens is when I see the textdraw instead of counting 2:59 - 2:58 - 2:57 etc it goes 2:59 - 2:49 - 2:39 I can't understand it

Please help me I need this problem finally fixed

Here is the callback for the countdown

public SetCountDown(minutes, seconds, Float, Float:y)
{
Timer = TextDrawCreate(x, y, "00:00");
TextDrawTextSize(Timer,636.000000,824.000000);
TextDrawAlignment(Timer, 2);
TextDrawFont(Timer,3);
TextDrawLetterSize(Timer,0.499999,1.800000);
TextDrawColor(Timer,0xffffffff);
TextDrawSetProportional(Timer,2);
TextDrawSetShadow(Timer,1);
TextDrawSetOutline(Timer, 1);

Tmin = minutes;
Tsec = seconds;

TTimer = SetTimer("TimerSet",1000,1);
return 1;
}

Here is the "TimerSet" callback that is repeated 1000 ms

public TimerSet()
{
new string[5];
if(Tmin >= 1)
{
Tsec--;
}
if(Tsec <= 0 && Tmin != 0)
{
Tsec = 59;
Tmin--;
}
else if(Tmin == 0 && Tsec == 0)
{
OnCountDownEnd();
}
format(string, 5, "%d:%d",Tmin, Tsec);
TextDrawSetString(Timer, string);
return 1;
}


I would be so grateful if this is fixed

Thanks


Re: Really need help with countdown timer - MadeMan - 04.02.2010

The code should be good. Are you sure you don't mess with these variables somewhere else?


Re: Really need help with countdown timer - member - 04.02.2010

It seems ok, but i've simplified it a bit. Try it now.
Before the countdown starts, the values should be as so:

pawn Code:
Tmin = [whatever minute you want];
Tsec = 0;
pawn Code:
public SetCountDown(minutes, seconds, Float:x, Float:y)
{
   Timer = TextDrawCreate(x, y, "00:00");
   TextDrawTextSize(Timer,636.000000,824.000000);
   TextDrawAlignment(Timer, 2);
   TextDrawFont(Timer,3);
   TextDrawLetterSize(Timer,0.499999,1.800000);
   TextDrawColor(Timer,0xffffffff);
   TextDrawSetProportional(Timer,2);
   TextDrawSetShadow(Timer,1);
   TextDrawSetOutline(Timer, 1);

   Tmin = minutes;
   Tsec = seconds; // should be "0" if you want the whole minute

   TTimer = SetTimer("TimerSet",1000,1);
   return 1;
}

Here is the "TimerSet" callback that is repeated 1000 ms

public TimerSet()
{
    new string[5];
    Tsec--;
    if(Tsec <= 0)
    {
        Tsec = 59;
        Tmin--;
        if(Tmin <= 0)
        {
            OnCountDownEnd(); // Time's Up
        }
    }
    format(string, 5, "%d:%d",Tmin, Tsec);
    TextDrawSetString(Timer, string);
    ///TextDrawShowForAll ?
}
Also, aren't you supposed to be showing the textdraw once you've formatted the string? maybe the textdraw is being shown every 10 seconds in another timer or callback.


Re: Really need help with countdown timer - [HLF]Southclaw - 04.02.2010

No the variables are only changed in those callbacks

This is what's annoying me I can't understand what it is


Re: Really need help with countdown timer - member - 04.02.2010

Quote:
Originally Posted by ~ ЉǾǖŦĦЗŁΛẄ ~
No the variables are only changed in those callbacks

This is what's annoying me I can't understand what it is
Try the code out, see what happens.

Or try debugging. Add a clientmessage at the end of the TimerSet callback:
pawn Code:
SendClientMessageToAll(0xFFFFFFAA, string);



Re: Really need help with countdown timer - [HLF]Southclaw - 04.02.2010

Well I told it to print the GetTickTount every time the timer got called and this is the result

Code:
[19:49:39] 43929331
[19:49:39] 43929348
[19:49:39] 43929348
[19:49:39] 43929349
[19:49:39] 43929349
[19:49:39] 43929354
[19:49:39] 43929356
[19:49:39] 43929357
[19:49:39] 43929357
[19:49:39] 43929357
It seems the timer is going off every 1 ms instead of every 1000 but it clearly says in the script SetTimer("TimerSet",1000,1); WTF?


Re: Really need help with countdown timer - [HLF]Southclaw - 05.02.2010

come one, there must be someone that can identify the problem


Re: [UNSOLVED] Really need help with countdown timer - Joe Staff - 05.02.2010

I can't imagine why your counter would be acting like that. Are you accidently running the timer multiple times? Like OnPlayerSpawn or OnPlayerConnect?


Re: [UNSOLVED] Really need help with countdown timer - [HLF]Southclaw - 05.02.2010

No, the only place those variables are changed is in those 2 functions. Could it be an efficiency problem, like it doesn't get long enough to process the code every second or something?

This problem is pissing me off cos there seems to be no solution :@


Re: [UNSOLVED] Really need help with countdown timer - Fedee! - 05.02.2010

Quote:
Originally Posted by ~ ЉǾǖŦĦЗŁΛẄ ~
No, the only place those variables are changed is in those 2 functions. Could it be an efficiency problem, like it doesn't get long enough to process the code every second or something?

This problem is pissing me off cos there seems to be no solution :@
Well, to be sure if it isnt your GM or any other FS run it with a free-FS server, just that fs.