SA-MP Forums Archive
Timer won't Countdown!!! - 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: Timer won't Countdown!!! (/showthread.php?tid=278802)

Pages: 1 2


[SOLVED]Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

I have a textdraw with a timer:
pawn Code:
new GameMinutes = 14;
new GameSeconds = 59;
new Text:Textdraw0;
Textdraw properties:
pawn Code:
Textdraw0 = TextDrawCreate(86.000000,427.000000,"15:00");
    TextDrawAlignment(Textdraw0,2);
    TextDrawBackgroundColor(Textdraw0,0x000000ff);
    TextDrawFont(Textdraw0,3);
    TextDrawLetterSize(Textdraw0,0.499999,2.000000);
    TextDrawColor(Textdraw0,0xffffffff);
    TextDrawSetOutline(Textdraw0,1);
    TextDrawSetProportional(Textdraw0,1);
    TextDrawSetShadow(Textdraw0,1);
Timer:
pawn Code:
SetTimer("GameTime",1000,1);
Timer function:
pawn Code:
public GameTime()
{
    if(GameSeconds > 0 || GameMinutes > 0)
    {
        GameSeconds--;
        if(GameSeconds <= -1)
        {
            GameMinutes--;
            GameSeconds=59;
        }
        new TimeString[14];
        format(TimeString,sizeof(TimeString),"%02d:%02d",GameMinutes,GameSeconds);
        TextDrawSetString(Textdraw0,TimeString);
    }
    if(GameSeconds == 0 && GameMinutes == 0)
    {
        OnGameModeExit();
    }
    return 1;
}
When I go ingame, all I see is 15:00 and they timer doesn't count down! Please help me!


Re: Timer won't Countdown!!! - a_big - 24.08.2011

I know this is off-topic but couldnt you use the game clock?


Re: Timer won't Countdown!!! - Jefff - 24.08.2011

pawn Code:
new GameSeconds = 900; // 60s - min, 300s - 5min
public GameTime()
{
    new m = ((GameSeconds/60)%60);
    new s = (GameSeconds%60);
    new TimeString[14];
    format(TimeString,sizeof(TimeString),"%02d:%02d",m,s);
    TextDrawSetString(Textdraw0,TimeString);
    if(GameSeconds == 0) OnGameModeExit();
    GameSeconds--;
    return 1;
}
and TextDrawShowForAll or ForPlayer


Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

@a_big: No, it's a countdown timer until the end of the gamemode.


Re: Timer won't Countdown!!! - Intoxicated - 24.08.2011

Quote:
Originally Posted by a_big
View Post
I know this is off-topic but couldnt you use the game clock?
^^ That.

Just use TogglePlayerClock and use a timer to update the time every second or so.


Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Jefff: It still doesn't count down :/


Re: Timer won't Countdown!!! - grand.Theft.Otto - 24.08.2011

Quote:
Originally Posted by Intoxicated
View Post
^^ That.

Just use TogglePlayerClock and use a timer to update the time every second or so.
Do you not get it? He said COUNTDOWN not the default GTA SA clock ..

Why not use gametext instead of textdraws? Then again other gametext may interfere with it.


Re: Timer won't Countdown!!! - Jefff - 24.08.2011

Where is TDShowFor ?


Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Under OnPlayerConnect

pawn Code:
public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid, Textdraw0);
    return 1;
}



Re: Timer won't Countdown!!! - grand.Theft.Otto - 24.08.2011

Doubt this will work but, try setting it for max players:

pawn Code:
public GameTime()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GameSeconds > 0 || GameMinutes > 0)
        {
            GameSeconds--;
            if(GameSeconds <= -1)
            {
                GameMinutes--;
                GameSeconds=59;
            }
            new TimeString[14];
            format(TimeString,sizeof(TimeString),"%02d:%02d",GameMinutes,GameSeconds);
            TextDrawSetString(Textdraw0,TimeString);
        }
        if(GameSeconds == 0 && GameMinutes == 0)
        {
            OnGameModeExit();
        }
    }
    return 1;
}



Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Nice try, but still no success!


Re: Timer won't Countdown!!! - iPLEOMAX - 24.08.2011

