Problem with killing a timer
#1

Hello all, thanks for helping me here
My problem is that I made a timer that starts when you type a command, and it stills repeating, than I made another command that kills the timer, but it's not working properly.
Like this, sometimes, you type the command and the timer stops, but other times, its bugs and you can type the command the many times you want, and the timer just doesnt stop.
I dont know why, can anyone help me please?

Код:
new TimerCores;
new CoresAuto[MAX_PLAYERS];

OnPlayerDisconnect
CoresAuto[playerid] = 0;

OnPlayerCommandText
if(strcmp(cmd, "/cores", true) == 0) //This Starts the Timer
{
	if(IsPlayerConnected(playerid))
	{
		if(CoresAuto[playerid] == 0)
		{
			if(IsPlayerInAnyVehicle(playerid)) {
			CoresAuto[playerid] = 1;
			TimerCores = SetTimerEx("Rainbow", 100, true, "i", playerid);
			SendClientMessage(playerid, COLOR_GREEN, "Cores automбticas ATIVADO!");
			SendClientMessage(playerid,cinza,"Para parar as cores automбticas, digite /pararcores.");
			}
			else
			{
			SendClientMessage(playerid, COLOR_RED, "Vocк nгo estб em um veнculo!");
			}
			return 1;
			}
		else if(CoresAuto[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR_RED, "Cores automбticas jб estб ativado!");
			return 1;
		}
	}
}

if(strcmp(cmd, "/pararcores", true) == 0) //This kill the timer
{
	CoresAuto[playerid] = 0;
	KillTimer(TimerCores);
	SendClientMessage(playerid, COLOR_RED, "Cores automбticas DESATIVADO!");
	return 1;
}


public AutoCores(playerid) //This is the public that the timer will use
{
new rand = random(252)+0;
new rand1 = random(252)+0;
new iVehicleID = GetPlayerVehicleID(playerid);
ChangeVehicleColor(iVehicleID,rand,rand1);
return 1;
}
Anyone can please help me? Thanks
Reply
#2

The main thing I can see here is that you are using one variable to store the timer id, then you change it. So if playerid 1 types this command, it will set TimerCores to his timerid. Then if playerid 2 tries to do it, it will set TimerCores to his timerid. Then when playerid 1 tries to kill the timer, he's just killing playerid 2's. You see what I'm saying? If more than one player types this command, it will bug. You need to give each player a unique timerid.

http://pastebin.com/m6b1a8f65

Try that. Instead of using two variables, one to store the timerid and one to see if they've set a timer, I just used one. That way, you can store the timerid for that playerid, and also set it to -1 when it's not being used.
Reply
#3

Thanks man, it worked perfectly
Reply
#4

Er...sorry, it's not working so good, for near everyone it stops, but for some players, it still working...is there any way to make the timer work for like 2 min and than stop automactly?
Reply
#5

I got a problem :/ When i make a account everythink is ok, and when i log in everythink is good. But when
create a character it takes me back to the login page :/ why ? -.-
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)