// Modding API

Build on top of DCO_AI

A published surface for other addons: events to subscribe to, settings to change, AI state to read. Use it instead of modded class on DCO internals — those move between updates, this does not.

Getting started

Everything lives on two classes. DCO_API holds settings and AI state; DCO_Events holds the events. Both are static — there is nothing to place in the world and nothing to register.

  1. Add DCO_AI to your addon's dependencies.GUID 5EDAAE0D3CC60D6B, in the Dependencies block of your addon.gproj.
  2. Subscribe and call from server-side code.A component on your game mode or a mission entity. Events only fire on the server and writes are refused on clients.
  3. Check that DCO is actually running before you lean on it.DCO_API.IsReady() is true once the global component exists.
// addon.gproj
GameProject {
  Dependencies {
    "58D0FB3206B6F859"  // ArmaReforger
    "5EDAAE0D3CC60D6B"  // DCO_AI
  }
}

Versioning

DCO_API.Version() returns an integer: major × 100 + minor, so 100 means 1.0. Within one major version nothing published is removed or renamed, and anything due to go away is marked deprecated for at least one release first.

if (DCO_API.Version() < 100 || !DCO_API.IsReady())
    return;  // too old, or DCO isn't loaded — fall back quietly

What you get

EventsFifteen invokers: contact, stress, morale, squad tasks, kills, objectives, commander mode and stock, operations, spawns, reinforcements, fire missions, victory.
SettingsRead and write at four scopes — global, faction, squad, soldier — using the same key names as the server config.
StateMorale, stress, suppression, cover and ammo per soldier; task, phase, flags, strength, objective and commander per squad.
Checked against v0.4.146. Everything on this page was read out of DCO_API.c and DCO_Events.c in the mod source. If you have seen notes describing commands, locks or modifiers, those are not in the shipped API yet — Version() still returns 100.
Nothing you write is invisible. Every change you make goes into the DCO log and into report.txt under your mod's name, so a server owner can see which addon changed what. That is a feature — it keeps your mod blameless when something else breaks.

Events

Get the event object three ways — they all return the same singleton. Subscribe with Insert, and always Remove when your component goes away.

DCO_Events ev = DCO_API.Events();
// or
DCO_Events ev = DCO_Events.Get();
// or
DCO_Events ev = AICommander_ManagerComponent.GetInstance().GetEvents();

ev.GetOnContact().Insert(OnContact);
// ... later
ev.GetOnContact().Remove(OnContact);

Soldier & squad events

GetterHandler signatureFires when
GetOnContact()(SCR_AIGroup group, IEntity enemy, vector pos)A squad that knew of no enemies now knows of one, seen or heard. It won't fire again until the squad has forgotten every enemy — roughly 150 s without new information.
GetOnStressChanged()(IEntity soldier, int from, int to)Stress moves between 0 calm, 1 suppressed and 2 pinned.
GetOnMoraleChanged()(IEntity soldier, int from, int to)Morale state changes: 0 Calm, 1 Tense, 2 Shaken, 3 Panic, 4 Break.
GetOnSquadTaskChanged()(AIGroup group, DCO_EGroupTask from, DCO_EGroupTask to, string by)A squad is given a new task. by names whoever gave it.
GetOnSoldierKilled()(IEntity victim, IEntity killer, float distance)An AI soldier dies. killer is null when unknown, and distance is then -1.
Keep these handlers short. Stress and morale fire per soldier and can run hot in a large battle. Count, queue or sample — don't do pathfinding or file I/O in there.

Commander & mission events

GetterHandler signatureFires when
GetOnObjectiveOwnerChanged()(CMD_AICommanderObjectiveComponent obj, FactionKey from, FactionKey to)An objective changes hands. An empty key means nobody owns it.
GetOnObjectiveContested()(CMD_AICommanderObjectiveComponent obj, bool contested)Two or more factions now have presence inside the objective, or it drops back to one or none.
GetOnCommanderModeChanged()(AICommander_BaseComponent cmd, CMD_ECommanderMode from, CMD_ECommanderMode to)A commander switches between OFFENSIVE, DEFENSIVE and BALANCED.
GetOnCommanderStockEmpty()(AICommander_BaseComponent cmd, string kind)Reinforcement stock drops from above zero to zero. kind is "soldiers" or "points". Unlimited stock (-1) never fires.
GetOnOperation()(string name, string detail)The planner starts, branches, replans or ends an operation: op_plan, op_phase, op_phase_end, op_branch, op_replan, op_reserve, op_end.
GetOnSpawner()(string name, string detail)spawner_spawn, spawner_off (switched off, e.g. enemies nearby), spawner_stop (stock or points used up).
GetOnReinforcementRequest()(string name, string detail)A commander asks for reinforcements.
GetOnFireMission()(string name, string detail)An artillery or mortar request is queued, with tier, shells, type and position.
GetOnVictory()(string name, string detail)The victory component ends the mission.
GetOnAnyEvent()(string name, string detail)All of the above as text. One subscription to log everything or forward it to Scenario Framework.