Try this:
pawn Code:
new GameSeconds = 1451;
new Text:Textdraw0;
pawn Code:
Textdraw0 = TextDrawCreate(86.000000,427.000000,"Loading..");
    TextDrawAlignment(Textdraw0,2);
    TextDrawBackgroundColor(Textdraw0,0x000000ff);
    TextDrawFont(Textdraw0,3);
    TextDrawLetterSize(Textdraw0,0.499999,2.000000);
    TextDrawColor(Textdraw0,0xffffffff);
    TextDrawSetOutline(Textdraw0,1);
    TextDrawSetProportional(Textdraw0,1);
    TextDrawSetShadow(Textdraw0,1);
pawn Code:
public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid, Textdraw0);
    return true;
}
pawn Code:
SetTimer("GameTime",1000,1);
pawn Code:
forward GameTime();
public GameTime()
{
    GameSeconds++;
    new TimeString[14];
    format(TimeString,sizeof(TimeString),"%i:%i",(GameSeconds/(60*60))%24,(GameSeconds/60)%60);
    //                                 Hours:Minutes
    TextDrawSetString(Textdraw0,TimeString);
    //In case you need a reset on completing 24 hours:
    if((GameSeconds/(60*60))%24 == 24) { GameSeconds = 0; }
    return true;
}
//You don't need GameMinutes here. No other stuff.



Re: Timer won't Countdown!!! - Bakr - 24.08.2011

None of the previous posts will fix your problem. You need to hide and re-display the textdraw each time you set a new string to it, or it won't update on the player's screen. You should hide it, set the string, then show it again.
pawn Code:
TextDrawHideForAll( Textdraw0 );
TextDrawSetString( Textdraw0, TimeString );
TextDrawShowForAll( Textdraw0 );



Re: Timer won't Countdown!!! - iPLEOMAX - 24.08.2011

Quote:
Originally Posted by Bakr
View Post
None of the previous posts will fix your problem. You need to hide and re-display the textdraw each time you set a new string to it, or it won't update on the player's screen. You should hide it, set the string, then show it again.
pawn Code:
TextDrawHideForAll( Textdraw0 );
TextDrawSetString( Textdraw0, TimeString );
TextDrawShowForAll( Textdraw0 );
Mine is tested and it works without it. (And I usually add that after string update though... Weird, lol.)


Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Quote:
Originally Posted by Bakr
View Post
None of the previous posts will fix your problem. You need to hide and re-display the textdraw each time you set a new string to it, or it won't update on the player's screen. You should hide it, set the string, then show it again.
pawn Code:
TextDrawHideForAll( Textdraw0 );
TextDrawSetString( Textdraw0, TimeString );
TextDrawShowForAll( Textdraw0 );
No, the timer doesn't countdown, even after putting it in the timer like this:

pawn Code:
public GameTime()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GameSeconds > 0 || GameMinutes > 0)
        {
            GameSeconds--;
            if(GameSeconds <= -1)
            {
                GameMinutes--;
                GameSeconds=59;
            }
            new TimeString[14];
            format(TimeString,sizeof(TimeString),"%02d:%02d",GameMinutes,GameSeconds);
            TextDrawSetString(Textdraw0,TimeString);
            TextDrawHideForAll( Textdraw0 );
            TextDrawSetString( Textdraw0, TimeString );
            TextDrawShowForAll( Textdraw0 );
        }
        if(GameSeconds == 0 && GameMinutes == 0)
        {
            OnGameModeExit();
        }
    }
    return 1;
}



Re: Timer won't Countdown!!! - iPLEOMAX - 24.08.2011

Have you tried my method above?^


Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Im trying it now.


Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Quote:
Originally Posted by iPLEOMAX
View Post
Have you tried my method above?^
With your method, all I get is "Loading" in the bottom corner.


Re: Timer won't Countdown!!! - iPLEOMAX - 24.08.2011

You sure you have done everything correctly? (Look at mine in the screeny here, with seconds )




Re: Timer won't Countdown!!! - Tigerbeast11 - 24.08.2011

Well, I copied and pasted your script so it should have worked. I honestly have no idea why it's doing this...