Jump to content

Error:Object reference not set to an instance of an object


Ben A.

Recommended Posts

Hi all, please can i have some help with this error, heres my code:

Spoiler

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rage;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Engine.Scripting.Entities;
using System.Drawing;

namespace British_Callouts.Callouts
{
    [CalloutInfo("Acid Attack", CalloutProbability.High)]
    public class AcidAttack : Callout
    {
        private Ped myPed;
        private Vehicle myVehicle;
        private Vector3 SpawnPoint;
        private Blip myPedBlip;
        private LHandle Pursuit;
        private bool PursuitCreated = false;
        private Ped Victim;
        private Blip SearchArea;

        public override bool OnBeforeCalloutDisplayed()
        {

            SpawnPoint = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(250f));

            myPed = new Ped("g_m_m_chicold_01", SpawnPoint, 0f);
            Victim = new Ped("u_m_y_zombie_01", SpawnPoint, 0f);

            myVehicle = new Vehicle("FAGGIO2", SpawnPoint);

            if (!myPed.Exists()) return false;
            if (!myVehicle.Exists()) return false;
            if (!Victim.Exists()) return false;

            myPed.WarpIntoVehicle(myVehicle, -1);

            ShowCalloutAreaBlipBeforeAccepting(SpawnPoint, 30f);
            AddMinimumDistanceCheck(20f, SpawnPoint);

            SearchArea = new Blip(myPed.Position, 100f)

            CalloutMessage = "Acid Attack";
            CalloutPosition = SpawnPoint;

            Functions.PlayScannerAudioUsingPosition("WE_HAVE CRIME_ATTEMPTED_MURDER_IN_OR_ON_POSITION", SpawnPoint);

            return base.OnBeforeCalloutDisplayed();
        }
        public override bool OnCalloutAccepted()

        {

            myVehicle.IsPersistent = true;
            myPed.IsPersistent = true;
            myPed.BlockPermanentEvents = true;
            myPedBlip = myPed.AttachBlip();
            myPedBlip.IsFriendly = false;

            SearchArea = new Blip(myPed.Position, 100f)
            {
                Alpha = 0.5f,
                Color = Color.Yellow
            };

            Victim.IsPersistent = true;
            myPed.Tasks.CruiseWithVehicle(100f, VehicleDrivingFlags.None);
            return base.OnCalloutAccepted();
        }

        public override void Process()
        {

            base.Process();
            if (!PursuitCreated && Game.LocalPlayer.Character.DistanceTo(myPed.Position) < 5f)
            {
                Pursuit = Functions.CreatePursuit();
                Functions.AddPedToPursuit(Pursuit, myPed);
                Functions.SetPursuitIsActiveForPlayer(Pursuit, true);
                PursuitCreated = true;
            }
            if (PursuitCreated && !Functions.IsPursuitStillRunning(Pursuit))
            {
                End();
            }
        }

        public override void End()
        {
            base.End();
            if (myPed.Exists()) { myPed.Dismiss(); }
            if (myVehicle.Exists()) { myVehicle.Dismiss(); }
            if (myPedBlip.Exists()) { myPedBlip.Delete(); }
            if (SearchArea.Exists()) { SearchArea.Delete(); }
        }
    }
}

Im new to coding so i have no idea what this means!

Playing BattleBorn Roleplay! Great community, active server and staff! Hiring LEOs + EMS + Staff! Discord.gg//pz3teSD

Link to comment
Share on other sites

Please post the actual error from your ragepluginhook.log

Also you should never create blips, spawn vehicles/peds, or do anything else visible to the player in OnBeforeCalloutDisplayed. All of that should be done in OnCalloutAccepted. The only things you should do in OnBeforeCalloutDisplayed are to check if it's OK to show the callout, and return false if it isn't. Otherwise, if the callout isn't accepted, then you'll have a bunch of stuff spawned in for a callout that doesn't actually occur. 

[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

Thank you, but ive sorted it, weapon was spelt wrong, thanks anyway!

Playing BattleBorn Roleplay! Great community, active server and staff! Hiring LEOs + EMS + Staff! Discord.gg//pz3teSD

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