This is a first attempt at creating a script for smart traffic lights that turn green after waiting. The coordinates are sent to the server and then to all clients so the state is synced however AI ignore any changes.
You should try to add an option for when any emergency vehicles with lights on the light turns green. (If possible make it not able to respond to ambers.)
That’s a good idea, should be fairly straight forward to implement I’ll look into it.
It’s possible to override vehicle/PED behavior with natives like SetDriveTaskDrivingStyle() which has a bit for ignoring lights but some of the other stuff gets a bit messy and I dunno if it’s worth the possible desync issues.
One alternative solution is modifying traffic density to be more during the day and significantly less at night and then only changing lights at night if you have issues with AI behavior. Could also lower AI speeds in city and modify handling/braking to avoid accidents.
Yes, the goal is to provide a mechanic for bypassing traffic lights while still forcing the player to come to a full stop and follow basic traffic laws. If you stop at a light and it changes green cops should also see that the light is green so they know you’re not running the light.
It depends on how strict you want traffic laws to be, this provides a middle ground between having to obey every traffic light and completely ignoring every traffic light.
This is a rough work around, it’s by no means perfect but might provide a starting point for others to build off of if they think it’s useful. There’s plenty of other issues with AI vehicle behavior but considering you need to stop at the light first collisions aren’t a major issue in my experience.
Hi Brent, I have recently implemented this into my server to try and get the drag lights working well. Here is a video (ignore the water part) with me staging my car and as soon as i get in or slightly past the gates (this is where the light picks up a vehicle per the distance change i made) The green light turns on just a bit too quickly. I was wondering if you can make the green light delay a bit longer from when I come to a stop in front of the light? I tried editing the TRAFFIC_LIGHT_DURATION_MS = 7000 – Duration to turn light green (ms) but it doesnt seem to work as you can see in the video, it turns green rather quickly and I know for a fact that it wont pick my car up until i am within the gated area. Any help is greatly appreciated as I know this is not what the script is intended for lol. https://www.youtube.com/watch?v=pdDnilGeUZc&t=120s Thank you!
Nevermind. If anyone is interested in the same modification to this script. Add in the section beneath where I have “-- attempt to make a pause between light”
and add this line below at the top where the other Local’s are (change time to your liking): local TRAFFIC_LIGHT_WAIT_MS = 4000
section to replace:
– If traffic light found and not the same as the last one
if (trafficLight ~= 0) and (trafficLight ~= lastTrafficLight) then
– attempt to make a pause between light
Citizen.Wait(TRAFFIC_LIGHT_WAIT_MS)
– Trigger server event to change light for everyone
– TODO: verify this works for all clients, network/entity ID same or different…
TriggerServerEvent(‘SmartTrafficLights:setLight’, GetEntityCoords(trafficLight, false))
hello there, i just downloaded citizen and my traffic lights are off. Can somebody help me? If you gonna help me, i can give you some money to paypal. 3$