detail is the full key=value log line, for example op_end cmd=US_1 primary=OBJ_Town reason=captured. Parse what you need from it.

Two things to know. GetOnAnyEvent() covers this table only — not the soldier and squad events above. And the four polled ones (owner, contested, mode, stock) are checked once a second, so your callback can arrive up to a second late.

Reading AI state

All read-only, all safe to call on anything — a non-DCO entity returns a zero or a null rather than throwing.

Per soldier

CallReturns
SoldierMorale(soldier)Morale state: 0 Calm, 1 Tense, 2 Shaken, 3 Panic, 4 Break. -1 if it isn't a DCO soldier.
SoldierMoraleValue(soldier)Morale pressure as a number — higher is worse.
SoldierStress(soldier)0 calm, 1 suppressed, 2 pinned.
SoldierSuppression(soldier)Suppression, 0 to 1.
SoldierInCover(soldier)True in valid cover or inside a building.
SoldierAmmo(soldier)Rounds left in the current magazine, 0 to 1.

Per squad

CallReturns
SquadTask(group)DCO_EGroupTask: NONE, ATTACK, FLANK, SUPPORT_BY_FIRE, DEFEND, GARRISON, RECON, PATROL, REINFORCE, TRANSPORT, FIRE_MISSION.
SquadPhase(group)DCO_ETaskPhase: MOVING, STAGING, EXECUTING, HOLDING.
SquadState(group)Bit flags: EN_ROUTE 1, IN_CONTACT 2, SUPPRESSED 4, COMBAT_INEFFECTIVE 8, RETREATING 16, MOUNTED 32.
SquadMorale(group)Average morale pressure across the squad.
SquadAlive(group) / SquadPeak(group)Soldiers alive now, and the most it ever had — the pair gives you attrition.
SquadObjective(group)The objective its commander gave it, or null.
SquadCommander(group)Its commander, or null.
if (DCO_API.SquadState(group) & DCO_EGroupState.COMBAT_INEFFECTIVE)
    Print("squad is spent: " + DCO_API.SquadAlive(group) + "/" + DCO_API.SquadPeak(group));

Commanders & objectives

Two list calls fill an array you own and return the count.

array<AICommander_BaseComponent> cmds = {};
int n = DCO_API.Commanders(cmds);

array<CMD_AICommanderObjectiveComponent> objs = {};
int m = DCO_API.Objectives(objs);

From there, ask the objects themselves: a commander answers GetCommanderMode(), GetReinforcementStock(), GetPointsStock() and GetCommanderFactionKey(); an objective answers GetOwnerFaction() and GetLogName().

Changing settings

Writes take your mod's name as the first argument. Reads don't. Everything is clamped to its valid range rather than refused, so you can't put DCO into an impossible state by passing a silly number.

The four scopes

ScopeCallNotes
GlobalGetSetting(key)
SetSetting(mod, key, value)
Affects everything with no faction override.
FactionGetSetting(key, faction)
SetSetting(mod, key, value, faction)
Only works if the server config has a factions block for that faction. Otherwise refused with no_faction_layer.
SquadGetSquadSetting(group, key)
SetSquadSetting(mod, group, key, value)
Key: vehicleExit, where -1 means follow the global value.
SoldierGetSoldierSetting(soldier, key)
SetSoldierSetting(mod, soldier, key, value)
Keys: aiSkill, aimAccuracy, aimSpeed, aiPerception, suppressionEffect, takeCoverChance, personality, leadership.

personality: 0 Cautious, 1 Standard, 2 Aggressive, 3 Reckless. leadership v0.4.146: 0 Poor, 1 Average, 2 Good, 3 Inspiring.

Keys

Two families, both accepted by the same calls. DCO_API.HasSetting(key) tells you whether a key exists before you try.

FamilyCountNames
Main settings8aiAggression, vehicleExit, aiSkillDefault, aimAccuracy, aimSpeed, aiPerception, suppressionEffect, takeCoverChance
Tuning keys544The config name (tune_hear_mask) or the short internal name (hear.mask) — both work. Defaults and ranges are in DCO_GlobalConfig_README.txt beside the server config.
DCO_API.SetSetting("MyMod", "aiAggression", 1.5);
DCO_API.SetSetting("MyMod", "tune_hear_mask", 1.0);
DCO_API.SetSetting("MyMod", "aiPerception", 0.8, "USSR");
DCO_API.SetSquadSetting("MyMod", group, "vehicleExit", 16);
DCO_API.SetSoldierSetting("MyMod", soldier, "aiPerception", 1.5);
DCO_API.SetSoldierSetting("MyMod", soldier, "leadership", 3);  // Inspiring

When changes land

