Jump to content

LSPDFR Crash when accepting Callout


Nicooo

Recommended Posts

As soon as I accept this callout, LSPD:FR Crashes...

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LSPD_First_Response.Engine.Scripting;
using LSPD_First_Response.Engine.Scripting.Entities;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Engine;
using Rage;
using System.Diagnostics;
using Rage.Attributes;
using Rage.Native;
using System.Windows.Forms;

namespace City_Callouts.Callouts
{
    [CalloutInfo("WrongParkedVehicle", CalloutProbability.High)]
    public class WrongParkedVehicle : Callout
    {
        public Blip SuspectBlip;
        public Vector3 SpawnPoint;
        public Vehicle SuspectVehicle;
        public Ped SuspectPed;
        public Blip VehicleBlip;


        public override bool OnBeforeCalloutDisplayed()
        {           
            SpawnPoint = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(700f));

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

            CalloutMessage = "Wrong Parked Vehicle";
            return base.OnBeforeCalloutDisplayed();
        }
        public override void OnCalloutDisplayed()
        {
            base.OnCalloutDisplayed();
            Functions.PlayScannerAudio("WE_HAVE");
        }
        public override bool OnCalloutAccepted()
        {
            Game.DisplayHelp("Press ~r~T~s~ to begin a conversation", 7500);
            Game.LocalPlayer.Character.Position.DistanceTo(SuspectPed);

            SuspectPed  = new Ped("a_m_m_bevhills_01", SpawnPoint, 32f);
            VehicleBlip = new Blip(SpawnPoint);
            SuspectVehicle = new Vehicle("Blista", SpawnPoint);

            SuspectBlip = SuspectPed.AttachBlip();
            SuspectBlip.IsFriendly = false;

            SuspectPed.IsPersistent = true;
            SuspectPed.BlockPermanentEvents = true;

            return base.OnCalloutAccepted();
        }
        public override void Process()
        {
            base.Process();
            if (Game.LocalPlayer.Character.DistanceTo(SuspectPed.Position) < 30f)
            Game.IsKeyDown(System.Windows.Forms.Keys.T);
                {
                    Game.DisplaySubtitle("~b~Officer:~s~ Hello sir, is that your car?", 9000);
                    GameFiber.Yield();
                    Game.DisplaySubtitle("~r~Suspect:~s~ Yeah, i just wanted to leave.", 7000);
                    GameFiber.Yield();
                    Game.DisplaySubtitle("~b~Officer:~s~ You're not going anywhere, imagine there was a crash because of your car!.", 6500);
                    GameFiber.Yield();
                    Game.DisplaySubtitle("~r~Suspect:~s~ I don't care, i just want to leave right now ok?!", 4000);
                    GameFiber.Yield();
                    Game.DisplaySubtitle("~b~Officer:~s~ No, I guess you have to come with me to the PD!", 6500);
                    GameFiber.Yield();
                    Game.DisplaySubtitle("~b~Suspect:~s~ No, I'm leaving now, fuck you!", 3000);
                    GameFiber.Yield();
                    Game.DisplayNotification("Arrest the ~r~suspect~s~.");
                    if (Functions.IsPedArrested(SuspectPed));
                }
            
            {
                End();
            }
        }
        public override void End()
        {
            base.End();
            if (SuspectBlip.Exists()) SuspectBlip.Delete();
            if (SuspectVehicle.Exists()) SuspectVehicle.Delete();
            if (SuspectPed.Exists()) SuspectPed.Dismiss();
            if (VehicleBlip.Exists()) VehicleBlip.Delete();
        }
    }
}

 

 

 

 

Link to comment
Share on other sites

Changed something, new code:

Spoiler

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LSPD_First_Response.Engine.Scripting;
using LSPD_First_Response.Engine.Scripting.Entities;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Engine;
using Rage;
using System.Diagnostics;
using Rage.Attributes;
using Rage.Native;
using System.Windows.Forms;

