Jump to content
Sign in to follow this  
PNWParksFan

LSPDFR crashes when spawned cop added to pursuit with AddCopToPursuit approaches suspect

Recommended Posts

I am working on a plugin which adds pursuit units to the game. I spawn the units as follows:

LHandle pursuit;
pursuit = GetPursuit();

Vehicle ResponseVehicle;
Model rVehicleModel;
Ped CopPed;
Model CopModel;
Vector3 SpawnLocation = World.GetNextPositionOnStreet(PlayerPosition.Around(250));

rVehicleModel = new Model("policeold1");
CopModel = new Model("s_m_y_cop_01");

if (!rVehicleModel.IsValid)
{
	Game.DisplayNotification("~R~Unable to create model "   rVehicleModel.Name);
	return;
}
ResponseVehicle = new Vehicle(rVehicleModel, SpawnLocation);
ResponseVehicle.MakePersistent();
ResponseVehicle.IsSirenOn = true;
ResponseVehicle.ShouldVehiclesYieldToThisVehicle = true;

CopPed = new Ped(CopModel, SpawnLocation, 3f);
Functions.AddCopToPursuit(pursuit, CopPed);
CopPed.WarpIntoVehicle(ResponseVehicle, ResponseVehicle.GetFreeSeatIndex().GetValueOrDefault(0));

Now, if I comment out the line with "AddCopToPursuit", the unit still joins the pursuit due to LSPDFR 0.3's auto-pursuit feature. That said, I want to explicitly add the cop to the pursuit so that it won't be affected by plugins like @Albo1125's auto pursuit disabler. When I have Albo's plugin installed, then if I just spawn the cops without adding them to the pursuit, they just sit there (as expected). 

The problem is, if I call AddCopToPursuit, then when the cops I spawned and added myself approach the suspect, LSPDFR crashes with the errors shown below. Note this happens consistently, even when I have no other RPH or LSPDFR plugins enabled other than the one I'm developing. The crash doesn't happen immediately on spawning the units, it only happens when the units get close to the suspects. All of my game fibers are named, so the crash appears to be originating in LSPDFR; additionally the crash refers to specific lines in the LSPDFR code. 

[1/24/2016 10:50:29 PM.069] LSPD First Response: 
[1/24/2016 10:50:29 PM.070] LSPD First Response: ==============================
[1/24/2016 10:50:29 PM.070] LSPD First Response: UNHANDLED EXCEPTION DURING GAME THREAD TICK
[1/24/2016 10:50:29 PM.070] LSPD First Response: ------------------------------
[1/24/2016 10:50:29 PM.070] LSPD First Response: Origin: Game fiber "<UNNAMED THREAD>".
[1/24/2016 10:50:29 PM.070] LSPD First Response: ------------------------------
[1/24/2016 10:50:29 PM.071] LSPD First Response: Exception type: System.NullReferenceException
[1/24/2016 10:50:29 PM.071] LSPD First Response: Exception message: Object reference not set to an instance of an object.
[1/24/2016 10:50:29 PM.071] LSPD First Response: ------------------------------
[1/24/2016 10:50:29 PM.071] LSPD First Response: Inner exceptions:
[1/24/2016 10:50:29 PM.071] LSPD First Response: ------------------------------
[1/24/2016 10:50:29 PM.072] LSPD First Response: Stack trace:
[1/24/2016 10:50:29 PM.072] LSPD First Response: at ?????????????????????????????????????????.?????????????????????????????????????????() in E:\GTA V\LSPD First Response\LSPD First Response\Engine\Scripting\Chase.cs:line 413
[1/24/2016 10:50:29 PM.072] at ?????????????????????????????????????????.?????????????????????????????????????????() in E:\GTA V\LSPD First Response\LSPD First Response\Engine\Main.cs:line 52
[1/24/2016 10:50:29 PM.072] at LSPD_First_Response.Mod.LSPDFR.MainLoop() in E:\GTA V\LSPD First Response\LSPD First Response\Mod\LSPDFR.cs:line 607
[1/24/2016 10:50:29 PM.073] at Rage.GameFiber.Main()
[1/24/2016 10:50:29 PM.073] LSPD First Response: ==============================
[1/24/2016 10:50:29 PM.073] LSPD First Response: 

Am I using AddCopToPursuit wrong, or is there some bug in LSPDFR? 

 

Edited by PNWParksFan

Share this post


Link to post
Share on other sites

Update: It appears that calling "Functions.SetPedAsCop(CopPed);" first before adding the cop to the pursuit stops the crash, although I need to do some more testing to be sure. If that's the case, I would suggest that the AddCopToPursuit function either raise an exception if the ped is not a cop, or automatically set the cop as a ped. 

Share this post


Link to post
Share on other sites
2 hours ago, PNWParksFan said:

Update: It appears that calling "Functions.SetPedAsCop(CopPed);" first before adding the cop to the pursuit stops the crash, although I need to do some more testing to be sure. If that's the case, I would suggest that the AddCopToPursuit function either raise an exception if the ped is not a cop, or automatically set the cop as a ped. 

Yea. Set the ped as a cop first before adding the ped as a cop. 

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
Sign in to follow this  

×