SA-MP Forums Archive
[Solved]Create a loop to stop at the first available slot... - 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: [Solved]Create a loop to stop at the first available slot... (/showthread.php?tid=108864)



[Solved]Create a loop to stop at the first available slot... - Outbreak - 16.11.2009

Imagine i have 50 vehicles spawned, i've defined MAX_VEHICLES as 100.

Then i destroy vehicle IDs 3, 8, 25

So now i have 47 vehicles left, IDs 1-50 with slots 3, 8 and 25 available.

When a vehicle is created, i will set it VehSpawned[vehid] = 1;

So when looping i will need to find the first available slot, which will be VehSpawned[vehid] == 0

If im looping But how would i create a loop that will stop when it finds the first available slot?

Instead of looping through 100 slots...




Re: [Help?]Create a loop to stop at the first available slot... - yom - 16.11.2009

Use break;

Exemple:
pawn Код:
new id;
   
for (id = 1; id < MAX_VEHICLES; id ++)
  if (!VehSpawned[id])
    break;

printf("%d", id);



Re: [Help?]Create a loop to stop at the first available slot... - Donny_k - 16.11.2009

Or use 'foreach' and I think 'Itter_Free', whatever it's called it finds the first empty slot in the itterator but this would mean removing the value when you delete a vehicle so it is an empty slot.


Re: [Help?]Create a loop to stop at the first available slot... - Outbreak - 16.11.2009

Thanks guys for the replies

Great help