get player units fixed

This commit is contained in:
2024-11-06 09:51:31 +01:00
parent 64f87abd7a
commit 242e313093
2 changed files with 14 additions and 12 deletions
+3 -3
View File
@@ -449,7 +449,7 @@ do -- INIT DCS_UTIL
return DCS_UTIL.__miz_groups[groupName].category == 5; return DCS_UTIL.__miz_groups[groupName].category == 5;
end end
return Group.getByName(groupName) == nil return StaticObject.getByName(groupName) ~= nil
end end
---comment ---comment
@@ -743,7 +743,7 @@ do -- INIT DCS_UTIL
---@return table units ---@return table units
function DCS_UTIL.getAllPlayerUnits() function DCS_UTIL.getAllPlayerUnits()
local units = {} local units = {}
for key, value in pairs({ 1, 2, 3 }) do for key, value in pairs({ 0, 1, 2 }) do
local players = coalition.getPlayers(value) local players = coalition.getPlayers(value)
for key, unit in pairs(players) do for key, unit in pairs(players) do
units[#units + 1] = unit units[#units + 1] = unit
@@ -791,7 +791,7 @@ do -- INIT DCS_UTIL
function DCS_UTIL.getAllPlayerGroups() function DCS_UTIL.getAllPlayerGroups()
local groupNames = {} local groupNames = {}
local result = {} local result = {}
for key, value in pairs({ 1, 2, 3 }) do for key, value in pairs({ 0, 1, 2 }) do
local players = coalition.getPlayers(value) local players = coalition.getPlayers(value)
for key, unit in pairs(players) do for key, unit in pairs(players) do
local group = unit:getGroup() local group = unit:getGroup()
+11 -9
View File
@@ -302,13 +302,15 @@ do
local function CheckAndTriggerSpawnAsync(unit, time) local function CheckAndTriggerSpawnAsync(unit, time)
local function isPlayer(unit) local function isPlayer(unit)
if unit == nil then return false, "unit is nil" end
if unit and unit:isExist() then if unit:isExist() ~= true then return false, "unit does not exist" end
if Spearhead.DcsUtil.IsGroupStatic(unit:getName()) == true then local group = unit:getGroup()
if group ~= nil then
if Spearhead.DcsUtil.IsGroupStatic(group:getName()) == true then
return false return false
end end
if AI_GROUPS[unit:getGroup():getName()] == true then if AI_GROUPS[group:getName()] == true then
return false return false
end end
@@ -319,15 +321,15 @@ do
return true return true
end end
end end
AI_GROUPS[unit:getGroup():getName()] = true AI_GROUPS[group:getName()] = true
end end
return false return false, "unit is nil or does not exist"
end end
if isPlayer(event.initiator) == true then if isPlayer(unit) == true then
local groupId = event.initiator:getGroup():getID() local groupId = unit:getGroup():getID()
SpearheadEvents.AddCommandsToGroup(groupId) SpearheadEvents.AddCommandsToGroup(groupId)
SpearheadEvents.TriggerPlayerEntersUnit(event.initiator) SpearheadEvents.TriggerPlayerEntersUnit(unit)
end end
return nil return nil