Jump to content

Closing Roads


ThornabySean

Recommended Posts

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;
        }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by AlconH
Link to comment
Share on other sites

Never create blips in a loop. It causes awful performance problems. Take out the blips altogether and it should work better. 

[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

As AlconH said, I've already created a plugin that does exactly this... 

Stealth22
LSPDFR Tester | Plugin Developer
My 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

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.



×
×
  • Create New...