SetTimerEx Problem
#1

Basically, I have a command and all it has in it is a variable and a SetTimerEx. In the callback that the timer is calling it reduces the variable each second until it = 0 then it kills the timer for the player. It works as it should if the command is only used once, however if the player spams the command twice, the timer will never kill, and it keeps repeating the Test callback.. Has anyone else ever had this problem with SetTimerEx?

pawn Код:
forward Test(playerid);
new testtimer[MAX_PLAYERS];
new TestStuff[MAX_PLAYERS];
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;
    }
}
pawn Код:
if (strcmp("/test", cmdtext, true, 5) == 0)
{
    testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid);
    TestStuff[playerid] += 5;
   
    return 1;
}
This above, if you use the command while its still counting down from the last time you used the command, the timer will never kill and it will just keep sending the "TEST: Timer Killed" message..

Is this a known problem with the function, or am I completely looking over something?

Reply
#2

pawn Код:
public Test(playerid)
{
    if(TestStuff[playerid])
    {
        TestStuff[playerid]--;
        new teststring[128];
        format(teststring,sizeof(teststring),"TEST: (%i) Stuffs Remaining", TestStuff[playerid]);
        SendClientMessage(playerid,COLOR_RED,teststring);
        return 1;
    }
    else
    {
        KillTimer(testtimer[playerid]);
        TestStuff[playerid]=0;
        SendClientMessage(playerid,COLOR_YELLOW,"TEST: Timer Killed");
        return 1;
    }
}
pawn Код:
if(strcmp("/test", cmdtext, true, 5) == 0)
{
    if(!TestStuff[playerid])
        testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid);
    TestStuff[playerid] += 5;
    return 1;
}
Reply
#3

Quote:
Originally Posted by Jefff
I appreciate the response but its not quite what I'm trying to get at, basically the problem is with the timer, if the timers already running, and its called again, it will never allow you to kill it again. If you try that simple little script on my first post on an empty gamemode you will see what I mean. Yes, I could try to avoid this by only allowing them to use the command once until the timer stops, but for the use I need it for I need them to be able to use it as much as possible.

Kind of difficult to explain, I hope I clarified the question.
Reply
#4

Quote:
Originally Posted by yeswecanchange09
Quote:
Originally Posted by Jefff
I appreciate the response but its not quite what I'm trying to get at, basically the problem is with the timer, if the timers already running, and its called again, it will never allow you to kill it again. If you try that simple little script on my first post on an empty gamemode you will see what I mean. Yes, I could try to avoid this by only allowing them to use the command once until the timer stops, but for the use I need it for I need them to be able to use it as much as possible.

Kind of difficult to explain, I hope I clarified the question.
I understand and this is normal
example
Код:
testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid); // Timer return 1 so testtimer[playerid] = 1;
U type command second time
Код:
testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid); // Timer return 2 so testtimer[playerid] = 2;
U type command third time
Код:
testtimer[playerid] = SetTimerEx("Test",2000,1,"i",playerid); // Timer return 3 so testtimer[playerid] = 3;
Код:
...
	}
	else
	{
		KillTimer(testtimer[playerid]); // it kills testtimer[playerid] = 3, so testtimer[playerid] = 1 and 2 are stil calling
		TestStuff[playerid]=0;
		SendClientMessage(playerid,COLOR_YELLOW,"TEST: Timer Killed");
		return 1;
	}
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)