Lots of little changes.

This commit is contained in:
iTracerFacer 2024-11-15 17:54:44 -06:00
parent c2bde278a4
commit 9ce92421e6
4 changed files with 126 additions and 39 deletions

View File

@ -235,7 +235,7 @@ function BuildAFARP(Coordinate)
local m = MESSAGE:New(string.format("FARP %s in operation!",FName),15,"CTLD"):ToBlue() local m = MESSAGE:New(string.format("FARP %s in operation!",FName),15,"CTLD"):ToBlue()
end end
function my_ctld:OnAfterCratesBuild(From,Event,To,Group,Unit,Vehicle) function blue_ctld:OnAfterCratesBuild(From,Event,To,Group,Unit,Vehicle)
local name = Vehicle:GetName() local name = Vehicle:GetName()
if string.find(name,"FOB",1,true) then if string.find(name,"FOB",1,true) then
local Coord = Vehicle:GetCoordinate() local Coord = Vehicle:GetCoordinate()
@ -361,7 +361,14 @@ function blue_ctld:OnAfterTroopsDeployed(From,Event,To,Group,Unit,Troops)
-- Red CTLD Functions -- Red CTLD Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------
function red_ctld:OnAfterCratesBuild(From,Event,To,Group,Unit,Vehicle)
local name = Vehicle:GetName()
if string.find(name,"FOB",1,true) then
local Coord = Vehicle:GetCoordinate()
Vehicle:Destroy(false)
BuildAFARP(Coord)
end
end
function red_ctld:OnAfterTroopsDeployed(From,Event,To,Group,Unit,Troops) function red_ctld:OnAfterTroopsDeployed(From,Event,To,Group,Unit,Troops)
if Unit then if Unit then

View File

@ -74,7 +74,21 @@ local RED_AA_ZONES = {
ZONE:New("RED-AA-13"), ZONE:New("RED-AA-13"),
ZONE:New("RED-AA-14"), ZONE:New("RED-AA-14"),
ZONE:New("RED-AA-15"), ZONE:New("RED-AA-15"),
ZONE:New("RED-AA-16") ZONE:New("RED-AA-16"),
ZONE:New("RED-AA-17"),
ZONE:New("RED-AA-18"),
ZONE:New("RED-AA-19"),
ZONE:New("RED-AA-20"),
ZONE:New("RED-AA-21"),
ZONE:New("RED-AA-22"),
ZONE:New("RED-AA-23"),
ZONE:New("RED-AA-24"),
ZONE:New("RED-AA-25"),
ZONE:New("RED-AA-26"),
ZONE:New("RED-AA-27"),
ZONE:New("RED-AA-28"),
ZONE:New("RED-AA-29"),
ZONE:New("RED-AA-30")
} }

View File

