Jump to content

[Solved] Can someone tell me why this code crashes LSPDFR?


OJS

Recommended Posts

Okay, so I have come across an issue with my code, and I have absolutely no idea why it crashes the game. So, it happens in my "Stolen Vehicle" callouts whenever the callout is accepted. I know that it deals with these lines of the code below:

            // Vehicle Info.
            var modelName = SuspectVehicle.Model.Name; // The vehicle's model name. 
            var vColor = SuspectVehicle.PrimaryColor.ToKnownColor(); // The vehicle's known primary color.
            var licensePlateNum = SuspectVehicle.LicensePlate; // The vehicle's license plate number.

            Game.DisplayNotification("Respond Code 3! The vehicle is a " + vColor + " " + modelName + " with license plate number " + licensePlateNum); // Display's a notification for the player specifying Response type and a description of the suspect vehicle.

Previously the variables above were set as private readonly strings. And I added a ".ToString()" method to the end of it's assigned values. This didn't help at all. So, I switched it to be vars, hoping the program could sort it automatically (I assume that's why the var type exists). I've even moved the vars outside of the "OnCalloutAccepted" method, that didn't help much at all. Here is what the Log says:

Quote
  • [10/15/2020 19:25:49.626] LSPD First Response: [FATAL] OnCalloutAccepted crashed: System.NullReferenceException: Object reference not set to an instance of an object.
  • [10/15/2020 19:25:49.626] at BlaineCountyCallouts.Callouts.StolenVehicleLCGSD.OnCalloutAccepted() in C:\Users\Johnny Shumway\Documents\Blaine County Callouts\Dev Files\BlaineCountyCallouts\BlaineCountyCallouts\Callouts\StolenVehicleLCGSD.cs:line 48
  • [10/15/2020 19:25:49.626] at EEUVGzJhfZCnkbPIILrIqALshKUeb.cfHDzunAimgxOgvWSPMPWcbRWAfY() in E:\GTA V\LSPD First Response\LSPD First Response\Mod\Callouts\CalloutManager.cs:line 412

Basically, what I am trying to do with this code is display a notification to notify the player of how to respond (Code 2, Code 3, Code 99, etc.), and give a description of the suspect's vehicle. Since, the player will, more times than not need to search for it. I could really use some help for this.

 

Thanks,

- OfficerohnnyShumway

Edited by OfficerJohnnyShumway
Question has been solved.
Link to comment
Share on other sites

  • Management Team

Ideally you show us line 48 of StolenVehicleLCGSD.cs so we can have a better look at what might be causing it.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

Link to comment
Share on other sites

54 minutes ago, LMS said:

Ideally you show us line 48 of StolenVehicleLCGSD.cs so we can have a better look at what might be causing it.

Line 48 is:

var modelName = SuspectVehicle.Model.Name;

 

Link to comment
Share on other sites

28 minutes ago, Rich said:

SuspectVehicle is not valid?

            SuspectVehicle = new Vehicle(GroundVehiclesToSelectFrom[rnd.Next(GroundVehiclesToSelectFrom.Length)], SVLCGSDSpawnPoint) // Sets the vehicle to be a random vehicle from the "GroundVehiclesToSelectFrom" array.
            {
                IsPersistent = true, // Makes the vehicle Persistent.
                EngineHealth = eDamage, // Set's the engine health.
                IsStolen = true, // Marks the vehicle as stolen.
                Heading = 352.9712f // Sets the vehicles heading.
            };

 

Link to comment
Share on other sites

21 minutes ago, Rich said:

That doesn't tell me it's valid.  You have an error on line 48 due to a null reference exception, and the only thing you're trying to do on line 48 is reference SuspectVehicle's model name.

I think I might of just realized what was wrong, could this error be caused due to the "SuspectVehicle" variable being static:

private static Vehicle SuspectVehicle; // The stolen vehicle.

Previously when I was making the variables (on line 48, 49, and 50) in the class rather than in the method I made it static since Visual Studio suggested it after I made the vars as private readonly strings.  

Link to comment
Share on other sites

5 minutes ago, Rich said:

You're trying to reference SuspectVehicle's model on line 48, but you don't create the vehicle until line 64.

Oh, well that explains a lot lol My bad, thanks mate! I feel so stupid for overlooking that.

Link to comment
Share on other sites

  • The title was changed to [Solved] Can someone tell me why this code crashes LSPDFR?

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...