getRandomParkingSpots
Definition
-- @/lua/ge/extensions/gameplay/city.lua:61
local function getRandomParkingSpots(minDist, startName) -- returns parking spot & zone names (start & destination) with a minimum distance
-- startName is optional
minDist = minDist or 300
local spots = sites.parkingSpots
local names = tableKeys(spots.byName)
if not names[2] then -- needs at least two parking spots
log('W', logTag, 'Minimum 2 parking spots needed to return a start and finish result!')
return
end
-- randomize parkingspot names
names = arrayShuffle(names)
local nameA, nameB = names[1], names[2]
if startName and spots.byName[startName] then
nameA = startName
end
local pA, pB = spots.byName[nameA], spots.byName[nameB]
local i = 2
while nameB and pA.pos:distance(pB.pos) < minDist do
pB = spots.byName[names[i]]
nameB = names[i]
i = i + 1
end
if not nameB then -- no destination beyond distance found
log('W', logTag, 'No destination parking spot found within given distance')
return
end
table.sort(pA.zones, function(a,b) return (a.customFields.values.priority or 0) > (b.customFields.values.priority or 0) end)
table.sort(pB.zones, function(a,b) return (a.customFields.values.priority or 0) > (b.customFields.values.priority or 0) end)
return nameA, nameB, pA.zones[1].name, pB.zones[1].name
end
Callers
@/lua/ge/extensions/gameplay/parking.lua
local function getRandomParkingSpots(originPos, minDist, maxDist, minCount, filters) -- returns a list of random parking spots, with a bias for origin position
if not sites then return {} end
vehIds = vehIds or parkedVehIds
local randomPsList, psList = getRandomParkingSpots(focus and focus.pos, minDist, maxDist, #vehIds)
if not psList then return end
local transforms
local psList = getRandomParkingSpots(options.pos, nil, nil, amount, {checkVehicles = true})
if psList[1] then