Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Happy Holidays from the GTANet team!

Traffic Lights Check


qwerasdzxc
 Share

Recommended Posts

qwerasdzxc

There's a native IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS (Vehicle vehicle) that returns bool as a result. In-game I tried doing this on my current vehicle but nothing happens, it's always set to false..

If someone knows anything about how to make this work for vehicle that player is using I'd be grateful!

 

I need this function so I can implement it in my mod.

Thanks in advance!

Link to comment
Share on other sites

Fireboyd78

I don't think this will work on a player's vehicle. It's probably meant for the AI traffic, since the game wouldn't necessarily know if the player stopped at a traffic light.

Link to comment
Share on other sites

qwerasdzxc

I don't think this will work on a player's vehicle. It's probably meant for the AI traffic, since the game wouldn't necessarily know if the player stopped at a traffic light.

Ahh I thought so.. Anyway you think that some improvisation can be made?

Link to comment
Share on other sites

Fireboyd78

 

I don't think this will work on a player's vehicle. It's probably meant for the AI traffic, since the game wouldn't necessarily know if the player stopped at a traffic light.

Ahh I thought so.. Anyway you think that some improvisation can be made?

 

It would be some pretty lengthy and complicated code, but you could probably get all nearby vehicles with peds in them, check to see if they're stopped at a traffic light, get the distance between the player and that stopped vehicle, make sure they're facing roughly the same direction, and then see if the player went flying past them. That's all I can think of.

Edited by Fireboyd78
Link to comment
Share on other sites

qwerasdzxc

 

 

I don't think this will work on a player's vehicle. It's probably meant for the AI traffic, since the game wouldn't necessarily know if the player stopped at a traffic light.

Ahh I thought so.. Anyway you think that some improvisation can be made?

 

It would be some pretty lengthy and complicated code, but you could probably get all nearby vehicles with peds in them, check to see if they're stopped at a traffic light, get the distance between the player and that stopped vehicle, make sure they're facing roughly the same direction, and then see if the player went flying past them. That's all I can think of.

 

Well yeah, nothing can be simple :(

Nevermind I'll try to figure something out, thanks for the suggestions!

Link to comment
Share on other sites

I managed to get the following working in C#:

 if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - player.CurrentVehicle.Heading) < 30) && (player.CurrentVehicle.Speed <= closestVehicle.Speed))            {                player.CurrentVehicle.PrimaryColor = VehicleColor.MatteDarkRed;            }            else            {                player.CurrentVehicle.PrimaryColor = VehicleColor.Green;            }

basically, If you're stopped at a red light, and there is another car near you, and that car is facing a similar direction, and that car is also stopped at the red light, then your car is gonna be red, otherwise, your car is gonna be green.

 

Put this in your OnTick() function and have a drive around to get a better understanding on how it needs to be improved. Not sure if its gonna be possible to check if you're stopped at a red light if there are no other cars around though.

Link to comment
Share on other sites

I managed to get the following working in C#:

 if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - player.CurrentVehicle.Heading) < 30) && (player.CurrentVehicle.Speed <= closestVehicle.Speed))            {                player.CurrentVehicle.PrimaryColor = VehicleColor.MatteDarkRed;            }            else            {                player.CurrentVehicle.PrimaryColor = VehicleColor.Green;            }

basically, If you're stopped at a red light, and there is another car near you, and that car is facing a similar direction, and that car is also stopped at the red light, then your car is gonna be red, otherwise, your car is gonna be green.

 

Put this in your OnTick() function and have a drive around to get a better understanding on how it needs to be improved. Not sure if its gonna be possible to check if you're stopped at a red light if there are no other cars around though.

Objects exist for the traffic lights. There's 3 that's not that same as the others, they seem to have colours attached to them which seems to power the actual poles. I could be wrong though, but using your method you could also apply to the actual lightpole for additional failsafes. As I understand it, vehicles that are parked (engine off) also flag as true for being stopped at lights, so perhaps make sure the engine is on also for your original method.

"prop_traffic_01a",			"prop_traffic_lightset_01",	"prop_traffic_01a",		"prop_traffic_01b",		"prop_traffic_01d",		"prop_traffic_02a",			"prop_traffic_02b",			"prop_traffic_03a",	"prop_traffic_03b",		
Edited by Tiryll
Link to comment
Share on other sites

