Simple deployable traffic lights that can be interacted with to control the flow of AI traffic.
This is an addon for Waypoint Placeables, using it’s logic for placing and picking up the objects.
The traffic light menu allows players to control the traffic light using the following options: Green, Red, Yellow Flashing, and Race Start lights.
Players can get creative and use the traffic lights in a number of ways. Some examples include:
- Police DUI checkpoints
- Construction crews controlling traffic
- Traffic control at events
- Using the “Race Start” mode for the countdown for drag races
Multiple traffic lights can be placed and operated at the same time. Updates to the traffic lights are synced between all players.
This script is based off of Smallos xnTrafficLights.
Preview
GitHub: wp-trafficlights
Usage
Using the traffic lights is quite simple.
- Acquire a traffic light item
- Use the item and place the traffic light in the desired location
- Interact with the traffic light via target to open the menu
- You can also use
/trafficlight
command to open the menu for the traffic light last interacted with
- You can also use
- Select the “Set stopping point” option
- Choose the point where you want traffic to stop.
- Change the radius of the stopping point using the mouse wheel up/down (configurable)
- Select the traffic light mode: Red, Green, Yellow Flashing, or Race Start
Note: If using flashing yellow, it is recommended to have a large radius for your stopping point. Traffic will move slowly while inside the zone.
Performance
The script is designed to be as performant as possible.
Resource monitor results:
- While not in use: 0.00ms
- While in use w/ any mode: 0.00ms
- While placing stopping point (running a raycast): 0.12ms
Dependencies
- Waypoint Placeables
- This is used for placing/picking up the traffic lights items. If you wish to use a different method or do not want an item based system, you can modify to suit your needs or use the original xnTrafficLights.
- QBCore / ESX / OX for Notifications
- menuv
Credit
This script is based off of Smallos xnTrafficLights. Original logic and functionality is derived from xnTrafficLights.
Many modifications have been made to the original script to improve usability and performance. Some changes include:
- improve performance by removing several
while true
loops - remove dependency on jaymenu
- add additional traffic light modes (flashing yellow, race start)
- allow placement and control of multiple traffic lights at the same time