Attack on TeufortDocs

Build on AOT

Plugin API

aot.inc, the natives and forwards other SourceMod plugins use to work with AOT.

Other plugins talk to AOT through addons/sourcemod/scripting/include/aot.inc. AOT registers the shared library aot.

Include it

To use AOT only when it is loaded, include it as optional and check the library before you call a native:

my_plugin.sp
#include <sourcemod>

#undef REQUIRE_PLUGIN
#include <aot>

public void OnMapStart()
{
    if (LibraryExists("aot") && AOT_IsActive())
    {
        char mission[AOT_MAX_MISSION];
        AOT_GetMission(mission, sizeof(mission));
        LogMessage("This map runs AOT mission %s", mission);
    }
}

Without the #undef REQUIRE_PLUGIN, your plugin does not load unless aot.smx is loaded.

Words

  • AOT map: a map that is not an mvm_ map, with aot_enabled 1, that has a mission: the first one its map file lists, the aot_popfile override, or one a plugin names in AOT_OnPlanMission.
  • Map file: configs/aot/maps/<map>.ini, the missions a map can run, its hand-placed robot spawns and the entities to take off it. See Add a map.
  • Mission: the name a mission is known by, usually <map>_<template>. See Missions.

Natives

NativeWhat it does
bool AOT_IsActive()The current map runs as AOT. True from the moment the map loads, before the mission file itself is loaded.
bool AOT_IsAotMap(const char[] map)A map would run as AOT with the current settings. Missions only a plugin names are not counted.
bool AOT_GetMission(char[] buffer, int maxlen)The current map's mission name. False, with an empty buffer, on a map that is not AOT.
bool AOT_LoadMission(const char[] popfile)Switch the current AOT map to another mission. AOT checks the files, adds the spawn points, then loads it. False when the name is unsafe or a file is missing; the running mission stays.
int AOT_GetMapMissionCount(const char[] map)How many missions a map's file lists. The map does not have to be the current one, so a vote or a rotation can be built before it loads.
bool AOT_GetMapMission(const char[] map, int index, char[] buffer, int maxlen)One of those missions, in the file's order. Index 0 is the mission the map starts with.
AOT_Mode AOT_GetMode()The mode in play: AOT_Mode_Defend or AOT_Mode_Mixed.
void AOT_SetMode(AOT_Mode mode)Ask for a mode. Applied now between waves, otherwise when the running wave ends.
bool AOT_IsBluHuman(int client)A human (not a bot) playing on BLU.
bool AOT_IsMissionBot(int client)A bot the mission spawned, on either team.

Forwards

ForwardWhen it fires
void AOT_OnMapEdit(const char[] map)While an AOT map loads, after AOT took off the entities its map file names and before it places the robot spawns. The map's entity list is open: edit it with SourceMod's EntityLump, or add spawns with AOT_AddSpawnPoint.
Action AOT_OnPlanMission(const char[] map, char[] popfile, int maxlen)While a map loads, before its entities exist. Set popfile and return Plugin_Changed to name a mission you will switch to later, so its spawn points come with the map. A map with no mission of its own runs the one you name.
void AOT_OnMissionLoaded(const char[] map, const char[] popfile)After AOT loaded a mission: at map start and on every AOT_LoadMission.
Action AOT_OnRobotMarker()About once a second during a wave, on maps with no flag. Return Plugin_Handled to lead the robots your own way; AOT then removes its marker.
void AOT_OnModeChanged(AOT_Mode oldMode, AOT_Mode newMode)When the mode in play changes.
void AOT_OnTrace(const char[] kind, const char[] detail)One line for automated tests at each moment a test checks. Only fired while a plugin listens.

Example: plan a mission for any map

This plugin runs a shared template on every map that has no mission of its own:

aot_any_map.sp
#include <sourcemod>
#include <aot>

public Action AOT_OnPlanMission(const char[] map, char[] popfile, int maxlen)
{
    if (AOT_IsAotMap(map))
    {
        return Plugin_Continue;   // its map file already lists one
    }
    Format(popfile, maxlen, "%s_adv_wormhole_wreck", map);
    return Plugin_Changed;
}

Example: place spawns from a plugin

AOT_AddSpawnPoint(name, origin, yaw) adds a robot spawn point to the map that is loading. It only works inside AOT_OnMapEdit, because SourceMod opens the entity list only then.

aot_my_spawns.sp
#include <sourcemod>
#include <aot>

public void AOT_OnMapEdit(const char[] map)
{
    if (StrEqual(map, "cp_gorge"))
    {
        float origin[3] = { -1227.54, 2196.81, -350.97 };
        AOT_AddSpawnPoint("spawnbot", origin, 90.0);
    }
}

A spawnbot point added here counts as the map's own: AOT then leaves out the spawnbot points of the map file and BLU's spawn rooms.

A full example

addons/sourcemod/scripting/examples/aot_missions_menu.sp in the repo is a small plugin built on this API: a menu of the missions the current map can run, which an admin can switch between. It ships as source with every release.

Mission file helpers

aot_popfiles.inc (included by aot.inc) has AOT's own mission file checks as stocks, for plugins that switch missions themselves (on mvm_ maps too, with or without aot.smx):

StockWhat it does
AOT_IsSafePopfileThe name is safe to hand to tf_mvm_popfile: letters, digits, _ and - only.
AOT_FormatPopfilePathThe file's path: scripts/population/<popfile>.pop.
AOT_GetPopfileLoadNameThe file a mission loads: its own, or the shared template.
AOT_ReadPopfileBaseReads the file a #base line names.
AOT_ArePopfileBasesPresentThe file and every #base file exist. Templates inside the game's own files (robot_standard.pop, robot_giant.pop) count. Each missing file goes to the error log.
AOT_CollectSpawnNamesThe spawn names a mission uses.
AOT_POPFILE_BASE_DEPTHHow deep AOT follows #base (4).

Last updated on

On this page