SA-MP Forums Archive
Kameleon car - 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: Kameleon car (/showthread.php?tid=115530)



Kameleon car - WThieves - 24.12.2009

Help!, i want to make a command that makes it so that yout car acts like a kameleon, with this i mean it changes its color to a random one every second, how do i do this?
I've got this:
Quote:

if (strcmp(cmd, "/Kameleon", true) ==0 )
{
SetTimer("Kameleon", 1000, 0);
}

Quote:

public Kameleon(playerid)
{
RandomVehColor(playerid);
SetTimer("Kameleon2", 1000, 0);
}
public Kameleon2(playerid)
{
RandomVehColor(playerid);
SetTimer("Kameleon", 1000, 0);
}
It compiles and all but it doesn't work


Re: Kameleon car - DeathOnaStick - 24.12.2009

1. Why do you use 2 timers?
2. How did you declare the function"RandomVehColor"?

Cheerz


Re: Kameleon car - WThieves - 24.12.2009

Quote:
Originally Posted by DeathOnaStick
1. Why do you use 2 timers?
2. How did you declare the function"RandomVehColor"?

Cheerz
1:I used 2 timers for a loop
2:
Quote:

public RandomVehColor(playerid)
{
if(!IsPlayerInAnyVehicle(playerid)) return 0;
new rcolor = random(126); //max colors
ChangeVehicleColor(playerid,rcolor,rcolor);
return 1;
}




Re: Kameleon car - Backwardsman97 - 24.12.2009

Yeah, what's the point in two different timers if they both do the same thing?

pawn Код:
new Chameleon[MAX_PLAYERS];//At the top, btw how you actually spell it :P

if(!strcmp(cmd, "/kameleon", true))
{
   if(Chameleon[playerid]==-1)
       Chameleon[playerid]=SetTimerEx("Kameleon", 1000, 1, "i", playerid);
   else
   {
       KillTimer(Chameleon[playerid]);
       Chameleon[playerid]=-1;
   }
}

public Kameleon(playerid)
{
  RandomVehColor(playerid);
  return 1;
}
That would be a better version of it. The reason it wasn't working, was because you need to use SetTimerEx when the public function has parameters. And for a loop, just use a 1 in the last parameter of SetTimer. Just make sure you store the timer id to kill it later.


Re: Kameleon car - WThieves - 24.12.2009

Quote:
Originally Posted by Backwardsman97
Yeah, what's the point in two different timers if they both do the same thing?

pawn Код:
new Chameleon[MAX_PLAYERS];//At the top, btw how you actually spell it :P

if(!strcmp(cmd, "/kameleon", true))
{
   if(Chameleon[playerid]==-1)
      Chameleon[playerid]=SetTimerEx("Kameleon", 1000, 1, "i", playerid);
   else
   {
      KillTimer(Chameleon[playerid]);
      Chameleon[playerid]=-1;
   }
}

public Kameleon(playerid)
{
 RandomVehColor(playerid);
 return 1;
}
That would be a better version of it. The reason it wasn't working, was because you need to use SetTimerEx when the public function has parameters. And for a loop, just use a 1 in the last parameter of SetTimer. Just make sure you store the timer id to kill it later.
I'll try it and say if it works btw in the netherlands its Kameleon


Re: Kameleon car - Backwardsman97 - 24.12.2009

Oh sorry. :X


Re: Kameleon car - WThieves - 24.12.2009

I got this!
Quote:

**********gamemodes\gf.pwn(26827) : error 021: symbol already defined: "Chameleon"
**********gamemodes\gf.pwn(26829) : error 021: symbol already defined: "RandomVehColor"
**********gamemodes\gf.pwn(26830) : error 010: invalid function or declaration

Lines:
Quote:

public Chameleon(playerid) //26827
{ //26828
RandomVehColor(playerid); //26829
return 1; //26830
} //26831




Re: Kameleon car - Backwardsman97 - 24.12.2009

Use the code I posted. You changed the name of the public function, which was already assigned to the global variable of Chameleon.
pawn Код:
public Chameleon(playerid) //26827
Should have stayed:
pawn Код:
public Kameleon(playerid)



Re: Kameleon car - WThieves - 24.12.2009

Quote:
Originally Posted by Backwardsman97
Use the code I posted. You changed the name of the public function, which was already assigned to the global variable of Chameleon.
pawn Код:
public Chameleon(playerid) //26827
Should have stayed:
pawn Код:
public Kameleon(playerid)
Alright i'll redo!


Re: Kameleon car - WThieves - 24.12.2009

Quote:
Originally Posted by WThieves
Quote:
Originally Posted by Backwardsman97
Use the code I posted. You changed the name of the public function, which was already assigned to the global variable of Chameleon.
pawn Код:
public Chameleon(playerid) //26827
Should have stayed:
pawn Код:
public Kameleon(playerid)
Alright i'll redo!
Well now it doesn't give any errors but if i use the command iy still wont change the car's colors!