SettingTakes effect
Aggression, perception, tuning keysImmediately, on everyone.
Skill, accuracy, aim, suppression, coverCopied into soldiers at spawn, so only new soldiers pick it up. Use the soldier calls for those already on the map.
Writes can be refused. They return false and log a reason: unknown_key, not_server, mod_name_empty, no_faction_layer, no_dco_squad, no_dco_soldier. Check the return value when it matters — a typo in a key name fails silently otherwise.

Victory conditions

DCO_VictoryComponent ends a mission when a faction meets a condition. Add it to your game mode entity or to any entity in the world — only the server evaluates it, and the first faction to meet a condition wins through the vanilla end-game path.

ConditionDefaultWins when
Hold count0 (off)A faction holds at least this many DCO objectives.
Hold all primaryOffA faction holds every objective marked Primary. Needs at least one.
Hold objectiveEmpty (off)A faction holds one named objective for Hold Minutes without interruption. The timer resets if it changes hands.
Enemy stock emptyOffEvery enemy commander has used up its soldier stock. Unlimited stock never counts.
Typed objectivesOffEvery typed objective has finished; the faction that won the most of them takes it. A tie means no winner.
Grace / check seconds60 s / 5 sNothing is checked before the grace period, then every check interval.

It writes victory_init, victory_check, victory_hold and victory_end to the CMD log channel, and fires GetOnVictory() so your own addon can react before the mission closes.

A complete addon

This is the shape of a working listener: subscribe on game start, unsubscribe on game end, and do everything behind a server check. Two fuller examples ship alongside the mod rather than inside it — DCO_API_Example, which exercises every part of this page, and DCO_API_HudExample, a squad HUD built only on this API. Ask on Discord for the current copies.

class MyListener : Managed
{
    protected const string MOD = "MyMod";

    void Start()
    {
        if (!Replication.IsServer() || !DCO_API.IsReady())
            return;

        DCO_Events ev = DCO_API.Events();
        ev.GetOnContact().Insert(OnContact);
        ev.GetOnSquadTaskChanged().Insert(OnTask);
        ev.GetOnObjectiveOwnerChanged().Insert(OnOwner);

        DCO_API.SetSetting(MOD, "aiAggression", 1.2);
    }

    void Stop()
    {
        DCO_Events ev = DCO_API.Events();
        ev.GetOnContact().Remove(OnContact);
        ev.GetOnSquadTaskChanged().Remove(OnTask);
        ev.GetOnObjectiveOwnerChanged().Remove(OnOwner);
    }

    protected void OnContact(SCR_AIGroup group, IEntity enemy, vector pos)
    {
        PrintFormat("[MyMod] contact task=%1 alive=%2/%3 morale=%4",
            typename.EnumToString(DCO_EGroupTask, DCO_API.SquadTask(group)),
            DCO_API.SquadAlive(group), DCO_API.SquadPeak(group), DCO_API.SquadMorale(group));
    }

    protected void OnTask(AIGroup group, DCO_EGroupTask from, DCO_EGroupTask to, string by)
    {
        // react to the squad being retasked
    }

    protected void OnOwner(CMD_AICommanderObjectiveComponent obj, FactionKey from, FactionKey to)
    {
        Print(obj.GetLogName() + " taken by " + to);
    }
}

modded class SCR_BaseGameMode
{
    protected ref MyListener m_Listener;

    protected override void OnGameStart()
    {
        super.OnGameStart();
        m_Listener = new MyListener();
        m_Listener.Start();
    }

    override void OnGameEnd()
    {
        if (m_Listener)
            m_Listener.Stop();
        super.OnGameEnd();
    }
}
The one modded class that's fine. Modding SCR_BaseGameMode to get a start and end hook is vanilla, not DCO internals — that's exactly what this API is meant to let you stop doing everywhere else.

Troubleshooting

SymptomCheck
Nothing happens at allDCO_API.IsReady() is false until the global component exists, and every write is refused off the server. Subscribe from server-side code after game start.
A write returns falseRead the api_reject line in the log — it names the key and the reason.
Faction write refusedno_faction_layer: that faction has no factions block in the server config, so there is nothing to write to.
Setting changed but AI didn'tSkill, accuracy, aim, suppression and cover are copied at spawn. Existing soldiers need the per-soldier calls.
Key not recognisedTest with HasSetting(). Tuning keys take either tune_hear_mask or hear.mask — but not a typo in either. The reference lists every key that exists.
Contact event fires once and stopsBy design. It fires on the transition from no known enemies to some, and rearms only after the squad forgets them all.
Server is lagging under my handlerStress and morale fire per soldier. Sample or count in the handler and do the real work on a timer.
Everything is marked Dev buildThe API is written but not in the public Workshop release yet — see the roadmap.

Building something with it?

Come say so on Discord. API questions, missing events and breaking changes all get answered there first.