mirror of
https://github.com/akaAgar/the-universal-mission-for-dcs-world.git
synced 2025-11-25 19:31:01 +00:00
68 lines
2.5 KiB
Lua
68 lines
2.5 KiB
Lua
-- ====================================================================================
|
|
-- TUM.SUPPORTWINGMEN - HANDLES THE PLAYER'S WINGMEN
|
|
-- ====================================================================================
|
|
-- ====================================================================================
|
|
|
|
TUM.supportWingmen = {}
|
|
|
|
do
|
|
local wingmenGroupID = nil
|
|
|
|
local function createWingmen()
|
|
TUM.supportWingmen.removeAll() -- Destroy all pre-existing wingmen
|
|
TUM.log("Creating wingmen...")
|
|
|
|
local player = world:getPlayer()
|
|
if not player then return end
|
|
|
|
local playerTypeName = player:getTypeName()
|
|
|
|
local groupInfo = DCSEx.unitGroupMaker.create(
|
|
TUM.settings.getPlayerCoalition(),
|
|
Group.Category.AIRPLANE, -- TODO: or helicopter!
|
|
DCSEx.math.randomPointInCircle(DCSEx.math.vec3ToVec2(player:getPoint()), 500, 250),
|
|
{ playerTypeName, playerTypeName },
|
|
{
|
|
callsign = DCSEx.unitCallsignMaker.getNextGroupCallSign(player:getCallsign()),
|
|
silenced = true,
|
|
taskFollow = DCSEx.dcs.getObjectIDAsNumber(player:getGroup()),
|
|
unlimitedFuel = true
|
|
}
|
|
)
|
|
|
|
if not groupInfo then
|
|
TUM.log("Failed to spawn AI wingmen", TUM.logLevel.WARNING)
|
|
return
|
|
end
|
|
|
|
TUM.log("Spawned AI wingmen")
|
|
wingmenGroupID = groupInfo.groupID
|
|
end
|
|
|
|
function TUM.supportWingmen.removeAll()
|
|
if wingmenGroupID then TUM.log("Removing all wingmen...") end
|
|
|
|
DCSEx.world.destroyGroupByID(wingmenGroupID)
|
|
|
|
wingmenGroupID = nil
|
|
end
|
|
|
|
-------------------------------------
|
|
-- Called when an event is raised
|
|
-- @param event The DCS World event
|
|
-------------------------------------
|
|
function TUM.supportWingmen.onEvent(event)
|
|
if TUM.settings.getValue(TUM.settings.id.MULTIPLAYER) then return end -- No wingmen in multiplayer
|
|
if TUM.mission.getStatus() == TUM.mission.status.NONE then return end
|
|
if not event.initiator then return end
|
|
if Object.getCategory(event.initiator) ~= Object.Category.UNIT then return end
|
|
if not event.initiator:getPlayerName() then return end
|
|
|
|
if event.id == world.event.S_EVENT_TAKEOFF then -- Create wingmen on takeoff
|
|
createWingmen()
|
|
elseif event.id == world.event.S_EVENT_LAND then
|
|
TUM.supportWingmen.removeAll() -- Remove wingmen on landing
|
|
end
|
|
end
|
|
end
|