Jump to content

[need help] lspdfr crashing when I join the pursuit.


Guest

Recommended Posts

I have created a Callout but every time I join the pursuit lspdfr crashes.

doublechecked for any errors or mistakes, leaving the code below for anyone who could hopefully tell me what I did wrong,

Regs.

If I have done an obvious mistake, sorry I am still learning

 

<snip> in the code for things I removed so noone would steal the idea.

using LSPD_First_Response;
using LSPD_First_Response.Engine.Scripting.Entities;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using Rage;
using Rage.Native;
using System;
using System.Drawing;

namespace <snip>.Callouts
{
    [CalloutInfo("<snip>", CalloutProbability.Medium)]
    class <snip> : Callout
    {
        public Ped <snip>;
        public Ped A1;
        public Vehicle <snip>;
        public Vehicle Veh1;
        public Blip B1;
        public Blip B2;
        public LHandle pursuit;
        public Vector3 spawnPoint;

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

            <snip> = new Ped("<snip>", spawnPoint, 0f);
            A1 = new Ped(spawnPoint);

            <snip> = new Vehicle("<snip>", spawnPoint);
            Veh1 = new Vehicle(spawnPoint);

            if (!A1.Exists()) return false;
            if (!<snip>.Exists()) return false;
            if (!Veh1.Exists()) return false;
            if (!<snip>.Exists()) return false;

            A1.WarpIntoVehicle(Veh1, -1);
            <snip>.WarpIntoVehicle(<snip>, -1);

            this.ShowCalloutAreaBlipBeforeAccepting(spawnPoint, 15f);
            this.AddMinimumDistanceCheck(5f, A1.Position);

            this.CalloutMessage = "<snip>";
            this.CalloutPosition = spawnPoint;

            Functions.PlayScannerAudioUsingPosition("<snip>", spawnPoint);

            return base.OnBeforeCalloutDisplayed();
        }

        public override bool OnCalloutAccepted()
        {
            B1 = A1.AttachBlip();
            B2 = <snip>.AttachBlip();

            B2.Color = Color.Blue;
            B1.EnableRoute(Color.Red);

            NativeFunction.CallByName<uint>("<snip>", <snip>, A1, 0.0f, 0.0f, 40.0f);
            A1.Tasks.CruiseWithVehicle(Veh1, 60f, VehicleDrivingFlags.Emergency);

            A1.BlockPermanentEvents = true;
            <snip>.BlockPermanentEvents = true;

            Game.DisplaySubtitle("Get to the ~b~<snip>~w~.", 5000);
            Game.DisplayNotification("~b~Dispatch~w~: <snip>");
            this.pursuit = Functions.CreatePursuit();
            Functions.AddPedToPursuit(this.pursuit, this.A1);
            Functions.AddCopToPursuit(this.pursuit, this.<snip>);
            Functions.RequestBackup(spawnPoint, LSPD_First_Response.EBackupResponseType.Pursuit, LSPD_First_Response.EBackupUnitType.LocalUnit);

            return base.OnCalloutAccepted();
        }

        public override void OnCalloutNotAccepted()
        {

            if (A1.Exists()) A1.Delete();
            if (<snip>.Exists()) <snip>.Delete();
            if (Veh1.Exists()) Veh1.Delete();
            if (<snip>.Exists()) <snip>.Delete();
            if (B1.Exists()) B1.Delete();
            if (B2.Exists()) B2.Delete();

            base.OnCalloutNotAccepted();
        }

        public override void Process()
        {
            base.Process();

            if (!Functions.IsPursuitStillRunning(pursuit))
            {
                this.End();
            }
        }

        public override void End()
        {
            base.End();
            if (B1.Exists()) B1.Delete();
            if (B2.Exists()) B2.Delete();
            if (Veh1.Exists()) Veh1.Dismiss();
            if (<snip>.Exists()) <snip>.Dismiss();
            if (A1.Exists()) A1.Dismiss();
            if (<snip>.Exists()) <snip>.Dismiss();
        }
    }
}

 

Edited by NoNameSet
Link to comment
Share on other sites

Your peds are probably dead since you spawn them and then the vehicles in the same position, which kills the peds. So in OnCalloutAccepted(), check if they exists and not dead and then use Ped.IsPersistent = true and Veh.IsPersistent = true.

Also add Functions.SetPursuitIsActiveForPlayer(Pursuit, true);.

Link to comment
Share on other sites

7 hours ago, OJdoesIt said:

Your peds are probably dead since you spawn them and then the vehicles in the same position, which kills the peds.

They don't die/aren't dead when I get to the callout but I will try what you said.

3 hours ago, ToastinYou said:

Rather than pathetically snipping shit out thinking we're going to steal your code; just show us the line that is causing the crash and any lines that may interfere with that.

