[SOLVED finaly :D] Really need help with countdown timer
#1

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
Reply
#2

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

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.
Reply
#4

No the variables are only changed in those callbacks

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

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);
Reply
#6

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?
Reply
#7

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

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

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 :@
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)