SA-MP Forums Archive
countdown cmd problem - 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)
+--- Thread: countdown cmd problem (/showthread.php?tid=502516)



countdown cmd problem - Sojo12 - 24.03.2014

I took this code here in the forum itself but when i type the command,it executes properly but it shows 'GO!!"it keeps on repeating that and dont stop.I'm confused and need help from you!
Here is my code:
Код:
new TimerCount;

dcmd_countdown(playerid, params[])
{
new string[128];
new pName[24];
GetPlayerName(playerid,pName,24);
if(sscanf(params, "i", TimerCount)) return SendClientMessage( playerid, -1, "{FF0099}[ADMIN]{FFFFFF}/countdown [time]" );
if((TimerCount < 1) || (TimerCount > 20)) return SendClientMessage(playerid, -1, "{FF0000}[ERROR]{FFFFFF}You can start a countdown from 20 only!");
TimerCount = SetTimer("DTime", 1000, true);
format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}%s has initiated a countdown starting from %d",pName,TimerCount);
SendClientMessageToAll(COLOR_ADMIN,string);
return 1;
}

public DTime()
{
	new string[128];
    if(TimerCount == 0)
    {
        KillTimer(TimerCount);
        GameTextForAll("~r~GO!!!", 1000, 6);
        return 1;
    }
    format(string, sizeof(string), "~g~%d", TimerCount);
    GameTextForAll(string, 1000, 6);
    TimerCount--;
    return 1;
}
Thanks in advance.


Re: countdown cmd problem - Konstantinos - 24.03.2014

It happens because it's a repeated timer and when TimerCount will be 0, it will return 1. DTime will be called again and the same thing will go over and over again, it will never downgrade to a negative number. You should consider of stopping the timer.

There's a good tutorial about countdown: https://sampforum.blast.hk/showthread.php?tid=291392


Re: countdown cmd problem - Jefff - 24.03.2014

pawn Код:
public DTime(times)
{

    if(times > 0)
    {
        new string[10];
        format(string, sizeof(string), "~g~%d", times);
        GameTextForAll(string, 1300, 6);
        SetTimerEx("DTime",1000,false,"i",times-1);
    }else
        GameTextForAll("~r~GO!!!", 1000, 6);

    return 1;
}

dcmd_countdown(playerid, params[])
{
    if(isnull(params)) return SendClientMessage( playerid, -1, "{FF0099}[ADMIN]{FFFFFF}/countdown [time]" );
    if(!(0 < strval(params) < 21)) return SendClientMessage(playerid, -1, "{FF0000}[ERROR]{FFFFFF}You can start a countdown from 20 only!");

    DTime(strval(params));
    // SetTimerEx("DTime",1000,false,"i",strval(params));
    new pName[24],string[128];
    GetPlayerName(playerid,pName,24);
    format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}%s has initiated a countdown starting from %d",pName,strval(params));
    return SendClientMessageToAll(COLOR_ADMIN,string);
}



Re: countdown cmd problem - Hanuman - 24.03.2014

pawn Код:
new TimerCount;

dcmd_countdown(playerid, params[])
{
new string[128];
new pName[24];
GetPlayerName(playerid,pName,24);
if(sscanf(params, "i", TimerCount)) return SendClientMessage( playerid, -1, "{FF0099}[ADMIN]{FFFFFF}/countdown [time]" );
if((TimerCount < 1) || (TimerCount > 20)) return SendClientMessage(playerid, -1, "{FF0000}[ERROR]{FFFFFF}You can start a countdown from 20 only!");
SetTimer("DTime", 1000, 0);
format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}%s has initiated a countdown starting from %d",pName,TimerCount);
SendClientMessageToAll(COLOR_ADMIN,string);
return 1;
}

public DTime()
{
   
    TimerCount--;
    if(TimerCount == 0)
    {
        GameTextForAll("~r~GO!!!", 1000, 6);
        return 1;
    }
    else{
        new string[128];
        format(string, sizeof(string), "~g~%d", TimerCount);
        GameTextForAll(string, 1000, 6);
        SetTimer("DTime",1000,0);
    }
    return 1;
}
Replace ur codes with this.


Re: countdown cmd problem - Sojo12 - 25.03.2014

OK thanks guys.