Kameleon car
#1

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
Reply
#2

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

Cheerz
Reply
#3

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

Reply
#4

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.
Reply
#5

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
Reply
#6

Oh sorry. :X
Reply
#7

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

Reply
#8

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)
Reply
#9

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!
Reply
#10

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)