Timer doesn't work with my /countdown
#1

hello guys i have problem with my /countdown that i made few minutes ago.
this command was request by my friend this command uses administration system.
code

pawn Код:
new Player[MAX_PLAYERS];
forward CountdownGO(playerid);
forward Countdown(playerid);
forward Countdown2(playerid);
forward Countdown3(playerid);
forward Countdown4(playerid);
forward Countdown5(playerid);

public Countdown(playerid)
{
    if(Player[playerid] == 1)
    {
        GameTextForAll("~r~5",1000,6);
        PlayerPlaySound(playerid, 1056, 0, 0, 0);
        SetTimer("Countdown2",1000,false);
    }
    return 1;
}

public Countdown2(playerid)
{
    if(Player[playerid] == 1)
    {
        GameTextForAll("~y~4",1000,6);
        PlayerPlaySound(playerid, 1056, 0, 0, 0);
        SetTimer("Countdown3",1000,false);
    }
    return 1;
}

public Countdown3(playerid)
{
    if(Player[playerid] == 1)
    {
        GameTextForAll("~p~3",1000,6);
        PlayerPlaySound(playerid, 1056, 0, 0, 0);
        SetTimer("Countdown4",1000,false);
    }
    return 1;
}

public Countdown4(playerid)
{
    if(Player[playerid] == 1)
    {
        GameTextForAll("~g~2",1000,6);
        PlayerPlaySound(playerid, 1056, 0, 0, 0);
        SetTimer("Countdown5",1000,false);
    }
    return 1;
}

public Countdown5(playerid)
{
    if(Player[playerid] == 1)
    {
        GameTextForAll("~w~1",1000,6);
        PlayerPlaySound(playerid, 1056, 0, 0, 0);
        SetTimer("CountdownGO",1000,false);
    }
    return 1;
}

public CountdownGO(playerid)
{
    if(Player[playerid] == 1)
    {
        GameTextForAll("~r~GO ~y~GO ~g~GO!!!",1000,6);
        PlayerPlaySound(playerid, 1056, 0, 0, 0);
        TogglePlayerControllable(playerid, 1);
    }
    return 1;
}

CMD:countdown(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] > 3)
    {
         new string[100], id, id2, pname[MAX_PLAYER_NAME], name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
         if(sscanf(params, "u", id, id2)) return SendClientMessage(playerid, COLOR_RED, "SYNTAX: /countdown <id1> <id2>");
         GetPlayerName(id, name, sizeof(name));
         GetPlayerName(id2, name2, sizeof(name2));
         GetPlayerName(playerid, pname, sizeof(pname));
         if(id == INVALID_PLAYER_ID && id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Invalid-Playerid");
         if(id == playerid && id2 == playerid) return SendClientMessage(playerid, COLOR_RED, "You cannot countdown with yourself!");
         if(!id2)
         {
             format(string, sizeof(string), "Administrator %s(ID:%d) has made a countdown with %s(ID:%d)", pname, playerid, name, id);
             SendClientMessageToAll(COLOR_YELLOW, string);
             TogglePlayerControllable(id, 0);
             Player[id] = 1;
             return 1;
         }
         format(string, sizeof(string), "Administrator %s(ID:%d) has made a countdown with Player1 %s(ID:%d) and Player2 %s(ID:%d)", pname, playerid, name, id, name2, id2);
         SendClientMessageToAll(COLOR_YELLOW, string);
         TogglePlayerControllable(playerid, 0);
         TogglePlayerControllable(id2, 0);
         Player[playerid] = 1;
         Player[id2] = 1;
         SetTimer("Countdown", 1000, false);
    }
    return 1;
}
and i want to know if this command works too
Reply
#2

Hi Reklez,

I see a few issues, the first one being this line:
pawn Код:
SetTimer("Countdown", 1000, false);
The "Countdown" function expects a "playerid" parameter. However none is passed when using this timer. May I suggest adapting your countdown functions to the following:

pawn Код:
public Countdown()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Player[playerid] == 1)
            {
                GameTextForAll("~r~5",1000,6);
                PlayerPlaySound(playerid, 1056, 0, 0, 0);
                SetTimer("Countdown2",1000,false);
            }
           
        }
    }
    return 1;
}

public Countdown2()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Player[playerid] == 1)
            {
                GameTextForAll("~r~4",1000,6);
                PlayerPlaySound(playerid, 1056, 0, 0, 0);
                SetTimer("Countdown3",1000,false);
            }
        }
    }
    return 1;
}

public Countdown3()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Player[playerid] == 1)
            {
                GameTextForAll("~r~3",1000,6);
                PlayerPlaySound(playerid, 1056, 0, 0, 0);
                SetTimer("Countdown4",1000,false);
            }
        }
    }
    return 1;
}

public Countdown4()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Player[playerid] == 1)
            {
                GameTextForAll("~r~2",1000,6);
                PlayerPlaySound(playerid, 1056, 0, 0, 0);
                SetTimer("Countdown5",1000,false);
            }
        }
    }
    return 1;
}

public Countdown5()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Player[playerid] == 1)
            {
                GameTextForAll("~r~1",1000,6);
                PlayerPlaySound(playerid, 1056, 0, 0, 0);
                SetTimer("CountdownGO",1000,false);
            }
        }
    }
    return 1;
}

public CountdownGO()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Player[playerid] == 1)
            {
                GameTextForAll("~r~GO ~y~GO ~g~GO!!",1000,6);
                PlayerPlaySound(playerid, 1056, 0, 0, 0);
                Player[playerid] = 0;
            }
        }
    }
    return 1;
}
That may solve your issues.

Cheers,

TJ
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)