namespace City_Callouts.Callouts
{
    [CalloutInfo("WrongParkedVehicle", CalloutProbability.High)]
    public class WrongParkedVehicle : Callout
    {
        public Blip SuspectBlip;
        public Vector3 SpawnPoint;
        public Vehicle SuspectVehicle;
        public Ped SuspectPed;
        public Blip VehicleBlip;


        public override bool OnBeforeCalloutDisplayed()
        {
            SpawnPoint = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(700f));

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

            CalloutMessage = "Wrong Parked Vehicle";
            return base.OnBeforeCalloutDisplayed();
        }
        public override void OnCalloutDisplayed()
        {
            base.OnCalloutDisplayed();
            Functions.PlayScannerAudio("WE_HAVE");
        }
        public override bool OnCalloutAccepted()
        {
            Game.DisplayHelp("Press ~r~T~s~ to begin a conversation", 7500);

            SuspectPed = new Ped("a_m_m_bevhills_01", SpawnPoint, 32f);
            VehicleBlip = new Blip(SpawnPoint);
            SuspectVehicle = new Vehicle("Blista", SpawnPoint);

            SuspectBlip = SuspectPed.AttachBlip();
            SuspectBlip.IsFriendly = false;

            SuspectPed.IsPersistent = true;
            SuspectPed.BlockPermanentEvents = true;

            return base.OnCalloutAccepted();
        }
        public override void Process()
        {
            base.Process();
            if (Game.LocalPlayer.Character.Position.DistanceTo(SuspectPed.Position) < 5f);
            {
                Game.IsKeyDown(System.Windows.Forms.Keys.T);
            }
            {
                Game.DisplaySubtitle("~b~Officer:~s~ Hello sir, is that your car?", 9000);
                GameFiber.Wait(8000);
                Game.DisplaySubtitle("~r~Suspect:~s~ Yeah, i just wanted to leave.", 7000);
                GameFiber.Wait(7500);
                Game.DisplaySubtitle("~b~Officer:~s~ You're not going anywhere, imagine there was a crash because of your car!.", 6500);
                GameFiber.Wait(7000);
                Game.DisplaySubtitle("~r~Suspect:~s~ I don't care, i just want to leave right now ok?!", 4000);
                GameFiber.Wait(8000);
                Game.DisplaySubtitle("~b~Officer:~s~ No, I guess you have to come with me to the PD!", 6500);
                GameFiber.Wait(8000);
                Game.DisplaySubtitle("~b~Suspect:~s~ No, I'm leaving now, fuck you!", 3000);
                GameFiber.Wait(8000);
                Game.DisplayNotification("Arrest the ~r~suspect~s~.");
                if (Functions.IsPedArrested(SuspectPed));
                if (Functions.IsPedStoppedByPlayer(SuspectPed));
                {
                    End();
                }
            }
        }
            public override void End()
            { 
            base.End();
            if (SuspectBlip.Exists()) SuspectBlip.Delete();
            if (SuspectVehicle.Exists()) SuspectVehicle.Delete();
            if (SuspectPed.Exists()) SuspectPed.Dismiss();
            if (VehicleBlip.Exists()) VehicleBlip.Delete();
            }
    }
}

 

 

Now the plugin doesn't crash anymore, but as soon as I accept the callout, the dialouge shows, but it only should when i'm near the Ped

Edited by Nicooo
Changed the Code, added description

 

 

 

 

Link to comment
Share on other sites

3 hours ago, Nicooo said:

Changed something, new code:

  Reveal hidden contents

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LSPD_First_Response.Engine.Scripting;
using LSPD_First_Response.Engine.Scripting.Entities;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Engine;
using Rage;
using System.Diagnostics;
using Rage.Attributes;
using Rage.Native;
using System.Windows.Forms;

namespace City_Callouts.Callouts
{
    [CalloutInfo("WrongParkedVehicle", CalloutProbability.High)]
    public class WrongParkedVehicle : Callout
    {
        public Blip SuspectBlip;
        public Vector3 SpawnPoint;
        public Vehicle SuspectVehicle;
        public Ped SuspectPed;
        public Blip VehicleBlip;


