Timer Problem
#1

pawn Код:
forward Test(playerid);
new testtimer[MAX_PLAYERS];
new TestStuff[MAX_PLAYERS];
This is in a simple command:
pawn Код:
testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid);
TestStuff[playerid] += 5;
pawn Код:
public Test(playerid)
{
    if(TestStuff[playerid] >= 1)
    {
        TestStuff[playerid] -= 1;
        new teststring[128];
        format(teststring,sizeof(teststring),"TEST: (%i) Stuffs Remaining", TestStuff[playerid]);
        SendClientMessage(playerid,COLOR_RED,teststring);
        return 1;
    }
    else
    {
        KillTimer(testtimer[playerid]);
        SendClientMessage(playerid,COLOR_YELLOW,"TEST: Timer Killed");
        return 1;
    }
}
So I have something just like this and it works fine if you use the command just once. But if you use the command more then once in a row, say you spam the command twice, the timer never kills. After the TestStuff is gone it keeps repeating "TEST: Timer Killed" indefinitely. No warnings, no errors.

Why? How can I fix this?
Reply
#2

Change this:

Код:
testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid);
To:

Код:
testtimer[playerid] = SetTimerEx("Test",2000,0,"i",playerid);
Now it won't repeat.
Reply
#3

Quote:
Originally Posted by DJDhan
Now it won't repeat.
Thanks for the reply, but I need the timer to repeat, I just want it to stop repeating when the TestStuff runs out, but the KillTimer will not work when the SetTimerEx has been called twice, and this will happen a lot.
Reply
#4

What are trying to do actually?

Is this what you want to do?

Код:
forward Test(playerid);
new testtimer[MAX_PLAYERS];
new TestStuff[MAX_PLAYERS];
TestStuff[playerid] = 5;
Код:
if(!strcmp(cmdtext,"/test",true, 5))
{
    for(new i=TestStuff[playerid];i>=0;i--)
    {
        testtimer[playerid] = SetTimerEx("Test",2000,0,"ii",playerid,i);
    }
    return 1;
}
Код:
public Test(playerid)
{
new teststring[128];
format(teststring,sizeof(teststring),"TEST: (%i) Stuffs Remaining", i);
SendClientMessage(playerid,COLOR_RED,teststring);
if(i==0) KillTimer(testimer);
return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)