SA-MP Forums Archive
Timer 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Timer Problem (/showthread.php?tid=154118)



Timer Problem - yeswecanchange09 - 12.06.2010

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?


Re: Timer Problem - DJDhan - 12.06.2010

Change this:

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

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


Re: Timer Problem - yeswecanchange09 - 12.06.2010

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.


Re: Timer Problem - DJDhan - 12.06.2010

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;
}