I managed to get the following working in C#:

 if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - player.CurrentVehicle.Heading) < 30) && (player.CurrentVehicle.Speed <= closestVehicle.Speed))            {                player.CurrentVehicle.PrimaryColor = VehicleColor.MatteDarkRed;            }            else            {                player.CurrentVehicle.PrimaryColor = VehicleColor.Green;            }

basically, If you're stopped at a red light, and there is another car near you, and that car is facing a similar direction, and that car is also stopped at the red light, then your car is gonna be red, otherwise, your car is gonna be green.

 

Put this in your OnTick() function and have a drive around to get a better understanding on how it needs to be improved. Not sure if its gonna be possible to check if you're stopped at a red light if there are no other cars around though.

I tested the code and it works surprisingly well! It's not perfect because it doesn't run when there aren't any vehicles on the traffic light but it's better then nothing..

 

Also I have one weird problem with closestVehicle.EngineRunning in the if statement:

Vehicle closestVehicle = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, 50f, 0, 70);if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - currVeh.Heading) < 30) && (closestVehicle.EngineRunning == true))
error CS0154: The property or indexer 'GTA.Vehicle.EngineRunning' cannot be used in this context because it lacks the get accessor

Thanks anyway, I really appreciate your help on this!

Edited by qwerasdzxc
Link to comment
Share on other sites

Also I have one weird problem with closestVehicle.EngineRunning in the if statement:

Vehicle closestVehicle = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_CLOSEST_VEHICLE, playerPos.X, playerPos.Y, playerPos.Z, 50f, 0, 70);if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - currVeh.Heading) < 30) && (closestVehicle.EngineRunning == true))
error CS0154: The property or indexer 'GTA.Vehicle.EngineRunning' cannot be used in this context because it lacks the get accessor
Thanks anyway, I really appreciate your help on this!

 

 

From the ScriptHookV.NET source code:

property bool EngineRunning{    void set(bool value);}

That's why.

Link to comment
Share on other sites

 

if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - currVeh.Heading) < 30) && (closestVehicle.getEngineRunning()))

That should work now, engineRurunning is a private variable so you cant access it like how you were doing it, you need to use the getter method which is getEngineRunning().

 

 

Objects exist for the traffic lights. There's 3 that's not that same as the others, they seem to have colours attached to them which seems to power the actual poles. I could be wrong though, but using your method you could also apply to the actual lightpole for additional failsafes. As I understand it, vehicles that are parked (engine off) also flag as true for being stopped at lights, so perhaps make sure the engine is on also for your original method.

 

"prop_traffic_01a",

"prop_traffic_lightset_01",

"prop_traffic_01a",

"prop_traffic_01b",

"prop_traffic_01d",

"prop_traffic_02a",

"prop_traffic_02b",

"prop_traffic_03a",

"prop_traffic_03b",

 

That's interesting, if i have the time and energy after work, i might look into this. Thanks for your input :)

Edited by SYNTHES1SE
Link to comment
Share on other sites

 

if (Function.Call<bool>(Hash.IS_VEHICLE_STOPPED_AT_TRAFFIC_LIGHTS, closestVehicle) && (Math.Abs(closestVehicle.Heading - currVeh.Heading) < 30) && (closestVehicle.getEngineRunning()))
That should work now, engineRurunning is a private variable so you cant access it like how you were doing it, you need to use the getter method which is getEngineRunning().

 

No, you don't get it. There is no native for checking whether or not the engine is running.

Link to comment
Share on other sites

No, you don't get it. There is no native for checking whether or not the engine is running.

 

Oh, yeah, super tired and i guess i missed that, ¯\_(ツ)_/¯

 

I guess have a drive around and see if parked card do actually count as 'stopped at traffic lights'

Link to comment
Share on other sites

From the ScriptHookV.NET source code:

property bool EngineRunning{    void set(bool value);}

That's why.

 

Ah okay, I see now.. Well this check would be very useful but since the mod (in 99% time) doesn't see parked vehicles as stopped at traffic, it's good as it is!

 

Thanks for the answer!

Link to comment
Share on other sites

Well I found the new problem just now..

Sometimes even when you are stopping the vehicle before the traffic light, mod tells you that you are passing through red light (even though I am behind the traffic light).

I mean that can be seen by the function arguments, it's logical that that would happen.

If you have any ideas how to prevent this false trigger I would be grateful!

Thanks in advance!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.