Jump to content
ThornabySean

Closing Roads

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

 

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


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

Share this post


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


×