        public override bool OnBeforeCalloutDisplayed()
        {
            SpawnPoint = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(700f));

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

            CalloutMessage = "Wrong Parked Vehicle";
            return base.OnBeforeCalloutDisplayed();
        }
        public override void OnCalloutDisplayed()
        {
            base.OnCalloutDisplayed();
            Functions.PlayScannerAudio("WE_HAVE");
        }
        public override bool OnCalloutAccepted()
        {
            Game.DisplayHelp("Press ~r~T~s~ to begin a conversation", 7500);

            SuspectPed = new Ped("a_m_m_bevhills_01", SpawnPoint, 32f);
            VehicleBlip = new Blip(SpawnPoint);
            SuspectVehicle = new Vehicle("Blista", SpawnPoint);

            SuspectBlip = SuspectPed.AttachBlip();
            SuspectBlip.IsFriendly = false;

            SuspectPed.IsPersistent = true;
            SuspectPed.BlockPermanentEvents = true;

            return base.OnCalloutAccepted();
        }
        public override void Process()
        {
            base.Process();
            if (Game.LocalPlayer.Character.Position.DistanceTo(SuspectPed.Position) < 5f);
            {
                Game.IsKeyDown(System.Windows.Forms.Keys.T);
            }
            {
                Game.DisplaySubtitle("~b~Officer:~s~ Hello sir, is that your car?", 9000);
                GameFiber.Wait(8000);
                Game.DisplaySubtitle("~r~Suspect:~s~ Yeah, i just wanted to leave.", 7000);
                GameFiber.Wait(7500);
                Game.DisplaySubtitle("~b~Officer:~s~ You're not going anywhere, imagine there was a crash because of your car!.", 6500);
                GameFiber.Wait(7000);
                Game.DisplaySubtitle("~r~Suspect:~s~ I don't care, i just want to leave right now ok?!", 4000);
                GameFiber.Wait(8000);
                Game.DisplaySubtitle("~b~Officer:~s~ No, I guess you have to come with me to the PD!", 6500);
                GameFiber.Wait(8000);
                Game.DisplaySubtitle("~b~Suspect:~s~ No, I'm leaving now, fuck you!", 3000);
                GameFiber.Wait(8000);
                Game.DisplayNotification("Arrest the ~r~suspect~s~.");
                if (Functions.IsPedArrested(SuspectPed));
                if (Functions.IsPedStoppedByPlayer(SuspectPed));
                {
                    End();
                }
            }
        }
            public override void End()
            { 
            base.End();
            if (SuspectBlip.Exists()) SuspectBlip.Delete();
            if (SuspectVehicle.Exists()) SuspectVehicle.Delete();
            if (SuspectPed.Exists()) SuspectPed.Dismiss();
            if (VehicleBlip.Exists()) VehicleBlip.Delete();
            }
    }
}

 

 

Now the plugin doesn't crash anymore, but as soon as I accept the callout, the dialouge shows, but it only should when i'm near the Ped

Then you need to use an if statement. It would be: If (game.localplayer.character.position)

and then add your suspect and the distance.

Link to comment
Share on other sites

33 minutes ago, HazyTube said:

Then you need to use an if statement. It would be: If (game.localplayer.character.position)

and then add your suspect and the distance.

I'll try it, thank you

 

 

 

 

Link to comment
Share on other sites

You have a bunch of unnecessary code in there and could also use a fiber, waiting then yielding (which is compeltely unnecessary) after each subtitle isn't the best idea.

Link to comment
Share on other sites

7 minutes ago, NoNameSet said:

You have a bunch of unnecessary code in there and could also use a fiber, waiting then yielding (which is compeltely unnecessary) after each subtitle isn't the best idea.

Hi, i already changes the Gamefiber.Yield() to Gamefiber.Wait in the released callouts, thx 

10 minutes ago, NoNameSet said:

You have a bunch of unnecessary code in there and could also use a fiber, waiting then yielding (which is compeltely unnecessary) after each subtitle isn't the best idea.

Kannst auch auf Deutsch schreiben 😉

 

 

 

 

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