diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 557180a32..fc77cdeb6 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -3803,17 +3803,20 @@ do -- COORDINATE -- @param #number SearchRadius Radius of the search area. -- @param #number PosRadius Required clear radius around each position. -- @param #number NumPositions Number of positions to find. --- @return #table A table of Core.Point#COORDINATE that are clear of map objects within the given PosRadius. +-- @return #table A table of Core.Point#COORDINATE that are clear of map objects within the given PosRadius. nil if no positions are found. function COORDINATE:GetSimpleZones(SearchRadius, PosRadius, NumPositions) local clearPositions = UTILS.GetSimpleZones(self:GetVec3(), SearchRadius, PosRadius, NumPositions) - local coords = {} - for _, pos in ipairs(clearPositions) do - local coord = COORDINATE:NewFromVec2(pos) - table.insert(coords, coord) + if clearPositions and #clearPositions > 0 then + local coords = {} + for _, pos in pairs(clearPositions) do + local coord = COORDINATE:NewFromVec2(pos) + table.insert(coords, coord) + end + return coords end - return coords + return nil end - + end do diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index a44698097..401aab808 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -1515,7 +1515,7 @@ end -- @return #table A table of DCS#Vec2 positions that are clear of map objects within the given PosRadius. nil if no clear positions are found. function ZONE_RADIUS:GetClearZonePositions(PosRadius, NumPositions) local clearPositions = UTILS.GetSimpleZones(self:GetVec3(), self:GetRadius(), PosRadius, NumPositions) - if clearPositions or #clearPositions > 0 then + if clearPositions and #clearPositions > 0 then local validZones = {} for _, vec2 in pairs(clearPositions) do if self:IsVec2InZone(vec2) then @@ -1538,7 +1538,7 @@ end function ZONE_RADIUS:GetRandomClearZoneCoordinate(PosRadius, NumPositions) local radius = PosRadius or math.min(self.Radius/10, 200) local clearPositions = self:GetClearZonePositions(radius, NumPositions or 50) - if clearPositions or #clearPositions > 0 then + if clearPositions and #clearPositions > 0 then local randomPosition = clearPositions[math.random(1, #clearPositions)] return COORDINATE:NewFromVec2(randomPosition), radius end