How to get all vehicles in a radius

Hi all!

Does anyone know how I would be able to return a table of vehicles in a radius?

My aim is to create a command to repair all vehicles in a given radius
Something like this:

RegisterCommand('repairv', function(source,args)
   local carsTable = {}
  // Get the vehicles in radius args[1] and return in carsTable
  TriggerClientEvent('repairvehicles', source, carsTable)
end)

Thanks in advance!

you can use the GamePool to fetch the cars in your current pool then check the distance between the player and the vehicles.

you could try GetRandomVehicleInSphere, check to see if the car was already repaired?

Hi there. Thanks for your response, how can I fetch the vehicles with game pool though?

Example which you can use an example, simply change the checking if the seat is empty, to check if its damaged then repair it.

local vehiclePool = GetGamePool('CVehicle') -- Get the list of vehicles (entities) from the pool
for i = 1, #vehiclePool do -- loop through each vehicle (entity)
    if GetPedInVehicleSeat(vehiclePool[i], -1) == 0 then
        DeleteEntity(vehiclePool[i]) -- Delete vehicles (entities) that don't have a driver
    end
end```