Countdown
#1

Can anyone tell me why this countdown not working ?

what happens is.. when i enter command /cd 5

a 5 comes on the screen but it doesnt decrease..



pawn Код:
dcmd_cd(playerid,params[])
{
    #pragma unused playerid
    sscanf(params,"d",Scount);
    new string[256];
    format(string,sizeof(string),"%i",Scount);
    TextDrawSetString(TextdrawCD,string);
    TextDrawShowForAll(TextdrawCD);
    SetTimer("CDRepeat",10,0);
   
    return 1;
}
public CDRepeat()
{
    SetTimer("reper",1000,0);
}
public reper()
{
    Scount--;
    new string[256];
    format(string,sizeof(string),"%i",Scount);
    TextDrawSetString(TextdrawCD,string);
    if(Scount != 0)
    {
        SetTimer("CDRepeat",10,0);
    }
    if(Scount == 0)
    {
        TextDrawHideForAll(TextdrawCD);
        TextDrawShowForAll(TextdrawGO);
        SetTimer("CDRepeat",1000,0);
    }
}
Reply
#2

Use SetTimerEx() instead of just SetTimer() since you're passing a variable which is actually the one decreasing. Also, it's better to use just one timer, you're using two timers(reper and CDrepeat) which uses more RAM from what I know.

pawn Код:
SetTimerEx("reper", 1000, false, "i", Scount);
Reply
#3

but , since this variable was made outside these 3 functions.. passing it shouldnt affect it right ?? still ill try passing it
Reply
#4

From what I see, the variable only exists in the command and was not passed at all, unless you have declared it for an overall use.
Reply
#5

its been declared for overall use...

also.. if i dont want to use SetTimer.. how else can i make a countdown ?
Reply
#6

Try this:

pawn Код:
new Scount = 0, StartedCount = 0;
forward OneSecond();

public OnGameModeInit()
{
    SetTimer("OneSecond", 1000, true);
    return 1;
}

public OneSecond()
{
    new string[128];
    if(StartedCount != 0)
    {
        if(Scount == 0)
        {
            StartedCount = 0;
            TextDrawHideForAll(TextdrawCD);
            TextDrawShowForAll(TextdrawGO);
        }
        else
        {
            format(string, sizeof(string), "%i", Scount);
            TextDrawSetString(TextdrawCD,string);
            Scount--;
        }
    }
    return 1;
}

dcmd_cd(playerid, params[])
{
    #pragma unused params
    #pragma unused playerid
   
    new string[128], number;
    if(sscanf(params, "i", number)) return SendClientMessage(playerid, -1, "Usage: /cd [number]");
    Scount = number;
    format(string, sizeof(string), "%i", Scount);
    TextDrawSetString(TextdrawCD, string);
    TextDrawShowForAll(TextdrawCD);
    StartedCount = 1;
    return 1;
}
Reply
#7

this one is giving me the same result as my script..the countdown gets stuck at 5 the first time i do that command.. but works if i do it another time

EDIT : yours does not work after i put command again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)