Police Traffic Role
Reference for the `police` traffic role, which implements pursuit behavior including chasing suspects, managing sirens, avoiding head-on collisions, setting up roadblocks, and coordinating with the po
Reference for the police traffic role, which implements pursuit behavior including chasing suspects, managing sirens, avoiding head-on collisions, setting up roadblocks, and coordinating with the police system.
Role Properties
| Property | Value | Description |
|---|---|---|
class | "emergency" | Vehicle class category |
keepActionOnRefresh | true | Preserves pursuit state through respawn |
drivability | 0.5 | Reduced spawn drivability |
personalityModifiers.aggression | offset +0.1 | Slightly more aggressive |
Actions
| Action | Description |
|---|---|
pursuitStart | Begins pursuit: sets chase/follow mode, siren, and modifies respawn values |
pursuitEnd | Ends pursuit: stops vehicle, starts cooldown timer, resets flags |
chaseTarget | Switches to aggressive chase mode (no lane restriction) |
avoidTarget | Temporarily flees to dodge head-on collision |
roadblock | Stops vehicle in position as a roadblock |
pullOver | Inherited from base - pulls to side of road |
disabled | Inherited from base - permanent stop with hazards |
Key Methods
checkTarget() → id|nil
Scans all traffic vehicles for the best pursuit target (highest pursuit score, non-police).
onRefresh()
Re-evaluates targets on refresh. If a pursuit target exists, restarts pursuit. Checks roadblock distance to avoid re-triggering.
onTrafficTick(dt)
- Updates
validTargetstable with distance, interactive distance, and visibility for each potential target - Tracks police visibility for pursuit score counting
- Manages lane-change behavior during chase (exits lane mode when target is visible)
- Triggers crash avoidance when approaching target head-on at combined speed ≥
avoidSpeed - Auto-disables if vehicle takes critical damage
- Controls traffic signal freezing when lightbar is active
onUpdate(dt, dtSim)
- Manages siren pulse logic (passive mode → intermittent sirens → full sirens if target accelerates)
- Handles cooldown timer after pursuit ends
- Chase state machine: pulls over when near slow target, resumes chase when target moves
- Exits roadblock mode when target evades or drives away
Internals
Pursuit Modes (from target vehicle)
| Mode | Behavior |
|---|---|
| 0 | No pursuit |
| 1 | Passive - follow with intermittent sirens |
| 2+ | Aggressive - full chase with continuous sirens |
State Flow
none → pursuitStart → (chase ↔ follow ↔ flee ↔ pullOver) → pursuitEnd → disabled → (cooldown) → noneCooldown
After a pursuit ends, the police vehicle enters a cooldown period (arrestTime + 5 seconds minimum 10s) during which it won't pursue new targets.
Usage Example
-- Police vehicles are auto-assigned this role based on config type
-- Manual assignment:
local veh = gameplay_traffic.getTrafficData()[vehId]
veh:setRole('police')
-- Start pursuit programmatically
veh.role:setTarget(suspectId)
veh.role:setAction('pursuitStart', {targetId = suspectId})See Also
- gameplay/traffic/roles/empty - Empty Traffic Role - Related reference
- gameplay/traffic/roles/standard - Standard Civilian Traffic Role - Related reference
- gameplay/traffic/roles/suspect - Suspect Traffic Role - Related reference
- Gameplay Systems Guide - Guide
Empty Traffic Role
Reference for the `empty` traffic role, a minimal role that prevents extra actions or AI logic from being applied to a vehicle. Used when a vehicle needs to be in the traffic system but should not hav
Standard Traffic Role
Reference for the `standard` traffic role, the default role for civilian traffic vehicles. Implements reactive behavior to collisions and crashes - pulling over, fleeing, following, exchanging insuran