qwerasdzxc Posted June 7, 2015 Share Posted June 7, 2015 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 More sharing options...
Fireboyd78 Posted June 7, 2015 Share Posted June 7, 2015 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 More sharing options...
qwerasdzxc Posted June 7, 2015 Author Share Posted June 7, 2015 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 More sharing options...
Fireboyd78 Posted June 7, 2015 Share Posted June 7, 2015 (edited) 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 June 7, 2015 by Fireboyd78 qwerasdzxc 1 Link to comment Share on other sites More sharing options...
qwerasdzxc Posted June 7, 2015 Author Share Posted June 7, 2015 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 More sharing options...
SYNTHES1SE Posted June 11, 2015 Share Posted June 11, 2015 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. qwerasdzxc 1 Link to comment Share on other sites More sharing options...
Tiryll Posted June 11, 2015 Share Posted June 11, 2015 (edited) 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 June 11, 2015 by Tiryll Link to comment Share on other sites More sharing options...
qwerasdzxc Posted June 11, 2015 Author Share Posted June 11, 2015 (edited) 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 June 11, 2015 by qwerasdzxc Link to comment Share on other sites More sharing options...
Fireboyd78 Posted June 12, 2015 Share Posted June 12, 2015 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 accessorThanks 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 More sharing options...
SYNTHES1SE Posted June 12, 2015 Share Posted June 12, 2015 (edited) 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 June 12, 2015 by SYNTHES1SE Link to comment Share on other sites More sharing options...
Fireboyd78 Posted June 12, 2015 Share Posted June 12, 2015 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 More sharing options...
SYNTHES1SE Posted June 12, 2015 Share Posted June 12, 2015 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 More sharing options...
qwerasdzxc Posted June 12, 2015 Author Share Posted June 12, 2015 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 More sharing options...
qwerasdzxc Posted June 12, 2015 Author Share Posted June 12, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now