SA-MP Forums Archive
timer wont stop - 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 wont stop (/showthread.php?tid=73373)



timer wont stop - dice7 - 14.04.2009

I made this code:
Код:
new timer1;
Код:
	if (strcmp("/rainbow", cmdtext, true, 10) == 0)
  {
  new aa=0,bb;
  aa++;
  bb = aa%2;
	if(bb == 0)
	{
 	KillTimer(timer1);
	}
  timer1 = SetTimerEx("rainbow",50,1,"i",playerid);
  return 1;
	}
Код:
forward rainbow(playerid);
public rainbow(playerid)
{
	new ab, ac;
 	ab=random(127);
 	ac=random(127);
 	new veh;
	veh = GetPlayerVehicleID(playerid);
	ChangeVehicleColor(veh, ab, ac);
}
This code just randomly changes a cars colors. But the problem is that I can't make it stop. I also made a "rainbowoff" cmd which only had "killtimer(timer1)", but it still didn't want to stop. Please help


Re: timer wont stop - Benjo - 14.04.2009

When you kill the timer, the next line of the code will always restart it. Try giving your IF statement an ELSE part, and move the SetTimerEx line into there.

Код:
if(bb == 0)
{
  KillTimer(timer1);
}else{
  timer1 = SetTimerEx("rainbow", 50, 1, "i", playerid);
}
Hope that helps.


Re: timer wont stop - dice7 - 14.04.2009

I can't believe i made a silly mistake like that. But the code still doesn't work
I put the timer1 = SetTimerEx("rainbow",50,1,"i",playerid); firstly an else, like you showed and then before the if, but it still doesn't work


Re: timer wont stop - Benjo - 14.04.2009

Replace 'new timer1;' with this:
Код:
new timer1[MAX_PLAYERS];
new rainbowing[MAX_PLAYERS];
Then replace the IF statement with:
Код:
if(strcmp(cmd, "/rainbow", true) == 0) 
{
  if(rainbowing[playerid] == 1)
  {
    KillTimer(timer1[playerid]);
    rainbowing[playerid] = 0;
  }else{
    timer1[playerid] = SetTimerEx("rainbow", 50, 1, "i", playerid);
    rainbowing[playerid] = 1;
  }
  return 1;
}
This has changed it so every player has a timer variable of their own. Each player also has a variable that checks to see if their vehicle is currently "rainbowing" or not. If you do not have MAX_PLAYERS defined, change it to the amount of players allowed in the server at the same time. This might not be the most efficient way of doing it but it might get it working. *fingers crossed*

EDIT: oh and feel free to change the variable name "rainbowing", couldn't think of a more appropriate one


Re: timer wont stop - Nero_3D - 14.04.2009

pawn Код:
new IsRainbowing[MAX_PLAYERS];
pawn Код:
if(strcmp("/rainbow", cmdtext, true) == 0)
{
    if(IsRainbowing[playerid])
        KillTimer((IsRainbowing[playerid] - 1)), IsRainbowing[playerid] = false;
    else    IsRainbowing[playerid] = SetTimerEx("Reinbowing", 1000, true, "i", playerid) + 1;
    return true;
}
pawn Код:
forward Reinbowing(playerid);
public Reinbowing(playerid)
    if((playerid = GetPlayerVehicleID(playerid)) != INVALID_VEHICLE_ID)
        ChangeVehicleColor(playerid, random(256), random(256));



Re: timer wont stop - dice7 - 14.04.2009

Thank you. Btw, the upper script shows that there are 255 car colors in sa. Are there ?


Re: timer wont stop - Benjo - 14.04.2009

0 - 126 are all different colors. Many of the colors over 126 are black, but there are other colors. Some examples would be 130, 142, 144, 151... there are loads more.

https://sampwiki.blast.hk/wiki/Colors_List - scroll down to "Other Car Colors" on that page.