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
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 insurance, and honking.
Actions
| Action | Description |
|---|---|
fleePostCrash | Flees from crash scene (high aggression, no lane restriction) |
followPostCrash | Follows/chases the responsible vehicle |
askInsurance | Stops to exchange insurance info |
disabled | Permanent stop (critical damage) |
pullOver | Inherited - pulls to side of road |
Key Methods
onRefresh()
Resets targeting, generates driver personality profile:
- Brave drivers (bravery ≥ 0.55) →
followPostCrashafter collisions - Timid drivers (bravery ≤ 0.45) →
fleePostCrashafter collisions - Neutral drivers → just stop
Sets thresholds for minimum damage and collision count to trigger reactions.
onCollision(otherId, data)
Handles direct collision with another vehicle:
- Assigns fault if self is speeding (≥ 120% of speed limit)
- Sets event type to
"selfCollision", targets the other vehicle - Brave drivers may honk horn after delay
onOtherCollision(id1, id2, data)
Witnesses a collision between two other vehicles:
- Targets the slower vehicle
- Checks visibility, distance (within 60m interactive), and direction (must be ahead)
- Brave drivers may honk horn
onCrashDamage(data) / onOtherCrashDamage(otherId, data)
Handles non-collision crash damage (e.g., hitting a wall):
- Only processes if not already in a collision event
- Sets event type and targets the other vehicle (for other crash)
onTrafficTick(tickTime)
Main decision-making per 0.25s tick:
- Auto-disables on critical damage
- Checks target visibility and proximity
- crashThreshold events: Multiple collisions → flee or follow based on personality
- crash events: Pull over, optionally set
askInsuranceflag - Resets state if target moves out of range (120m)
- Manages traffic signal freezing for emergency config vehicles
onUpdate(dt, dtSim)
Per-frame update:
- Manages action timer countdown
- Insurance exchange: When both vehicles stopped and close → exchange, show UI message
- Follow/flee timeout: Returns to pull-over/insurance mode after timer expires
- Horn honking: Random delay for horn after being hit
Internals
Driver Event Types
| Type | Trigger |
|---|---|
selfCollision | Direct collision with another vehicle |
otherCollision | Witnessed collision between two others |
selfCrash | Crash damage without collision |
otherCrash | Witnessed another vehicle crash |
Personality Effects
| Trait | Low (< 0.45) | High (≥ 0.55) |
|---|---|---|
| Bravery | Flee from collisions | Follow/chase responsible driver |
| Patience | Short pull-over times | Long pull-over/follow times |
| Aggression | Lower base aggression | Higher aggression in flee/follow |
Usage Example
-- Standard role is auto-assigned to civilian traffic
-- Check if a vehicle would follow you after collision:
local veh = gameplay_traffic.getTrafficData()[vehId]
local bravery = veh.role.driver.personality.bravery
log("I", "", bravery >= 0.55 and "Will follow" or "Will flee or stop")See Also
- gameplay/traffic/roles/empty - Empty Traffic Role - Related reference
- gameplay/traffic/roles/police - Police Traffic Role - Related reference
- gameplay/traffic/roles/suspect - Suspect Traffic Role - Related reference
- Gameplay Systems Guide - Guide
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
Suspect Traffic Role
Reference for the `suspect` traffic role, which marks a vehicle as a wanted suspect that police will chase. Manages the transition from watched → wanted → fleeing → arrested states.