Stopping current countdown
#1

could someone help me out i am new here and got permissions to post topics so i have a countdown script it works fine but it want to make a new command which can stop current countdown i tried few times but it hasn't worked so here is the my count down codes please tell me how can i stop current countdown it is not stopping it just stops when count finishes like i did count down for 200 seconds then it doesn't stopping until 200 secs won't finishes and if i'am doing another /count while current running then it shows 2 countdowns so could someone help me to make a new cmd to stop the countdown while count running

this is the code

Код:
forward Counts(amount, const interval);
Код:
public Counts(amount, const interval)
{
    new string[250];
    TextDrawHideForAll(Textdrawcount0);
    TextDrawHideForAll(Textdrawcount1);
    if(amount > 0)
    {
        valstr(string, amount);
        SetTimerEx("Counts", interval, false, "ii", amount - 1, interval);
    }
    format(string, sizeof(string), string, interval, 3);
    TextDrawSetString(Textdrawcount0, string);
    TextDrawShowForAll(Textdrawcount0);
    return 1;
}
Код:
CMD:count(playerid, params[])
{
new counts;
if(sscanf(params, "d", counts))
        {
        SendClientMessage(playerid,COLOR_RED, "Usage: /count amount of countdowns");
        return 1;
        }
		if(counts == 0 || counts < 0 || counts > 3000)
		{
		SendClientMessage(playerid,COLOR_RED,"you can only count for 1-3000");
		return 1;
		}
        Counts(counts, 1000);
        return 1;
}
Reply
#2

pawn Код:
CMD:killcount(playerid, params[])
{
      KillTimer(Counts);
      TextDrawHideForAll(Textdrawcount0);
      TextDrawHideForAll(Textdrawcount1);
      counts = 0;
      return 1;
}
Reply
#3

Quote:
Originally Posted by AlexuTzVs
Посмотреть сообщение
pawn Код:
CMD:killcount(playerid, params[])
{
      KillTimer(Counts);
      TextDrawHideForAll(Textdrawcount0);
      TextDrawHideForAll(Textdrawcount1);
      counts = 0;
      return 1;
}
Errors

Код:
C:\Users\Ronaldo\Desktop\GameServer\gamemodes\GM.pwn(33885) : error 076: syntax error in the expression, or invalid function call
C:\Users\Ronaldo\Desktop\GameServer\gamemodes\GM.pwn(33888) : error 076: syntax error in the expression, or invalid function call
C:\Users\Ronaldo\Desktop\GameServer\gamemodes\GM.pwn(33888) : warning 215: expression has no effect
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
33885 Line : KillTimer(Counts);

33888 Line : Counts = 0;
Reply
#4

Do this:

pawn Код:
new counts;
new CountTimer[MAX_PLAYERS];



CMD:count(playerid, params[])
{
        if(sscanf(params, "d", counts))
        {
        SendClientMessage(playerid,COLOR_RED, "Usage: /count amount of countdowns");
        return 1;
        }
    if(counts == 0 || counts < 0 || counts > 3000)
    {
    SendClientMessage(playerid,COLOR_RED,"you can only count for 1-3000");
    return 1;
    }
        CountTimer[playerid] = SetTimerEx("Counts",200,0,"d",playerid);
        return 1;
}

CMD:killcount(playerid, params[])
{
      KillTimer(CountTimer[playerid]);
      TextDrawHideForAll(Textdrawcount0);
      TextDrawHideForAll(Textdrawcount1);
      counts = 0;
      return 1;
}
It's raw i had no time to test it i am on the phone
Reply
#5

You can use /count <0> it will make the count down = 0 so it will stop , maybe it is a solution
+Rep if i helped you.
Reply
#6

Just kill the timer set in the function Counts.
Reply
#7

Quote:
Originally Posted by AlexuTzVs
Посмотреть сообщение
Do this:

pawn Код:
new counts;
new CountTimer[MAX_PLAYERS];



CMD:count(playerid, params[])
{
        if(sscanf(params, "d", counts))
        {
        SendClientMessage(playerid,COLOR_RED, "Usage: /count amount of countdowns");
        return 1;
        }
    if(counts == 0 || counts < 0 || counts > 3000)
    {
    SendClientMessage(playerid,COLOR_RED,"you can only count for 1-3000");
    return 1;
    }
        CountTimer[playerid] = SetTimerEx("Counts",200,0,"d",playerid);
        return 1;
}

CMD:killcount(playerid, params[])
{
      KillTimer(CountTimer[playerid]);
      TextDrawHideForAll(Textdrawcount0);
      TextDrawHideForAll(Textdrawcount1);
      counts = 0;
      return 1;
}
It's raw i had no time to test it i am on the phone

Now if i am doing /count it finishes in just 1 secs i did /count 50 it finished 50 seconds in just 1 sec don't you have any other examples or give me another countdown system which can be stopped by a command
Reply
#8

anyone?
Reply
#9

Just rewrite it a bit and done
PHP код:
new CountsTimer = -1;
new 
CountsValue;
Counts(amountinterval 1000) {
    if(
CountsTimer == -1) {
        
CountsTimer SetTimer("pCounts"intervaltrue);
        
TextDrawShowForAll(Textdrawcount0);
        
CountsValue amount 1;
        
pCounts();
        return 
true;
    }
    return 
false;
}
KillCounts() {
    if(
CountsTimer != -1) {
        
TextDrawHideForAll(Textdrawcount0);
        
KillTimer(CountsTimer);
        
CountsTimer = -1;
        return 
true;
    }
    return 
false;
}
forward pCounts();
public 
pCounts() {
    if(--
CountsValue 0) {
        
KillCounts();
    } else {
        new 
string[32];
        
valstr(stringCountsValue);
        
TextDrawSetString(Textdrawcount0string);
    }

But the downside is that only one countdown can run at the same time
Reply
#10

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just rewrite it a bit and done
PHP код:
new CountsTimer = -1;
new 
CountsValue;
Counts(amountinterval 1000) {
    if(
CountsTimer == -1) {
        
CountsTimer SetTimer("pCounts"intervaltrue);
        
TextDrawShowForAll(Textdrawcount0);
        
CountsValue amount 1;
        
pCounts();
        return 
true;
    }
    return 
false;
}
KillCounts() {
    if(
CountsTimer != -1) {
        
TextDrawHideForAll(Textdrawcount0);
        
KillTimer(CountsTimer);
        
CountsTimer = -1;
        return 
true;
    }
    return 
false;
}
forward pCounts();
public 
pCounts() {
    if(--
CountsValue 0) {
        
KillCounts();
    } else {
        new 
string[32];
        
valstr(stringCountsValue);
        
TextDrawSetString(Textdrawcount0string);
    }

But the downside is that only one countdown can run at the same time
where to put those codes?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)