14.07.2016, 16:20
You should start using GetVehiclePoolSize (Unless you're not using SA-MP 0.3.7)
It retrieves the highest vehicle ID, so instead of 2000 (MAX_VEHICLES), you'd be using something much lower if there isn't a lot of vehicles.
I just wrote this, so I'm not sure if it has any bugs or not.
It retrieves the highest vehicle ID, so instead of 2000 (MAX_VEHICLES), you'd be using something much lower if there isn't a lot of vehicles.
I just wrote this, so I'm not sure if it has any bugs or not.
Код:
native IsValidVehicle(vehicleid); // According to the wiki, it doesn't exist in the default sa-mp includes, so you have to add it. GetClosestVehicle(playerid, Float: range) { new vehicleid = -1, Float: last = range, Float: current, Float: x, Float: y, Float: z; GetPlayerPos(playerid, x, y, z); for (new i = 1, j = GetVehiclePoolSize(); i <= j; i++) // for (new i = 1; i < MAX_VEHICLES; i++) { if (!IsValidVehicle(i)) continue; current = GetVehicleDistanceFromPoint(i, x, y, z); if (current < last) { vehicleid = i; last = current; } } return vehicleid; }