ThornabySean 2 Posted September 2, 2016 Share Posted September 2, 2016 Hi all, I am hoping someone can help with the script method I am using to close nearby roads. Based on a scenario the player is asked if the roads should be closed (to protect civs etc!); I have a script which runs and does work but it is not very performance friendly so I was hoping for a better way of achieving the road closure. At the minute based on the players position I am using ped.GetNearbyVehicles(16) and then looping through the vehicles to freeze the position of the vehicle. This works great to start with but then ends up being performance intensive after a while. The below is the function which is being called - I am passing the blip back so I can then remove it later. public static Blip CloseRoadsInAreaOfPed(Ped CloseRoadsAround, float DistanceFromCentre) { Vehicle CurrentVehicle; Vehicle[] AllVehicles; AllVehicles = CloseRoadsAround.GetNearbyVehicles(16); for (int i = 0; i < AllVehicles.Length; i++) { CurrentVehicle = AllVehicles[i]; if (CloseRoadsAround.DistanceTo(CurrentVehicle) < DistanceFromCentre) { CurrentVehicle.IsPositionFrozen = true; } } //Now place ablip around the area where the road is closed Blip RoadClosed = new Blip(CloseRoadsAround.Position, DistanceFromCentre); RoadClosed.Color = Color.Cyan; RoadClosed.Name = "Road Closure"; return RoadClosed; } Quote Link to comment Share on other sites More sharing options...
AlconH 1,711 Posted September 2, 2016 Share Posted September 2, 2016 How will this differ from the current "Close Nearby Roads" function that LSPDFR has by default? Or Traffic Control for that matter? I just wouldn't want you to waste your time on something that's already been made. Quote Link to comment Share on other sites More sharing options...
ThornabySean 2 Posted September 5, 2016 Author Share Posted September 5, 2016 Hi AlconH, Thank you for taking the time to reply, but this is not for a traffic stop so LSPDFR will not kick in. I want to have the ability to stop all vehicles within the vicinity of a Vector3 position, the above code works but has a big issue with screen refreshed so everything goes black! I have added in a check so the Blip does not get constantly redrawn (which was an issue in what I posted last week!) but still hitting this issue. I have looked and there does not appear to be an API call for this functionality, hence the reason for trying to create it myself; but admittedly this is part of my first Plugin. Cheers. Quote Link to comment Share on other sites More sharing options...
AlconH 1,711 Posted September 5, 2016 Share Posted September 5, 2016 (edited) 4 hours ago, ThornabySean said: Hi AlconH, Thank you for taking the time to reply, but this is not for a traffic stop so LSPDFR will not kick in. I want to have the ability to stop all vehicles within the vicinity of a Vector3 position, the above code works but has a big issue with screen refreshed so everything goes black! I have added in a check so the Blip does not get constantly redrawn (which was an issue in what I posted last week!) but still hitting this issue. I have looked and there does not appear to be an API call for this functionality, hence the reason for trying to create it myself; but admittedly this is part of my first Plugin. Cheers. Yeah, the close all roads function provided by LSPDFR works regardless, no matter what you're doing. Same with traffic control. However, if you still wish to continue developing this, try seeking help on the RPH discord server here: https://t.co/IaYUM3S13l Edited September 5, 2016 by AlconH Quote Link to comment Share on other sites More sharing options...
PNWParksFan 2,509 Posted September 6, 2016 Share Posted September 6, 2016 Never create blips in a loop. It causes awful performance problems. Take out the blips altogether and it should work better. Quote [REL] Coastal Callouts: An action-packed mod with new vehicles, maps, capabilities, and callouts in and around the waters of Los Santos [REL] Police Tape: Make your scenes more realistic while stopping peds and traffic [REL] Better EMS: Realistic and dynamic EMS response Join the Parks Benefactor Program to support my work and get early beta access! Link to comment Share on other sites More sharing options...
ThornabySean 2 Posted September 6, 2016 Author Share Posted September 6, 2016 Thanks @PNWParksFan, I had already realised and added in checks for existing blips - newb error! Quote Link to comment Share on other sites More sharing options...
Stealth22 804 Posted September 9, 2016 Share Posted September 9, 2016 As AlconH said, I've already created a plugin that does exactly this... Quote Stealth22LSPDFR Tester | Plugin DeveloperMy Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+ Please do not PM me for any kind of technical support. I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.