Conditions
An extensive list of all DLSv2 conditions available.
All conditions have the following four optional attributes available, each defined in milliseconds:
delay_time
: Delays returning true until the condition has been true for at least this many ms. For example, if you addeddelay_time="1000"
to a speed condition, it would not return true until the vehicle was at the specified speed for at least one second.max_on_time
: Maximum amount of time the condition will return true for (regardless of the actual value of the underlying condition). This resets after the underlying condition returns false again. For example, if you addedmax_on_time="500"
to a braking condition, it would only return true for the first half second that the vehicle was braking. If the vehicle stopped braking (after any amount of time) and started braking again, the timer would reset and it would return true for another 500ms.min_on_time
: Minimum amount of time the condition will return true for (regardless of the underlying condition). When a condition first becomes true, it will remain true for at least the amount of time specified, even if the underlying value is no longer true. For example, if you addedmin_on_time="2000"
to a braking condition, the condition would return true for at least 2 seconds after the vehicle starts braking, or longer if it continues braking for more than 2 seconds.stay_on_time
: Specified amount of time for the condition to continue returning true after the underlying condition has changed to false. For example, if you addedstay_on_time="1500"
to a door open condition, it would return true until 1.5 seconds after the door was closed again.
These attributes can be used together to achieve advanced control of the timing and duration of various functionality, and can be added to any of the conditions listed below.
Grouping Conditions
These special conditions can be used to group together multiple other conditions for advanced control. Any condition - including additional grouping conditions - can be nested inside these conditions.
Any
will return true if at least one condition within it is currently returning true. For example, in the configuration below, the condition will return true if either light mode "Stage 2" or "Stage 3" is active. You can think of this like a boolean "OR".
All
will return true only if every condition within it is currently returning true. For example, in the configuration below, the condition will only return true if the vehicle is not moving and the front left door is open. You can think of this like a boolean "AND".
These can be nested as deep as necessary to provide the control you need. For example, if you want to trigger a mode when either both front doors are open or both rear doors are open, you can do so:
By default, Requirements
in a mode are treated as an "all", and Triggers
are treated as an "any".
Global Conditions
Time
Based on in-game time. Specify a start and end time in hh:mm format (24-hour time). Darkness is approximately from 21:00 - 05:00. If the end time is earlier in the day than the start time, then it will include anytime from start to midnight, and anytime from midnight to end.
Weather
Random
Random chance conditions are evaluated independently once per occurrence per vehicle instance. Once an individual vehicle is spawned, all random chances in its config will be evaluated, and will not change again for that vehicle instance. If another vehicle of the same model is spawned, the random chances will be independently evaluated for that instance.
Vehicle Conditions
Control Group and Mode
Engine State
Indicator Lights
Doors
Speed
Acceleration
Livery
Towing
Specifies if the vehicle is currently towing another vehicle (as a towtruck - see the trailer section below for towing a trailer).
Trailer
Specifies if the vehicle currently has a trailer attached (true or false). attached
must always be specified. If attached
is set to true, you can optionally specify a particular trailer model that must be attached for the condition to be true, or you can omit the model to return true for any trailer.
Extra
Light Emissive
Braking
Base Health
Body Health
Engine Health
Gas Tank Health
Headlight Damage
Bumper Damage
Animation Event
Custom animation event tags can be defined when creating animations. Use the VisibleToScript:Event
tag channel. Put the custom event name in the configuration. Condition returns true while custom event is active within the animation.
Driver
Seats
Occupants and Passengers
Occupants and Passengers conditions are identical, except that "Occupants" includes the driver, and "Passengers" does not. You can mix/match "Min" and "Max", or use "IsFull" or "Any" by themselves.
Vehicle Owner
At Traffic Light
Road Conditions
These conditions are vehicle-specific but depend on where the vehicle is positioned on the road. This can be used to detect if the vehicle is currently facing the same or opposite direction as traffic, which lane the vehicle is in, whether it is on a median or shoulder, and how many adjacent lanes of traffic there are. This is very useful for setting automatic TA modes.
Node Flags
This condition checks the flags of nearby road path nodes. This can be used to detect highways, nearby intersections, etc.
The following attributes are available on the <NodeFlags>
condition:
all
: defaults to true. If true, all specified flags must be present amongst the specified nodes. If false, at least one of the specified flags must be present amongst the specified nodes.nearest_n
: defaults to 1. Specifies how many nodes to check for the specified flags. Nodes will be checked in order of direct distance from the vehicle's position. The nth nearest node may not necessarily be on the same road as the vehicle or be the nearest by driving distance.max_dist_to_node
: defaults to 50m. Specifies the maximum distance (in meters) away from the vehicle position for a node to be considered.no_node_status
: defaults to false. Specifies whether the condition should return true or false if no nodes are found within the specified distance.include_disabled_nodes
: defaults to false. Specifies whether to include nodes that are currently disabled. Ambient AI vehicles will not spawn/drive on disabled nodes, but vehicles with a driving task may sometimes. Most parking lots, small dirt paths, private areas, and many other roads have disabled nodes.
Within the NodeFlags
element there must be a <Flags>
element with no attributes, and within the Flags element there must be one or more <Item>
elements each specifying a node flag to check for. If nearest_n
is greater than 1 and all
is true, the condition will return true if all of the flags being checked for are present at least once across the n
nodes, even if they don't all appear on the same single node. The <Item>
has an optional attribute has_flag
which defaults to true. If set to false
then the code will ensure that none of the n
nodes checked has this flag.
The available <Item>
flags include:
Some of these flags can be visualized in CodeWalker paths view for reference. A junction
flag typically occurs once per intersection at the node in the middle of the intersection. traffic_light
and stop_sign
will typically appear at the stop bar when approaching the intersection.
Road Direction
Checks if the current road segment is flagged for one-way traffic. Typically occurs on divided highways where the opposite direction is technically a separate road. Also occurs occasionally with actual one-way streets.
On Road
Checks if the vehicle position is on the road within the bounds of the drive lanes, not including shoulders/medians. on_road
defaults to true
.
Shoulder and Median
These conditions check if the vehicle position is within a median (to the left side of the leftmost lane, typically in the buffer zone between oncoming traffic) or on the shoulder (right of the rightmost lane). Note that "median" returns true when the vehicle is left of the edge of the road on a one-way road even if there is no opposite divided road.
All attributes are optional. on_shoulder
or on_median
defaults to true
, in which case the condition will return true when the vehicle is on the shoulder/median. If set to false, it will return false when the vehicle is not on the shoulder/median. Min and max optionally specify the distance range in meters from the edge of the nearest lane. For example, if you set max="10"
then the condition will only return true if the vehicle is within 10 meters of the edge of the lane.
Road Lanes
There are several conditions relating to the number of lanes and the vehicle's position within them.
These conditions are all calculated based on the direction of traffic in the lane that the vehicle is currently in or closest to, regardless of which direction the vehicle itself is facing.
Total Lane Count
The basic RoadLanes
condition just checks the total number of road lanes on the current road.
The optional attribute both_directions
defaults to true. When set to true, it counts the total number of lanes in both directions on two-lane roads. When set to false, it only counts the number of lanes in the direction of traffic for the lane the vehicle is currently in/closest to. You must specify min
and/or max
for the number of lanes to check for.
Relative Lane Count
There are two relative road lanes conditions, RoadLanesLeft
and RoadLanesRight
, each behaving in the same way. Left specifies the number of additional vehicle lanes to the left of the current lane, and right specifies the number of additional lanes to the right. If it is a single lane road, both will return 0. The lane the vehicle in is not counted. This condition will change depending on which lane the vehicle is currently in.
Both conditions support specifying attributes min
and/or max
. At least one of the two must be specified. The condition returns true when the number of lanes to the left or right is greater than min and/or less than max.
Road Lane Position
The RoadLanePosition
condition checks the vehicle's position within the lane, from -1 being at the far left side of the lane to +1 being the far right side of the lane.
You must specify min
and/or max
as a decimal value between -1 and 1. The optional abs
attribute defaults to false and specifies whether the min/max should be applied to the absolute value of the position.
Road Lane Index
The RoadLaneIndex
condition checks which specific lane number the vehicle is in, starting from the leftmost lane as #1. If optional attribute from_left
is set to false, it will count from the rightmost lane starting with 1. You must specify min
and/or max
with the range of lane indexes the vehicle may be in.
Vehicle Offset from Road Direction
This condition checks the relative angle between the direction traffic flows in the current lane and the direction the vehicle is facing. The number is returned in degrees between -180 (left) and +180 (right). If the vehicle is facing the direction of traffic the offset is 0°. If the vehicle is facing exactly towards oncoming traffic the offset is 180°. Specify a min
and/or max
offset, and optionally set abs
to true if you want to compare the absolute value of the difference. abs
defaults to false, but in most cases it makes sense to set it to true unless you really want to ensure the vehicle is angled in a specific direction (which may be relevant for a TA or traffic stop setting).
Full Example
The following configuration adds an automatic traffic advisor function when the vehicle is owned by an NPC. The vehicle must be occupied by a non-player, not waiting at a traffic light, be stopped or moving under 15 mph, or be on a highway moving under 25 mph.
The left TA is triggered when the vehicle is facing forward (within +/- 45 degrees) with zero lanes to the right and at least one lane to the left, or when on the shoulder within 4 meters of the side of the lane. The right TA is triggered under the same conditions from the opposite side. The split TA is triggered when there is at least one lane on each side of the vehicle. All three modes will only trigger if the condition has been true for at least 2 seconds.
Here is an example of a similar config in action, including additional debug information showing some of the calculated values that are used in the underlying logic for these conditions:
Last updated