diff --git a/DCS_Afgainistan/Insurgent_Sandstorm/F99th-Insurgent_Sandstorm_1.0.6.miz b/DCS_Afgainistan/Insurgent_Sandstorm/F99th-Insurgent_Sandstorm_1.0.6.miz index a56e2eb..cf48cba 100644 Binary files a/DCS_Afgainistan/Insurgent_Sandstorm/F99th-Insurgent_Sandstorm_1.0.6.miz and b/DCS_Afgainistan/Insurgent_Sandstorm/F99th-Insurgent_Sandstorm_1.0.6.miz differ diff --git a/DCS_Afgainistan/Insurgent_Sandstorm/Moose_CTLD.lua b/DCS_Afgainistan/Insurgent_Sandstorm/Moose_CTLD.lua index 63c0c47..b1ff22b 100644 --- a/DCS_Afgainistan/Insurgent_Sandstorm/Moose_CTLD.lua +++ b/DCS_Afgainistan/Insurgent_Sandstorm/Moose_CTLD.lua @@ -235,7 +235,7 @@ function BuildAFARP(Coordinate) local m = MESSAGE:New(string.format("FARP %s in operation!",FName),15,"CTLD"):ToBlue() 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() if string.find(name,"FOB",1,true) then local Coord = Vehicle:GetCoordinate() @@ -361,7 +361,14 @@ function blue_ctld:OnAfterTroopsDeployed(From,Event,To,Group,Unit,Troops) -- 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) if Unit then diff --git a/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm.lua b/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm.lua index a159381..f81fb0a 100644 --- a/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm.lua +++ b/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm.lua @@ -74,7 +74,21 @@ local RED_AA_ZONES = { ZONE:New("RED-AA-13"), ZONE:New("RED-AA-14"), 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") } diff --git a/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm_Awacs.lua b/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm_Awacs.lua index 40a86d3..5037fed 100644 --- a/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm_Awacs.lua +++ b/DCS_Afgainistan/Insurgent_Sandstorm/Moose_InsurgentSandstorm_Awacs.lua @@ -1,43 +1,109 @@ --- Define the patrol zone -local patrolZone = ZONE:New("AWACS_PatrolZone") +-- Debugging flag +local DEBUG = true -- Define AWACS and its escorts -local awacsGroup = "BLUE EWR AWACS" -- Name of AWACS group from mission editor -local escortGroup1 = "BlueAWACS_Escort_Group1" -- First escort group -local escortGroup2 = "BlueAWACS_Escort_Group2" -- Second escort group +local awacsGroupName = "BLUE EWR AWACS" +local escortGroup1Name = "BlueAWACS_Escort_Group1" --- Spawn the AWACS and set up patrol behavior -local awacs = SPAWN:New(awacsGroup) - :InitLimit(1, 0) -- Limit to one active instance of AWACS - :OnSpawnGroup(function(group) - -- Define patrol within the zone - local awacsPatrol = AI_PATROL_ZONE:New(group, patrolZone, 5000, 10000, 500, 800) - awacsPatrol:ManageFuelOn(.7, 300) -- AWACS returns to base when low on fuel +-- Configuration parameters +local patrolAltMin = 5000 +local patrolAltMax = 8000 +local escortFollowDistance = 1000 +local respawnCheckInterval = 10 +local maxEscortSpawns = 10 -- maximum number of escort spawns - might take this out. - -- Event handler for AWACS being attacked - group:HandleEvent(EVENTS.Hit) - function group:OnEventHit(EventData) - group:RouteRTB() -- AWACS returns to base when attacked +-- Function to print debug messages if DEBUG is enabled +local function DebugMessage(message) + if DEBUG and message then + env.info("[AWACS DEBUG] " .. tostring(message)) end - end) - :Spawn() +end --- Spawn the first escort and attach to AWACS -local escort1 = SPAWN:New(escortGroup1) - :InitLimit(1, 0) - :OnSpawnGroup(function(escortGroup) - -- Attach the escort to follow AWACS - local awacsEscort1 = ESCORT:New(awacs, escortGroup) - awacsEscort1:Escort() - end) - :Spawn() +-- Function to send a message to all players +local function Announce(message, soundFile) + if message then + MESSAGE:New(message, 15):ToAll() + end + if soundFile then + --local sound = SOUND:New(soundFile) + --sound:ToAll() + end +end --- Spawn the second escort and attach to AWACS -local escort2 = SPAWN:New(escortGroup2) - :InitLimit(1, 0) - :OnSpawnGroup(function(escortGroup) - -- Attach the second escort to follow AWACS - local awacsEscort2 = ESCORT:New(awacs, escortGroup) - awacsEscort2:Escort() - end) - :Spawn() +-- Define the patrol zone +local patrolZone = ZONE:New("AWACS_PatrolZone") +if patrolZone then + DebugMessage("Patrol zone created: " .. patrolZone:GetName()) +else + DebugMessage("ERROR: Patrol zone 'AWACS_PatrolZone' not found. Check the mission editor.") + return -- Exit if the patrol zone is not defined +end + + + +-- 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)