API ReferenceGE Extensionsscenario
Demolition Derby
A simple demolition derby scenario mode where the last vehicle still moving wins. Tracks all scenario vehicles and declares a winner when only one remains in motion.
A simple demolition derby scenario mode where the last vehicle still moving wins. Tracks all scenario vehicles and declares a winner when only one remains in motion.
Public API
| Function | Signature | Description |
|---|---|---|
M.onScenarioChange | (sc) | Initializes vehicle tracking when scenario enters "running" state |
M.onPreRender | (dt) | Checks vehicle movement each second; declares winner |
Internals
- Tick interval: Checks once per second (accumulates
dtuntil ≥ 1) - Movement threshold: Vehicle must move > 1 unit between ticks to count as "moving"
- Stop ticks: After 15 consecutive stopped ticks, a vehicle is considered out
- Win condition: Exactly 1 vehicle moving while all others are stopped
How It Works
onScenarioChangedetects when a scenario enters"running"state- Iterates all scenario vehicles, stores references and initial positions
onPreRenderruns every second:- For each vehicle, checks distance from last known position
- Moving vehicles (>1 unit) reset their stop counter
- Stationary vehicles increment stop counter
- Vehicles with >15 stop ticks are considered "stopped"
- If exactly 1 vehicle is moving and all others are stopped, that vehicle wins
- Calls
scenario_scenarios.finish({msg = winnerName..' WINS!!!'})"
Usage Examples
-- Demolition derby is activated by including it in scenario modules
-- The scenario JSON should define multiple vehicles:
{
"vehicles": {
"scenario_player0": { "driver": {"player": true} },
"ai_vehicle_1": { "driver": {"AI": true} },
"ai_vehicle_2": { "driver": {"AI": true} }
}
}Key Notes
- Simple position-based movement detection (not velocity-based)
- No damage tracking - purely based on whether vehicles are still moving
- The 15-second stop timeout prevents false positives from brief stops
- All vehicle tracking resets when scenario state changes
- Works with any number of vehicles (2+)
See Also
- Scenario Bus Driver - Bus Route Scenario Logic - Related reference
- Scenario Damage Goal - Damage-Based Win/Fail Condition - Related reference
- Scenario Distance Goal - Distance-Based Win/Fail Condition - Related reference
- Scenario System Guide - Guide
Damage Goal
A scenario goal that monitors vehicle damage and triggers win or fail when damage exceeds a configurable limit. Supports threshold-based progress notifications.
Distance Goal
A scenario goal that monitors the distance between two vehicles and triggers win or fail when distance thresholds are exceeded.