countdown cmd problem
#1

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.
Reply
#2

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
Reply
#3

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);
}
Reply
#4

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.
Reply
#5

OK thanks guys.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)