MISSION SCRIPTING

Quick reference

A whole script

local missions = require("missions")
local mission = require(missions.MY_SCENARIO)

return {
    initial_state = mission.states.STATE_X,
    on_start = function(context, state) end,
    on_load = function(context, state) end,
    on_event_region_changed = function(context, state, event) end,
    on_event_player_trigger = function(context, state, event) end,
    on_event_squad_state = function(context, state, event) end,
    on_event_timer_elapsed = function(context, state, event) end,
    on_event_effect_result = function(context, state, event) end,
}

Every entry is optional. See How a script runs.

The calls you need most

tocall
remember a valuecontext:set_variable(name, value) / state:variable(name)
remember across launchescontext:set_flag(name, value) / context:get_flag(name)
waitcontext:start_timer(name, ms)
roll a random numbercontext:random()
spawn enemiescontext:squad(Squad.X):place{}
spawn placed objectscontext:activate_objects{slots = {Slot.O_X, Slot.O_Y}, active = true}
open a doorcontext:slot(Slot.D_X):transition{transition = context.sdk.device_transitions.open}
show a goalcontext:slot(Slot.M_DIRECTIVE_SENSOR_X):set_directive{directive = mission.Directive.X}
show a goal counterthe same, with progress = {current, maximum} on a directive with counter = true
play a linecontext:slot(Slot.M_DIALOG_SENSOR_X):play_dialogue_cue{cue = n}
watch a triggercontext:slot(Slot.PT_X):fire_trigger() then on_event_player_trigger
count who is in an areacontext:slot(Slot.PM_X):set_occupancy_condition{value = 1} then on_event_trigger_entered and on_event_trigger_exited
check a clearcontext:cohort{squads = {...}}.cleared
change areacontext:select_state(mission.states.STATE_X)
move the partycontext:teleport{region = n, spawn_set_hash = h}
start a scenecontext:scene(Scene.X):activate{}
fire a scene inputcontext:scene(Scene.X):send_event{key = mission.SceneInput.X.NAME}
wait for a scene outputon_event_scene_output, compare event.key with mission.SceneOutput.X.NAME
finishcontext:complete_mission{}

The full list is in the Lua API reference. For worked examples, see Recipes.

Where things are

Paths are inside your game install.

thingplace
your scriptsbin/x64/Sunrise/scripts/<name>/<name>.lua
a mod’s scriptsbin/x64/Sunrise/mods/<mod>/scripts/<name>/<name>.lua; they replace the base script
shared helpersbin/x64/Sunrise/scripts/lib/
generated SDKbin/x64/Sunrise/sdk/lua/
logbin/x64/Sunrise/logs/sunrise.log
settingsbin/x64/Sunrise/settings.json
in-game toolspress Insert