GROUP - change to GetUnits(n) to make it more robust, now returns first alive unit,actually. Similar changes to GetHeading()

This commit is contained in:
Applevangelist
2022-05-07 11:54:48 +02:00
parent 313f99d09d
commit e83ea8124e

View File

@@ -702,14 +702,25 @@ function GROUP:GetUnit( UnitNumber )
if DCSGroup then if DCSGroup then
local DCSUnit = DCSGroup:getUnit( UnitNumber ) local UnitFound = nil
-- 2.7.1 dead event bug, return the first alive unit instead
local units = DCSGroup:getUnits() or {}
local UnitFound = UNIT:Find(DCSUnit) for _,_unit in pairs(units) do
local UnitFound = UNIT:Find(_unit)
if UnitFound and UnitFound:IsAlive() then
return UnitFound
end
end
return UnitFound
end end
return nil return nil
end end
--- Returns the DCS Unit with number UnitNumber. --- Returns the DCS Unit with number UnitNumber.
@@ -1105,11 +1116,11 @@ function GROUP:GetHeading()
local GroupSize = self:GetSize() local GroupSize = self:GetSize()
local HeadingAccumulator = 0 local HeadingAccumulator = 0
local n=0 local n=0
local Units = self:GetUnits()
if GroupSize then if GroupSize then
for i = 1, GroupSize do for _,unit in pairs(Units) do
local unit=self:GetUnit(i)
if unit and unit:IsAlive() then if unit and unit:IsAlive() then
HeadingAccumulator = HeadingAccumulator + unit:GetHeading() HeadingAccumulator = HeadingAccumulator + unit:GetHeading()
n=n+1 n=n+1