RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Gameplay AchievementGameplay CityDiscoverForce FieldGarage ModeMarker InteractionParking SystemGameplay Playmode MarkersGameplay PoliceGameplay RallyGameplay Rally LoopGameplay Raw POIsGameplay Skidpad TestSpeed Trap LeaderboardsSpeed Traps and CamerasGameplay StatisticsTaxi Ride SystemTraffic SystemVehicle PerformanceWalking
Base Traffic RoleTraffic UtilitiesTraffic Vehicle

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 Extensionsgameplaytraffic

Base Traffic Role

Reference for `gameplay_traffic_baseRole`, the base class for all traffic vehicle driver roles. Provides personality generation, action management, flowgraph support, and common utility methods inheri

Reference for gameplay_traffic_baseRole, the base class for all traffic vehicle driver roles. Provides personality generation, action management, flowgraph support, and common utility methods inherited by concrete roles (standard, police, suspect, empty).


Constructor

local role = require('/lua/ge/extensions/gameplay/traffic/baseRole')(derivedClass, initData)

Creates a role instance by merging derivedClass methods over the base class, then calling init() and postInit().


Base Class Methods (C)

Initialization

MethodDescription
init(veh, name, data)Sets up role state, actions, personality, and flags
postInit()Resets action and applies generated personality

Actions

MethodDescription
setAction(name, args)Executes a named action function and fires onTrafficAction hook
resetAction()Restores default AI mode, clears flags and target

Personality

MethodDescription
generatePersonality() → tableReturns random personality (aggression, patience, bravery)
applyPersonality(data)Sets personality values and adjusts AI aggression
setAggression(base?, ignorePers?)Computes and sends aggression to AI

Target & Flowgraph

MethodDescription
setTarget(id)Sets the AI chase/follow target vehicle
setupFlowgraph(fgFile, varData)Loads and runs a custom flowgraph for this vehicle
clearFlowgraph()Stops the flowgraph and restores default behavior
checkTargetVisible(id?) → boolStatic raycast visibility check to target

Traffic Signals

MethodDescription
freezeTrafficSignals(state)Freezes/unfreezes all red traffic lights (for emergency vehicles)

Lifecycle Callbacks

MethodDescription
onRefresh()Called when vehicle data is refreshed
onRoleStarted() / onRoleEnded()Role transition hooks
onCrashDamage(data) / onOtherCrashDamage(otherId, data)Crash notification
onCollision(otherId, data) / onOtherCollision(id1, id2, data)Collision notification
onTrafficTick(tickTime)Called every 0.25s tick
onUpdate(dt, dtSim)Called every frame
onSerialize() / onDeserialized(data)State persistence
tryRandomEvent()Override point for random behavior

Internals

Base Actions

All roles inherit these base actions:

ActionDescription
pullOverLane change to the side, then stop. Optionally uses warning signal
disabledPermanent stop with hazard lights, lightbar off

Personality System

Each personality trait is a value from 0 to 1:

  • aggression: Affects AI driving aggression (±0.1 modifier)
  • patience: Affects wait times and response durations
  • bravery: Affects fight-or-flight decisions after collisions

Personality modifiers per role can set offset, min, max, and isLinear (uniform vs gaussian distribution).

Key Flags

FlagDescription
lockActionPrevents action changes (used by flowgraphs)
keepActionOnRefreshPreserves action through vehicle refresh
keepPersonalityOnRefreshPreserves personality through refresh
ignorePersonalityForces neutral personality values

Usage Example

-- Derived role pattern (see roles/standard.lua)
local C = {}
function C:init()
  self.actions = { myAction = function(args) ... end }
  for k, v in pairs(self.baseActions) do self.actions[k] = v end
  self.baseActions = nil
end
return function(...) return require('/lua/ge/extensions/gameplay/traffic/baseRole')(C, ...) end

See Also

  • gameplay/traffic/trafficUtils - Traffic Utility Functions - Related reference
  • gameplay/traffic/vehicle - Traffic Vehicle Object - Related reference
  • Gameplay Systems Guide - Guide

Rollover Detection

Reference for `gameplay_statisticModules_watchRollover`, a statistic submodule that detects vehicle rollovers (flipping upside-down and back upright).

Traffic Utilities

Reference for `gameplay_traffic_trafficUtils`, a collection of utility functions used by the traffic system for spawn point finding, vehicle group creation, road validation, and role loading.

On this page

ConstructorBase Class Methods (C)InitializationActionsPersonalityTarget & FlowgraphTraffic SignalsLifecycle CallbacksInternalsBase ActionsPersonality SystemKey FlagsUsage ExampleSee Also