AI_Spawn — v1.1

DCS World mission scripts that manage AI raid and patrol spawning based on live player population in the Normandy theatre.


Overview

These Lua scripts monitor active human player counts per coalition. When player numbers drop below configured thresholds, AI reinforcements are automatically spawned:

Landed AI units are automatically destroyed via an engine-shutdown event handler (event.id 19) to keep the mission clean.


Current Mission Scripts

File Notes
ai_spawn_3rdJune.lua Patrol-only (no raids). Uses coalition.getPlayers() count. 2 Red + 2 Blue patrol groups.
ai_spawn_10thJune.lua Raids + patrols. 3 Blue patrol groups (BlueAI_3 added). minPlayersRaid=10.
ai_spawn_18thJune.lua Raids + patrols. minPlayersRaid=15.
ai_spawn_24thJune.lua Raids + patrols. minPlayersRaid=15.
ai_spawn_6thJuly.lua Raids + patrols. minPlayersRaid=15.
ai_spawn_25thJuly.lua Raids + patrols. minPlayersRaid=10.
ai_spawn_8thAugust.lua Raids + patrols. minPlayersRaid=10. Red patrol uses delayed CAP start via timer.scheduleFunction.
ai_spawn_14thAugust.lua Raids + patrols. minPlayersRaid=15.
ai_spawn_template.lua Mission-agnostic template. Copy and edit the CONFIG table for new dates.

Legacy originals moved to old/ (archived for reference only).


Generic Template: ai_spawn_template.lua

ai_spawn_template.lua is a mission-agnostic drop-in replacement. You configure a single CONFIG table at the top of the file instead of editing hardcoded logic throughout the script.

Configuration Sections

Section Purpose
player_count_method "mist" (scan all active units) or "coalition" (use coalition.getPlayers())
update_interval Seconds between player-count refreshes
patrol_spawn_delay Seconds after player count before patrols spawn
raids Red and Blue raid groups (group_name, cooldown, initial_timer, message text)
patrols Red and Blue patrol groups (group, spawn_zone, patrol_zone, altitude, speed, engage_range)
template_groups List of ME template group names to destroy at mission start

Example snippet

CONFIG.raids = {
  red = {
    enabled       = true,
    min_players   = 15,
    group_name    = "1./JG26 AI 1",
    cooldown      = 3600,
    initial_timer = 1600,
    message = {
      coalition = 1,
      text      = "All callsigns, this is Brutus. JaBos from JG26...",
      duration  = 60,
    },
  },
  blue = {
    enabled       = true,
    min_players   = 15,
    group_name    = "313rd FS AI 1",
    cooldown      = 3600,
    initial_timer = 1000,
    message = {
      coalition = 2,
      text      = "All callsigns, this is Kenway. Jugs from 313th FS...",
      duration  = 60,
    },
  },
}

Patrol Groups

Each patrol entry requires matching group, spawn_zone, and patrol_zone names in the Mission Editor:

CONFIG.patrols = {
  red = {
    {
      group        = "RedAI_1",
      spawn_zone   = "Red_Spawn_1",
      patrol_zone  = "Red_Patrol_Zone_1",
      min_alt      = 1000,
      max_alt      = 3000,
      speed        = 400,
      engage_range = 10000,
    },
  },
  blue = {
    {
      group        = "BlueAI_1",
      spawn_zone   = "Blue_Spawn_1",
      patrol_zone  = "Blue_Patrol_Zone_1",
      min_alt      = 1000,
      max_alt      = 3000,
      speed        = 400,
      engage_range = 10000,
    },
  },
  max_players = 7,
}

Key Differences from Original Mission-Embedded Scripts

  1. Templated structure — All hardcoded values (group names, timers, messages) moved to CONFIG.
  2. Unified enginebuildPlayersTable, checkRaid, spawnPatrol, and startCAP are shared and not duplicated per mission.
  3. Defensive coding — Nil guards on event.initiator, Group.getByName, and chained method calls.
  4. Engine shutdown cleanup — Preserved from originals; destroys AI units that land.
  5. 3rd June exception — Uses simplified coalition.getPlayers() count and mist.scheduleFunction loop for patrol-only operation (no raids).

Changelog

Version Changes
1.0 Initial extraction — Extracted 8 mission-embedded AI spawn scripts from .miz files, created generic ai_spawn_template.lua, templated all mission variants, archived originals to old/.
1.1 Current

Dependencies