Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
qwerasdzxc

Traffic Lights Check

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!

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
SYNTHES1SE

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.

Share this post


Link to post
Share on other sites
Tiryll

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

Share this post


Link to post
Share on other sites
qwerasdzxc

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

Share this post


Link to post
Share on other sites
Fireboyd78

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.

Share this post


Link to post
Share on other sites
SYNTHES1SE

 

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

Share this post


Link to post
Share on other sites
Fireboyd78

 

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.

Share this post


Link to post
Share on other sites
SYNTHES1SE

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'

Share this post


Link to post
Share on other sites
qwerasdzxc

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!

Share this post


Link to post
Share on other sites
qwerasdzxc

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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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