Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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.

  • Author
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;

 

  • Author
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.
            };

 

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

  • Author
2 minutes ago, Rich said:

It might be easier to just look at your code as a whole instead of in sharing bits here and there.  Drop a Pastebin link if you'd like.

Okay, here is the pastebin link: https://pastebin.com/u8C84f6M

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

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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.