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
| Method | Description |
|---|---|
init(veh, name, data) | Sets up role state, actions, personality, and flags |
postInit() | Resets action and applies generated personality |
Actions
| Method | Description |
|---|---|
setAction(name, args) | Executes a named action function and fires onTrafficAction hook |
resetAction() | Restores default AI mode, clears flags and target |
Personality
| Method | Description |
|---|---|
generatePersonality() → table | Returns 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
| Method | Description |
|---|---|
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?) → bool | Static raycast visibility check to target |
Traffic Signals
| Method | Description |
|---|---|
freezeTrafficSignals(state) | Freezes/unfreezes all red traffic lights (for emergency vehicles) |
Lifecycle Callbacks
| Method | Description |
|---|---|
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:
| Action | Description |
|---|---|
pullOver | Lane change to the side, then stop. Optionally uses warning signal |
disabled | Permanent 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
| Flag | Description |
|---|---|
lockAction | Prevents action changes (used by flowgraphs) |
keepActionOnRefresh | Preserves action through vehicle refresh |
keepPersonalityOnRefresh | Preserves personality through refresh |
ignorePersonality | Forces 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, ...) endSee 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.