SA-MP Forums Archive
Quick Question - Loops/Team vehicles - 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)
+--- Thread: Quick Question - Loops/Team vehicles (/showthread.php?tid=566948)



Quick Question - Loops/Team vehicles - FunnyBear - 09.03.2015

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


Re: Quick Question - Loops/Team vehicles - biker122 - 09.03.2015

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 ++)



AW: Quick Question - Loops/Team vehicles - Kaliber - 09.03.2015

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