How can I loop trough all spawned vehicles in the server? - 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: How can I loop trough all spawned vehicles in the server? (
/showthread.php?tid=620824)
How can I loop trough all spawned vehicles in the server? -
EtayJ - 03.11.2016
Title says it all.
Re: How can I loop trough all spawned vehicles in the server? - Jelly23 - 03.11.2016
for( new c = 1; c <= MAX_VEHICLES; c ++ ) but i'd recommend foreach.
Re: How can I loop trough all spawned vehicles in the server? -
EtayJ - 03.11.2016
Quote:
Originally Posted by Jelly23
for( new c = 1; c <= MAX_VEHICLES; c ++ ) but i'd recommend foreach.
|
MAX_VEHICLES is the maximum amount of vehicles that are CURRENTLY SPAWNED in the server? Does it change every single time I spawn or despawn a car? How do I get the ID of vehicle c in the loop?
Re: How can I loop trough all spawned vehicles in the server? -
Konstantinos - 03.11.2016
Take a look at the example:
https://sampwiki.blast.hk/wiki/GetVehiclePoolSize
If you use YSI 4, make use of "Vehicle" iterator.
Re: How can I loop trough all spawned vehicles in the server? -
EtayJ - 03.11.2016
Quote:
Originally Posted by Konstantinos
|
Thank you Jelly and Konstantinos for the really fast response, I appreciate it
This answers my question
Btw, what is YSI 4?
Re: How can I loop trough all spawned vehicles in the server? -
Konstantinos - 03.11.2016
Quote:
Originally Posted by EtayJ
Btw, what is YSI 4?
|
YSI library contains many includes such as
y_ini,
y_iterate (also known as
foreach) and many more.
I just mentioned in case you were using it already so you'd take advantage of the pre-made iterators.
Re: How can I loop trough all spawned vehicles in the server? -
RedFusion - 03.11.2016
pawn Код:
for(new vehicleid = 1, max_vehicleid = GetVehiclePoolSize(); vehicleid <= max_vehicleid; vehicleid ++) {
if(IsValidVehicle(vehicleid)) {
// do stuff
}
}
something like this?
https://sampwiki.blast.hk/wiki/Loops
https://sampwiki.blast.hk/wiki/GetVehiclePoolSize