Small Quest.
#1


After a long time doing nothing related to the scripting scene , I decided to do some little stuff again. And a after a while something bugged me.

For example , you want to add a 10 vehicles , assigned to a team or whatever.

Код:
new teamcars[10]; // at start
Код:
teamcar[1] = AddStaticVehicleEx // at ongamemode init
teamcar[2] = AddStaticVehicleEx
etc
etc
Afterwards you only want a certain team to enter these cars.

Код:
if(vehicleid == teamcar[1] || vehicleid == teamcar[1] ) // at public OnPlayerEnterVehicle
{
 // check team here 
else
{
// kick wrong out  	
}
}

This goes all without any problems.

Now the question is how would I be able to check teamcar[1] till teamcar[10] , without calling them separtely each time ( like vehicleid == teamcar[1] || vehicleid == teamcar[2] || etc )

Maybe the answer is simple , but I never tried something like this , I just want to simplify code.
Doing this with carids is rather simple ;

Код:
 if((carid >= 61) && (carid <= 63)
Doing this with my code is something different.
Reply
#2

Код:
for(new i=0; i<10; i++)
{
  if(vehicleid == teamcars[i])
  {
    //The vehicle is a teamcar 
    //rest of code
    break;   //This stops the loop
  } 
}
Reply
#3

sandra can you please give an example of

for(new i=0; i<2; i++)
{
if(vehicleid == teamcars[i])
{
//The vehicle is a teamcar
//rest of code
break; //This stops the loop
}
}

Thanks
Reply
#4

Код:
public IsAPoliceCar(vehicleid)
{
	for(new i=0; i<35; i++)
  {
  if(vehicleid == copv[i])
  {
  break;
  }
  }
  return 1;
}
This code should see copv[1] etc etc till copv[34] as a copcar. Instead of that , it sees all cars as a copcar. Where does it go wrong ?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)