API ReferenceGE Extensionsscenario
Speed Goal
A scenario goal that monitors vehicle speed and triggers win or fail if the vehicle stays outside a speed range for too long. Supports min/max speed, timeout countdown, waypoint-specific checks, and d
A scenario goal that monitors vehicle speed and triggers win or fail if the vehicle stays outside a speed range for too long. Supports min/max speed, timeout countdown, waypoint-specific checks, and delayed activation.
Internal State
| Field | Type | Description |
|---|---|---|
M.instances | varies | Assigned as {} |
Public API (Exports)
| Function | Signature | Description |
|---|---|---|
M.init | (scenario) | Parses and validates speed goals from scenario JSON |
M.processState | (scenario, state, stateData) | Checks speed each race tick |
M.updateFinalStatus | (scenario, instance) | Reports final goal status to statistics |
Goal JSON Schema
{
"goal": {
"speed": {
"minSpeed": 10,
"maxSpeed": 50,
"maxTimeout": 5,
"delay": 3,
"purpose": "fail",
"wayPointNum": [3, 5, 8],
"msg": "scenarios.myScenario.tooSlow"
}
}
}| Field | Type | Default | Description |
|---|---|---|---|
minSpeed | number | optional | Minimum speed (m/s) - triggers timeout if below |
maxSpeed | number | optional | Maximum speed (m/s) - triggers timeout if above |
maxTimeout | number | 0 | Seconds outside range before triggering result |
delay | number | optional | Seconds after race start before checking begins |
purpose | string | "fail" | "fail" or "win" |
wayPointNum | number[] | optional | Only check speed at these waypoint indices |
msg | string | auto | Custom message on trigger |
How It Works
initfilters goals forid == "speed", validates types, defaultspurposeto"fail"- Each
onRaceTick(0.25s interval):- If
delayis set and timer hasn't passed it, skips check - If
wayPointNumis set, only checks at those specific waypoint indices - Reads vehicle velocity from
map.objectsviafobjData.vel:length()
- If
- If speed is outside [minSpeed, maxSpeed] range:
- Increments
instance.Timeoutby tick time - Shows countdown flash messages each second
- Increments
- If speed returns to valid range, resets timeout to 0
- When timeout exceeds
maxTimeout, callsshowMsgwhich:- Sets result to
"failed"or"passed"based onpurpose - Calls
scenario_scenarios.finish()with formatted time string
- Sets result to
Usage Examples
-- In scenario JSON: fail if speed drops below 15 m/s for 5 seconds
{
"vehicles": {
"scenario_player0": {
"goal": {
"speed": {
"minSpeed": 15,
"maxTimeout": 5,
"purpose": "fail"
}
}
}
}
}
-- Check speed only at waypoints 2 and 4:
{
"speed": {
"maxSpeed": 30,
"maxTimeout": 3,
"wayPointNum": [2, 4],
"purpose": "fail"
}
}Key Notes
maxSpeedof 0 is explicitly rejected (logged as error)- Speed is measured in m/s from the map object tracker
- If map tracking is missing, re-enables it via
mapmgr.enableTracking - Countdown messages use
helper.flashUiMessagewith 0.5s duration - The
winpurpose is useful for speed challenge scenarios - Timeout resets completely when speed returns to valid range
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