Quick Question - Loops/Team vehicles
#1

Hey,

I was adding team vehicles to my server, and then I thought of something.

Instead of having

pawn Код:
new SwatCars[2]; // Top

SwatCars[0] = CreateVehicle(..
SwatCars[1] = CreateVehicle(.. // OnGameModeInit

if(vehicleid == SwatCars[0] || vehicleid == SwatCars[1]) // OnPlayerEnterVehicle
Would I be able to loop through the swat vehicles? Like this,

pawn Код:
#define MAX_SWAT 2
new SwatCars[MAX_SWAT];

SwatCars[0] = CreateVehicle(..
SwatCars[1] = CreateVehicle(..

for(new i = 0; i < MAX_SWAT; c++) {
if(vehicleid == SwatCars[i])}
Thanks
Reply
#2

You could just do it like:
pawn Код:
new SwatCars[2];
and loop through them by using:
pawn Код:
for(new i = 0; i < sizeof(SwatCars); i ++)
Reply
#3

Sure

But you can do sth smarter and work with flags

PHP код:
new SwatCars[2];
SwatCars[0] = CreateVehicle(...); //First swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
CreateVehicle(...); //swat car
SwatCars[1] = CreateVehicle(...); //Last swat car
if(SwatCars[0] <= vehicleid <= SwatCars[1]) 
{
     
//Here it is a SwatCar

So you always need only 2 cells

Greekz
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)