API ReferenceGE Extensionsscenario
Scenario Waypoints
M.dependencies = {'scenario_scenarios'}
Dependencies
M.dependencies = {'scenario_scenarios'}The core waypoint tracking system for scenario races. Manages waypoint progression, branching paths, lap counting, vehicle trigger detection via wheel-corner intersection, and marker mode updates.
Public API (Exports)
| Function | Signature | Description |
|---|---|---|
M.initialise | () | Sets up waypoints, builds successor graph, initializes vehicles |
M.getVehicleWaypointData | (vehicleId) | Returns deep copy of vehicle's waypoint progress |
M.onScenarioChange | (scenario) | Clears state when scenario is nil |
M.onScenarioRestarted | (scenario) | Re-initializes branching and successor graph |
M.onScenarioVehicleTrigger | (vid, wpData, dtOff) | Processes vehicle waypoint triggers, updates race progress and UI |
M.onVehicleAIStateChanged | (data) | Initializes waypoint tracking for newly AI-controlled vehicles |
M.onPreRender | (dtReal, dtSim, dtRaw) | Per-frame: checks wheel-corner intersections with waypoints |
M.activateWaypointBranch | (branchName, vehicleId, dtOff) | Inserts branch waypoints into vehicle's config |
M.deactivateWaypointBranch | (branchName) | Removes branch waypoints (currently disabled) |
M.updateResetVehicleData | (vehicleId, curWpIndex, nextWpIndex) | Resets vehicle to specific waypoint indices |
M.isFinalWaypoint | (vehicleId, waypointName) | Checks if waypoint is the final one |
M.onSerialize | () | - |
M.onDeserialized | (data) | - |
M.onClientEndMission | () | - |
State Structure
M.state = {
vehicleWaypointsData = {}, -- vid → {cur, next, lap, waypointConfig, nextWps, wheelOffsets, ...}
nextWpForVehicle = {}, -- vid → next waypoint index
waypointBranches = {}, -- branchName → list of waypoint names
branchGraph = {}, -- branchName → {index → {cpName, successors, isFinalWaypoint, ...}}
pathnodes = {}, -- wpName → pathnode object (for intersection tests)
}How It Works
Initialization
- Builds a successor graph from
BranchLapConfigandlapConfigBranches - Each node in the graph stores its successors, branch info, and whether it's a final waypoint
- Creates
pathnodeobjects for each waypoint (used for intersection detection) - Calls
race_marker.setupMarkers()with all waypoint positions - Initializes per-vehicle tracking data with wheel offsets for corner-based detection
Waypoint Detection (onPreRender)
- Each frame, updates vehicle wheel corner positions using rotation and offset
- For each vehicle, checks if any wheel corner line segment (previous→current) intersects a target waypoint's pathnode
- Intersection uses the pathnode's
intersectCornersmethod with time interpolation - On hit, triggers
onScenarioVehicleTriggerwhich advances waypoint progress
Waypoint Progression
processWaypoint(vid)advancescur/nextindices- Determines marker modes:
default,next,branch,lap,final - Handles branching: when a waypoint has multiple successors, shows
branchmode (yellow) - Handles laps: detects lap completion, fires
onRaceLaphook - When final waypoint reached on final lap, calls
scenario_scenarios.endRace()
Branching
BranchLapConfigcan contain arrays (branch choices) instead of stringsactivateWaypointBranchinserts a branch's waypoints into the vehicle's config at the current position- Successor graph pre-computes all possible paths through branches
Marker Mode Assignment
| Mode | When |
|---|---|
default | Normal next checkpoint |
next | Checkpoint after the next one (preview) |
branch | Next checkpoint has multiple successors |
lap | Final checkpoint of a non-final lap |
final | Final checkpoint of the final lap |
start | Rolling start checkpoint |
| M.addWaypointBranch | varies | Assigned as addWaypointBranch |
| M.onUpdate | varies | Assigned as onUpdate |
Usage Example
-- Waypoints are initialized automatically by scenarios.lua during pre-running state
-- Get current progress for a vehicle:
local wpData = scenario_waypoints.getVehicleWaypointData(vehicleId)
if wpData then
print("Current waypoint:", wpData.cur, "Lap:", wpData.lap)
end
-- Reset a vehicle to a specific waypoint:
scenario_waypoints.updateResetVehicleData(vehicleId, 3, 4)Key Notes
- Uses wheel corner positions (not vehicle center) for precise checkpoint detection
- Time interpolation (
tNorm) provides sub-frame accuracy for timing - Branching is stored per-vehicle - different vehicles can take different branches
disableWaypointTimesis auto-set when branches exist (comparisons become invalid)- Rolling start uses a special initial state with
cur = -2, next = -1 - The successor graph handles circular paths (last WP → first WP) for lap races
- Serialization converts vehicle ID keys to name keys for save/load
Additional Exports
M.onDrawDebug- (undocumented)
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
Waypoint Action
A scenario goal that displays flash messages when the player reaches specific waypoints. Unlike other goals, this is purely informational - it doesn't trigger win or fail conditions.
Attention Marker
A race checkpoint marker that displays a single floating arrow ribbon. Designed for walking/on-foot scenarios with a bobbing animation and height offset when the player is nearby.