@ -1,43 +1,109 @@
-- Define the patrol zone -- Debugging flag
local patrolZone = ZONE:New("AWACS_PatrolZone") local DEBUG = true
-- Define AWACS and its escorts -- Define AWACS and its escorts
local awacsGroup = "BLUE EWR AWACS" -- Name of AWACS group from mission editor local awacsGroupName = "BLUE EWR AWACS"
local escortGroup1 = "BlueAWACS_Escort_Group1" -- First escort group local escortGroup1Name = "BlueAWACS_Escort_Group1"
local escortGroup2 = "BlueAWACS_Escort_Group2" -- Second escort group
-- Spawn the AWACS and set up patrol behavior -- Configuration parameters
local awacs = SPAWN:New(awacsGroup) local patrolAltMin = 5000
:InitLimit(1, 0) -- Limit to one active instance of AWACS local patrolAltMax = 8000
:OnSpawnGroup(function(group) local escortFollowDistance = 1000
-- Define patrol within the zone local respawnCheckInterval = 10
local awacsPatrol = AI_PATROL_ZONE:New(group, patrolZone, 5000, 10000, 500, 800) local maxEscortSpawns = 10 -- maximum number of escort spawns - might take this out.
awacsPatrol:ManageFuelOn(.7, 300) -- AWACS returns to base when low on fuel
-- Event handler for AWACS being attacked -- Function to print debug messages if DEBUG is enabled
group:HandleEvent(EVENTS.Hit) local function DebugMessage(message)
function group:OnEventHit(EventData) if DEBUG and message then
group:RouteRTB() -- AWACS returns to base when attacked env.info("[AWACS DEBUG] " .. tostring(message))
end end
end) end
:Spawn()
-- Spawn the first escort and attach to AWACS -- Function to send a message to all players
local escort1 = SPAWN:New(escortGroup1) local function Announce(message, soundFile)
:InitLimit(1, 0) if message then
:OnSpawnGroup(function(escortGroup) MESSAGE:New(message, 15):ToAll()
-- Attach the escort to follow AWACS end
local awacsEscort1 = ESCORT:New(awacs, escortGroup) if soundFile then
awacsEscort1:Escort() --local sound = SOUND:New(soundFile)
end) --sound:ToAll()
:Spawn() end
end
-- Spawn the second escort and attach to AWACS -- Define the patrol zone
local escort2 = SPAWN:New(escortGroup2) local patrolZone = ZONE:New("AWACS_PatrolZone")
:InitLimit(1, 0) if patrolZone then
:OnSpawnGroup(function(escortGroup) DebugMessage("Patrol zone created: " .. patrolZone:GetName())
-- Attach the second escort to follow AWACS else
local awacsEscort2 = ESCORT:New(awacs, escortGroup) DebugMessage("ERROR: Patrol zone 'AWACS_PatrolZone' not found. Check the mission editor.")
awacsEscort2:Escort() return -- Exit if the patrol zone is not defined
end) end
:Spawn()
-- Define the AWACS spawn
local awacsSpawn = SPAWN:New(awacsGroupName):InitLimit(1, 0)
-- Function to spawn and attach escorts to AWACS
function spawnEscort(escortGroupName, awacsGroup)
if not escortGroupName or not awacsGroup then
DebugMessage("ERROR: Invalid escort group name or AWACS group.")
return
end
DebugMessage("Spawning escort: " .. escortGroupName)
Announce("Spawning escort for AWACS.", "escort_spawn.ogg")
local escortSpawn = SPAWN:New(escortGroupName):InitLimit(1, maxEscortSpawns)
escortSpawn:OnSpawnGroup(function(escortGroup)
if not escortGroup then
DebugMessage("ERROR: Escort group failed to spawn.")
return
end
DebugMessage("Escort spawned: " .. escortGroup:GetName())
-- Set the escort group to follow the AWACS
SCHEDULER:New(nil, function()
if awacsGroup:IsAlive() and escortGroup:IsAlive() then
escortGroup:TaskFollow(awacsGroup, escortFollowDistance)
DebugMessage("Escort assigned to follow AWACS.")
else
DebugMessage("AWACS or escort is not alive.")
end
end, {}, 3, respawnCheckInterval)
end):Spawn()
end
-- Start AWACS in a patrol pattern within the patrol zone
awacsSpawn:InitRepeatOnEngineShutDown()
:OnSpawnGroup(function(awacsGroup)
if not awacsGroup then
DebugMessage("ERROR: AWACS group failed to spawn.")
return
end
DebugMessage("AWACS spawned: " .. awacsGroup:GetName())
Announce("AWACS is now airborne and patrolling.", "awacs_spawn.ogg")
-- Create a patrol task for the AWACS in the defined zone
local patrolTask = AI_PATROL_ZONE:New(patrolZone, patrolAltMin, patrolAltMax)
patrolTask:SetControllable(awacsGroup)
patrolTask:__Start(1)
DebugMessage("Patrol task assigned to AWACS.")
-- Spawn and manage escorts
spawnEscort(escortGroup1Name, awacsGroup)
end)
:Spawn()
-- Create a scheduled task to check if AWACS is alive and respawn if destroyed
SCHEDULER:New(nil, function()
local awacsGroup = awacsSpawn:GetLastAliveGroup()
if not awacsGroup or not awacsGroup:IsAlive() then
DebugMessage("AWACS destroyed. Respawning...")
Announce("AWACS has been destroyed! Respawning...", "awacs_destroyed.ogg")
awacsSpawn:Spawn()
end
end, {}, 0, respawnCheckInterval)