Mission Manager
Reference for `gameplay_missions_missionManager`, the central orchestrator for starting and stopping missions with multi-step task pipelines.
Reference for gameplay_missions_missionManager, the central orchestrator for starting and stopping missions with multi-step task pipelines.
Module Exports (M)
| Function | Signature | Description |
|---|---|---|
start / startWithFade | (mission, userSettings, startingOptions) | Start mission with fade-to-black loading screen |
startAsScenario | (mission, userSettings) | Start without fade (scenario-style) |
startFromWithinMission | (mission, userSettings, instant) | Transition from one mission to another |
startInstant | (mission, userSettings, startingOptions) | Start immediately without fade or stashing |
startWithLoadingLevel | (mission, userSettings, level) | Load a level first, then start |
stop | (mission, data) | Stop mission (with optional fade) |
attemptAbandonMissionWithFade | (mission, force, abandonButtonPressed) | Abandon with fade and cleanup |
getForegroundMissionId | () → string|nil | Returns the currently active foreground mission ID |
getCurrentTaskdataTypeOrNil | () → string|nil | Returns "start" or "stop" if a task is active |
stopForegroundMissionInstantly | () | Emergency stop without cleanup pipeline |
fadeDuration | 0.75 | Duration of fade transitions |
allowMissionInteraction | () → bool | Returns false if game state is not freeroam |
Hooks / Lifecycle
| Function | Description |
|---|---|
onUpdate | Main loop: processes task pipeline steps, runs ongoing missions |
onTrafficStarted | Completes traffic spawn step in task pipeline |
onParkingVehiclesActivated | Completes traffic step when only parking spawns |
onScreenFadeState | Handles fade screen state transitions for task pipeline |
onClientEndMission | Alias for stopForegroundMissionInstantly (level unload) |
onCareerActive | Alias for stopForegroundMissionInstantly |
Task Pipeline Architecture
The manager uses a step-based task pipeline (taskData) that processes sequentially each frame:
Start Pipeline (startWithFade)
- taskStartFadeStep - Fade screen to black (timeout: 10s)
- taskStartRemoveVehicles - Delete all vehicles (if
removeAllVehiclesBeforeMission) - taskStartPreMissionHandling - Process user settings, save starting info, freeze traffic, prepare vehicle stash, load custom script
- taskStartVehicleStep - Spawn or select player vehicle, set differentials
- taskStartStartingOptionRepairStep - Handle repair costs in career mode
- taskStartTakePartConditionSnapshot - Snapshot vehicle part conditions
- taskStartTrafficStep - Spawn or activate traffic/parking
- taskStartMissionStep - Call
mission:onStart(), set environment, stash vehicles
Stop Pipeline
- taskStopMissionStep - Call
mission:onStop(), restore environment/traffic/vehicles/camera - taskStartRemoveVehicles - Delete vehicles if needed
- taskStopRespawnVehicleStep - Respawn default vehicle
- taskStopRespawnTrafficStep - Restore traffic
- taskStopFadeStep - Fade back in, reset game state to freeroam
Internals
Vehicle Stashing
Before a mission, all existing vehicles are "stashed" (deactivated). After the mission, they are "unstashed" (reactivated and unfrozen).
Traffic Management
- Freezes current traffic state before mission
- Spawns new traffic per mission's
setupModules.trafficconfiguration - Restores previous traffic state on stop
Environment Setup
- Saves and restores time-of-day, fog density
- Applies mission-specific time, time scale, fog, and wind settings
Foreground Exclusivity
Only one non-background mission runs at a time, tracked by foregroundMissionId.
How It Works
-- Each frame, onUpdate processes the active task pipeline:
local function onUpdate(dtReal, dtSim, dtRaw)
if taskData.active then
local step = taskData.steps[taskData.currentStep]
while step do
step.processTask(step, taskData)
-- Timeout enforcement (default 120s)
if step.complete then
taskData.currentStep = taskData.currentStep + 1
step = taskData.steps[taskData.currentStep]
else
step = nil -- wait for next frame
end
end
end
-- Run ongoing mission updates
if foregroundMissionId then
for _, mission in ipairs(gameplay_missions_missions.get()) do
if mission._isOngoing then
mission:onUpdate(dtReal, dtSim, dtRaw)
end
end
end
endHooks Fired
| Hook | When |
|---|---|
onMissionStartWithFade | Start pipeline begins |
onAnyMissionChanged("started", ...) | Mission successfully started |
onAnyMissionWillChange("stopped", ...) | Before mission stop |
onAnyMissionChanged("stopped", ...) | After mission fully stopped |
onMissionAbandoned | When abandon pipeline begins |
onMissionReconfigured | When restarting same mission with new settings |
onMissionStopped | When stop pipeline begins |
M.allowMissionInteraction | () |
M.attemptAbandonMissionWithFade | (mission, force, abandonButtonPressed) |
M.dependencies | value |
M.fadeDuration | value |
M.getCurrentTaskdataTypeOrNil | () |
M.getForegroundMissionId | () |
M.onCareerActive | () |
M.onClientEndMission | value |
M.onParkingVehiclesActivated | value |
M.onScreenFadeState | (state) |
M.onTrafficStarted | () |
M.onUpdate | (dtReal, dtSim, dtRaw) |
M.start | (mission, userSettings, startingOptions) |
M.startAsScenario | (mission, userSettings) |
M.startFromWithinMission | (mission, userSettings, instant) |
M.startInstant | (mission, userSettings, startingOptions) |
M.startWithFade | (mission, userSettings, startingOptions) |
M.startWithLoadingLevel | (mission, userSettings, level) |
M.stop | (mission, data) |
M.stopForegroundMissionInstantly | () |
See Also
- missions/locationsDetector - Nearby Mission Location Detection - Related reference
- missions/missionScreen - Mission UI Screen & Starting Options - Related reference
- missions/missions - Mission Registry & Data Management - Related reference
- Gameplay Systems Guide - Guide
Locations Detector
Reference for `gameplay_missions_locationsDetector`, which detects missions near the player by checking clustered POI locations.
Missions
Reference for `gameplay_missions_missions`, the central registry that loads, constructs, caches, and serves all missions in the game. This is the primary entry point for accessing mission objects.