Race Goals Manager
Central manager that initializes, validates, and dispatches race goal events to individual goal modules. Acts as the bridge between the scenario system and goal implementations.
Central manager that initializes, validates, and dispatches race goal events to individual goal modules. Acts as the bridge between the scenario system and goal implementations.
Internal State
| Field | Type | Description |
|---|---|---|
M.onRaceEnd | varies | Assigned as onRaceEnd |
Public API
| Function | Signature | Description |
|---|---|---|
M.initialiseGoals | () | Parses vehicle goals from scenario JSON, loads goal modules |
M.onRaceStart | () | Dispatches onRaceStart to all goals |
M.onRaceInit | () | Dispatches onRaceInit to all goals |
M.onRaceWaypointReached | (data) | Dispatches waypoint event to all goals |
M.onRaceTick | (raceTickTime, scenarioTimer) | Dispatches tick to all goals |
M.onRaceResult | (status) | Dispatches race result to all goals |
M.onCountdownEnded | () | Dispatches countdown end to all goals |
M.updateGoalsFinalStatus | () | Calls updateFinalStatus on all loaded goals |
M.state | - (table field) | Shared state table: {goals = {}} - populated by initialiseGoals |
Goal Schema
Defines expected types for each goal's JSON fields:
| Goal ID | Fields |
|---|---|
timeLimit | msg, maxTime, countdown, waitTime |
nomove | msg, triggerEndOnly |
position | msg, purpose, endPoint |
damage | msg, purpose, damageLimit, damageThreshold |
distance | msg, purpose, maxDistance, minDistance, distanceEnable, target |
speed | msg, purpose, maxSpeed, minSpeed, maxTimeout, wayPointNum, delay |
drift | msg, failMsg, minDrift, maxDrift, timeAllowance |
finishRace | passed, failed, mustWin |
wayPointAction | wayPointNum, wayPointMsg |
Goal Loading
Goals are loaded as Lua modules with these search paths:
scenario/<goalName>.luascenario/<goalName>goal.lua
Each goal module must implement:
init(scenario)- Parse and validate goal instancesprocessState(scenario, state, stateData)- Handle eventsupdateFinalStatus(scenario)- Report final results
How It Works
initialiseGoalsiterates all scenario vehicles- For each vehicle with goals defined, creates goal instances with:
vehicleName,vId,id,value,status,startPos
- Validates goal fields against
goalSchema - Loads goal modules via
require()and callsinit()on each - Event hooks (
onRaceTick,onRaceResult, etc.) dispatch to all loaded goals
Goal Instance Structure
{
vehicleName = "scenario_player0",
vId = 12345, -- vehicle object ID
id = "damage", -- goal type name
value = { damageLimit = 500, purpose = "fail" },
status = {}, -- result tracking
startPos = vec3(...) -- vehicle position at init
}Usage Examples
-- Goals are defined in scenario JSON under vehicles:
{
"vehicles": {
"scenario_player0": {
"goal": {
"damage": {"damageLimit": 500},
"finishRace": {"mustWin": true}
}
},
"*": {
"goal": {
"finishRace": {}
}
}
}
}
-- The "*" wildcard applies goals to all vehicles without explicit goalsKey Notes
- Wildcard
"*"vehicle goals apply to vehicles without explicit goal definitions - Schema validation logs errors but doesn't prevent goal loading
- Supports
localizedStringtype (either a string or{txt: "...", context: {...}}) - Goals can be arrays (unnamed) or objects (keyed by goal ID)
- Fires
onRaceGoalsInitilisedhook after all goals are loaded
See Also
- Scenario Bus Driver - Bus Route Scenario Logic - Related reference
- Scenario Damage Goal - Damage-Based Win/Fail Condition - Related reference
- Scenario Demolition Derby - Last Vehicle Moving Wins - Related reference
- Scenario System Guide - Guide
Race Debug
Provides debug visualization for race waypoints and paths. Draws waypoint spheres and route prisms in the 3D world when editor mode and debug setting are enabled.
Race UI
Manages the in-game HUD for race scenarios - tracks waypoint progress, lap changes, and checkpoint time comparisons. Sends data to the UI via `guihooks.trigger`.