From e83ea8124e380e027aa37989c8d2134996634f8b Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sat, 7 May 2022 11:54:48 +0200 Subject: [PATCH] GROUP - change to GetUnits(n) to make it more robust, now returns first alive unit,actually. Similar changes to GetHeading() --- Moose Development/Moose/Wrapper/Group.lua | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index d8b23a871..076d6e623 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -701,15 +701,26 @@ function GROUP:GetUnit( UnitNumber ) local DCSGroup = self:GetDCSObject() if DCSGroup then - - local DCSUnit = DCSGroup:getUnit( UnitNumber ) - local UnitFound = UNIT:Find(DCSUnit) + local UnitFound = nil + -- 2.7.1 dead event bug, return the first alive unit instead + local units = DCSGroup:getUnits() or {} + + for _,_unit in pairs(units) do + + local UnitFound = UNIT:Find(_unit) + + if UnitFound and UnitFound:IsAlive() then + + return UnitFound + + end + end - return UnitFound end return nil + end --- Returns the DCS Unit with number UnitNumber. @@ -1105,17 +1116,17 @@ function GROUP:GetHeading() local GroupSize = self:GetSize() local HeadingAccumulator = 0 - local n=0 + local Units = self:GetUnits() + if GroupSize then - for i = 1, GroupSize do - local unit=self:GetUnit(i) + for _,unit in pairs(Units) do if unit and unit:IsAlive() then HeadingAccumulator = HeadingAccumulator + unit:GetHeading() n=n+1 end end - return math.floor(HeadingAccumulator / n) + return math.floor(HeadingAccumulator / n) end BASE:E( { "Cannot GetHeading", Group = self, Alive = self:IsAlive() } )