How can I loop trough all spawned vehicles in the server?
#1

Title says it all.
Reply
#2

for( new c = 1; c <= MAX_VEHICLES; c ++ ) but i'd recommend foreach.
Reply
#3

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?
Reply
#4

Take a look at the example: https://sampwiki.blast.hk/wiki/GetVehiclePoolSize

If you use YSI 4, make use of "Vehicle" iterator.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Take a look at the example: https://sampwiki.blast.hk/wiki/GetVehiclePoolSize

If you use YSI 4, make use of "Vehicle" iterator.
Thank you Jelly and Konstantinos for the really fast response, I appreciate it
This answers my question
Btw, what is YSI 4?
Reply
#6

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.
Reply
#7

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
Quote:
https://sampwiki.blast.hk/wiki/CreateVehicle
"The vehicle ID of the vehicle created (1 to MAX_VEHICLES)."

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)