I am of the opinion that I know a possible option that implements the whole thing better. The problem with setting the state is that the visibility of this is very limited by OneSync, because in GTA the traffic lights are behind the intersection is the player at one or the other traffic light already on the intersection until the status is then displayed correctly, unless you let the thread really run with wait(0) which I do not recommend.

However, there is an .xml file in the game files that contains all the intersections, it seems visually as if you can also manually change the phases there. I don’t know exactly.

In order to implement this correctly only on the client side, a native like GetObjectsInArea is missing, we have the function for vehicles, but not for objects, traffic lights are objects and so we can always detect only the closest object to which one is closest.

My third suggestion that might work would be:

  • Write a function that automatically inserts intersections based on chat command or even better a thread that detects traffic lights in a certain radius against checks whether already exists and if not created. so must be driven to the data collection only once the whole map.
  • Then all traffic lights with the native CreateModelHide ensured that all vanilla traffic lights are not visible.
  • Copy all traffic lights from gta v and rename then, so they are not hided. But I also don’t know if in that case the natives to set the status of the traffic light still work.
  • On this basis one could OneSync compatible the traffic lights in a certain radius around the players spawn let with the hope that the radius of the correct traffic light status with it further visibly is, but it is a XXL project to place all traffic lights again in such a way that they are defined as crossings and are switched suitably, advantage here would be that this approach but in itself server-sided with a thread the Spawn and delete would be solvable and client-sided only the Sync works with events. This saves resource timing at the client. One would have to understand the mentioned xml file better and know its effect. Likewise one should find from the code a method to recognize what distinguishes the crossings. In this case you could write a script which reads the xml and rewrites it into a lua or json config according to the script, that would be the optimal way.

I have tried to look at the xml, if someone has more knowledge of it and can say more precisely what affects how and how to recognize which traffic light to which intersection for which interval is I could tackle the whole thing.

From the server side it would also be conceivable to manage to stop ai vehicles I think. I recommend in this case, however, to turn off the AI to save performance and instead write an AI that sends itself vehicles through the world because these would be easier to control.

Otherwise you could also load traffic lights as custom objects that don’t show anything and then start to define where on the model the light should go and then work with further objects, which might work again over even greater distance if the client spawns the light but the server spawns the traffic light itself.

Translated with DeepL Translate: The world's most accurate translator (free version)

1 Like