Sorry, all I have really snipped out was the names I used for public Vehicle Veh1 and the other one Vehicle named Heli...as for ped it's pilot.

and for the native i used task heli chase.

Link to comment
Share on other sites

@OJdoesIt thanks, fixed the crashing of the pursuit.

I have a question, would you know a NativeFunction that gets a Ped to go to a specific x,y,z location on foot or in a vehicle?

Link to comment
Share on other sites

@ToastinYou I hate to bother you again but I have been searching all day for a Ped.Task/NativeFunction that gets a Ped in a vehicle to drive to a certain x,y,z location.

I haven't found anything in the Ped.Task functions but in the NativeFunctions I have found "TASK_VEHICLE_DRIVE_TO_COORD" but for some reason I can't get it to work.

again I am sorry, hope you can help me out. If not it's ok you've done enough to help me already.

 

Link to comment
Share on other sites

9 hours ago, NoNameSet said:

@OJdoesIt thanks, fixed the crashing of the pursuit.

I have a question, would you know a NativeFunction that gets a Ped to go to a specific x,y,z location on foot or in a vehicle?

Cop.Tasks.DriveToPosition
Cop.Tasks.GoStraightToPosition

 

Link to comment
Share on other sites

@OJdoesIt I have one last question, promiss it'll be the last one lol.

I am trying to make a Ped in a vehicle wait for the player to get in THAN drive off. Do you know any NativeFunction/Task? I don't wan't to make the ped Wait for (duration) than drive off.

Example of what I am doing:

public Ped MyPed;
public Vehicle MyVehicle;
public ...

public override bool OnCalloutAccepted()
{
	MyPed.Tasks.DriveToPosition("the things you need to enter");
	//GameFiber.Sleep(duration);
	Game.LocalPlayer.Character.EnterVehicle(Vehicle's name, and other stuff);
	MyPed.Tasks.DriveToPosition(new place than the first one);
	//for some reason the 4 lines above don't really work together, the only one that really works alone is the first or last one
}

 

Link to comment
Share on other sites

1 hour ago, NoNameSet said:

@OJdoesIt I have one last question, promiss it'll be the last one lol.

I am trying to make a Ped in a vehicle wait for the player to get in THAN drive off. Do you know any NativeFunction/Task? I don't wan't to make the ped Wait for (duration) than drive off.

Example of what I am doing:


public Ped MyPed;
public Vehicle MyVehicle;
public ...

public override bool OnCalloutAccepted()
{
	MyPed.Tasks.DriveToPosition("the things you need to enter");
	//GameFiber.Sleep(duration);
	Game.LocalPlayer.Character.EnterVehicle(Vehicle's name, and other stuff);
	MyPed.Tasks.DriveToPosition(new place than the first one);
	//for some reason the 4 lines above don't really work together, the only one that really works alone is the first or last one
}

 

Find a way to test fot when player has entered said vehicle. Just look under Game.Localplayer.Character, you'll find something.

Link to comment
Share on other sites

3 minutes ago, ToastinYou said:

Find a way to test fot when player has entered said vehicle. Just look under Game.Localplayer.Character, you'll find something.

I'll see what I can find.

Link to comment
Share on other sites

@ToastinYou I am trying to create a End Callout key.

I have

public static InitializationFile initialiseFile()
        {
            InitializationFile ini = new InitializationFile("Plugins/LSPDFR/PursuingCallouts.ini");
            ini.Create();
            return ini;
}

then

public static String getEndKey()
        {
            InitializationFile ini = initialiseFile();
            string keyBinding = ini.ReadString("Keys", "EndCalloutKey", "End");
            return keyBinding;
}

and then

public override void Process()
        {
            base.Process();

            GameFiber.StartNew(delegate
            {
                {
                    KeysConverter kc = new KeysConverter();

                    Keys EndCalloutKey;

                    try
                    {

                        EndCalloutKey = (Keys)kc.ConvertFromString(getEndKey());
                    }

                    catch
                    {
                        EndCalloutKey = Keys.End;
                        Game.DisplayNotification("There was an error reading the .ini file.");
                    }

                    if (Game.IsKeyDown(EndCalloutKey))
                    {
                        try
                        {
	                        Game.DisplayNotification("~r~Whatever callout name~w~ is ~g~Code 4~w~.");
	                        Functions.PlayScannerAudio("THE_AUDIO_FILES");
	
	                        this.End();
                        }
                        catch (Exception ex)
                        {
                            Game.LogTrivial("Failed to end the callout.");
                        }
                    }
                }
            }, "keyCheckerForWhateverCallout");
}

and in my .ini

[Keys]
EndCalloutKey=End

for some reason this doesn't work, the callout(pursuit) still keeps on going,  hope you can help me with this.

Edited by NoNameSet
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...