Problem with textdraw countdown
#1

Hi guys,i created a textdraw command when a player enter in a zone,all works but it shows:

"Stay here for -240 seconds"

Where normal should be "Stay here for 60 seconds..59..58"

Here's the code:

pawn Код:
forward CountDown(playerid);
public CountDown(playerid)
{

    seconds--;
    new string[178];
    format(string,sizeof(string),"Stay in the turf %d for take over it!",seconds);
    TextDrawSetString(CountDownTD,string);

   if(seconds == 0)
   {
     TextDrawHideForPlayer(playerid, CountDownTD);
   }
   return 1;
}
pawn Код:
SetTimerEx("CountDown", 120000, true, "i", 1);
What's wrong?Thanks for help.
Reply
#2

Before the forward, try to put
pawn Код:
new seconds = 60;
Reply
#3

Thanks,but now the seconds doesnt decrease on textdraw.

They're frozen at: "Stay in the turf for 60 seconds"

How to fix?
Reply
#4

Anyone can help me?
Reply
#5

You need to hide it and re-show it to update probbably.
Reply
#6

Already tried,it doens't work
Reply
#7

Mh the countdown code looks okey BUT look the timer
pawn Код:
SetTimerEx("CountDown", 120000, true, "i", 1);
it only gets called each 120000ms :O
And there should be playerid instead of a 1 at the end

Than the timer never stops after completing (no KillTimer)

I would write a Countdown like that
pawn Код:
forward TurfCountDown(playerid, seconds);
public TurfCountDown(playerid, seconds)
{
    static string[64] = "Stay in the turf ";
    varstr(string[17], seconds, false);
    strcat(string, " for take over it!");
    TextDrawSetString(CountDownTD, string);
    if(--seconds < 0) {
        TextDrawHideForPlayer(playerid, CountDownTD);
    } else {
        TextDrawShowForPlayer(playerid, CountDownTD);
        SetTimerEx("TurfCountDown", 1000, false, "ii", playerid, seconds);
    }
}
This code can be used more as once at the same time
Reply
#8

I use killtimer in the gangzone turf (when the turf is done taken),the only problem that textdraw shows only:

"Stay in the turf for 120 seconds"

But the seconds doesnt decrease...

And i use "i" because i do a loop on all players.
Reply
#9

Quote:
Originally Posted by Logitech90
Посмотреть сообщение
I use killtimer in the gangzone turf (when the turf is done taken),the only problem that textdraw shows only:

"Stay in the turf for 120 seconds"

But the seconds doesnt decrease...

And i use "i" because i do a loop on all players.
Sure that the countdown doesnt decrease if the code only gets called each 120 seconds

You need to call it each seconds!

And you should know that "i" is just the format for SetTimerEx not the parameter

You just send a 1 to your function Countdown

I would recommend the wiki page about SetTimerEx, it looks like that there are some things unclear
Reply
#10

Umh,so,what i need to do?

I need only to decrease timer or what?

Thanks for patience.
Reply
#11

Errrrrrrrrrr........... Like this ?

pawn Код:
new
     seconds = 60
;

forward CountDown(playerid);
public CountDown(playerid)
{
    seconds--;
    new string[178];
    format(string,sizeof(string),"Stay in the turf %d for take over it!",seconds);
    TextDrawSetString(CountDownTD,string);

   if(seconds == 0)
   {
     TextDrawHideForPlayer(playerid, CountDownTD);
     KillTimer( countTimer[ playerid ] );
     seconds = 60;
   }
   return 1;
}

new
     countTimer[ MAX_PLAYERS ]
;

countTimer[ playerid ] = SetTimerEx("CountDown", 1000, true, "i", playerid);
Reply
#12

Fixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)