RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Bus DriverDamage GoalDemolition DerbyDistance GoalDrift GoalFinish Race GoalNo-Move GoalPosition GoalQuick RaceQuick Race LoaderRace MarkersRace DebugRace Goals ManagerRace UIScenario HelperScenario EngineScenarios LoaderSpeed GoalTime Limit GoalWaypoint ActionScenario Waypoints

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsscenario

Scenario Helper

Utility library for scenario scripting. Provides helper functions to queue Lua commands on vehicles, configure AI behavior, flash UI messages, and measure distances between scene objects.

Utility library for scenario scripting. Provides helper functions to queue Lua commands on vehicles, configure AI behavior, flash UI messages, and measure distances between scene objects.


Public API (Exports)

FunctionSignatureDescription
M.queueLuaCommand(vehicle, command)Sends a Lua command string to a vehicle object
M.queueLuaCommandByName(vehicleName, command)Sends command to vehicle found by scenetree name
M.getVehicleByName(name)Returns scenetree.findObject(name)
M.breakBreakGroup(vehicleName, group)Breaks a break group on the vehicle
M.triggerDeformGroup(vehicleName, group)Triggers a deform group (e.g., break a window)
M.trackVehicle(vehicleName, trackingName)Enables map tracking for a vehicle
M.setAiMode(vehicleName, mode, targetVehicleName?)Sets AI mode, optionally with a target vehicle
M.setAiAggression(vehicleName, aggression)Sets AI aggression multiplier
M.setAiAggressionMode(vehicleName, aggrMode)Sets dynamic aggression mode (e.g., "rubberBand")
M.setAiTarget(vehicleName, target)Sets AI pursuit/flee target
M.setAiAvoidCars(vehicleName, value)Enables/disables AI car avoidance ("on"/"off")
M.setAiRoute(vehicleName, waypoints)Sets AI route from waypoint list
M.setAiPath(arg)Full AI path configuration (see below)
M.setCutOffDrivability(vehicleName, drivability)Sets AI road drivability cutoff
M.flashUiMessage(msg, duration, useBiggerText?)Shows a flash message on screen
M.realTimeUiDisplay(msg)Shows a persistent real-time display message
M.getDistanceBetweenSceneObjects(sceneObjectName1, sceneObjectName2)Returns distance between two scene objects (-1 if not found)

setAiPath - Full AI Configuration

scenario_scenariohelper.setAiPath({
  vehicleName = "ai_vehicle1",
  waypoints = {"wp1", "wp2", "wp3", "wp1"},  -- required
  routeSpeed = 15,           -- m/s speed limit
  routeSpeedMode = 'limit',  -- 'limit' or 'set'
  driveInLane = 'on',        -- stay in lane
  lapCount = 3,              -- circuit laps
  aggression = 1.2,          -- aggression multiplier (max 2)
  aggressionMode = 'rubberBand',  -- distance-based aggression
  resetLearning = true,      -- reset traction learning
  avoidCars = 'on',          -- car avoidance
  speeds = {}                -- per-waypoint speeds
})

How It Works

  1. All AI functions serialize Lua commands as strings and send via vehicle:queueLuaCommand()
  2. AI state changes are also forwarded to scenario_scenarios.updateVehicleAiState() for persistence across resets
  3. setAiPath is the most comprehensive function - saves the full configuration to core_checkpoints for vehicle reset restoration
  4. flashUiMessage triggers ScenarioFlashMessage with {{msg, duration, soundCmd, bigText}}

Usage Example

local helper = require('scenario/scenariohelper')

-- Simple AI setup
helper.setAiMode("traffic_car", "span")
helper.setAiAggression("racer1", 1.5)

-- Send custom Lua to a vehicle
helper.queueLuaCommandByName("scenario_player0", "electrics.toggle_left_signal()")

-- Flash a message
helper.flashUiMessage("Get Ready!", 3, true)

-- Measure distance
local dist = helper.getDistanceBetweenSceneObjects("wp_start", "wp_finish")

Key Notes

  • Used extensively by scenarios.lua for AI initialization
  • setAiPath stores args in core_checkpoints so AI paths survive vehicle resets
  • All functions are synchronous (queue commands, don't wait for results)
  • aggressionMode = 'rubberBand' makes AI less aggressive when close to opponent

Additional Exports

  • M.setAiTargetVehicle - (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

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`.

Scenario Engine

The main scenario engine. Manages the entire scenario lifecycle: loading, state transitions, countdown, racing, finishing, multiseat, vehicle processing, waypoint processing, and UI coordination. This

On this page

Public API (Exports)setAiPath - Full AI ConfigurationHow It WorksUsage ExampleKey NotesAdditional ExportsSee Also