Jump to content
The Shroom

[Callout] Ped runs away from police when Task is set to fight him?

Recommended Posts

I'm having some issues regarding tasks in my callout. 

Whenever I set the task to do anything, it is always interrupted when I come to close and the Ped/Suspect starts running away in panic.

In this case I'm trying to make the suspect flee the player, and if he gets too close, start shooting at him instead. But, when the player gets close, the ped starts running away.

I have set the Suspects "BlockPermanentEvents" to true, but it doesn't fix my issue.

 

My current code looks like this: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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;

namespace Shroom.Callouts
{
    [CalloutInfo("Panic Button", CalloutProbability.Always)]
    public class PanicButton : Callout
    {
        private Ped attacker;
        private Blip attackerBlip;
        private Vector3 calloutSpawn;
        private LHandle pursuit;

        enum AttackerStatus
        {
            None, Attacking, Running
        }

        private AttackerStatus attackerStatus;

        public override bool OnBeforeCalloutDisplayed()
        {
            calloutSpawn = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(250f));
            ShowCalloutAreaBlipBeforeAccepting(calloutSpawn, 30f);
            AddMinimumDistanceCheck(20f, calloutSpawn);

            CalloutMessage = "Panic Button";
            CalloutPosition = calloutSpawn;

            Functions.PlayScannerAudioUsingPosition("UNITS_RESPOND_CODE_99_01", CalloutPosition);

            return base.OnBeforeCalloutDisplayed();
        }

        public override bool OnCalloutAccepted()
        {
            attacker = new Ped(calloutSpawn, 0f);
            attackerBlip = new Blip(attacker);
            attackerBlip.IsFriendly = false;
            attacker.IsPersistent = true;
            attacker.KeepTasks = true;
            attacker.BlockPermanentEvents = true;
            attacker.CanAttackFriendlies = true;

            pursuit = Functions.CreatePursuit();
            Functions.AddPedToPursuit(pursuit, attacker);
            Functions.SetPursuitCopsCanJoin(pursuit, true);
            Functions.SetPursuitIsActiveForPlayer(pursuit, true);

            attacker.Inventory.GiveNewWeapon(WeaponHash.Pistol, 100, true);

            return base.OnCalloutAccepted();
        }

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

            if (attacker.Exists())
            {
                if (Functions.IsPedArrested(attacker) || Functions.IsPedInPrison(attacker))
                {
                    End();
                }
            }

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

            if (attackerStatus == AttackerStatus.None)
            {
                attackerStatus = AttackerStatus.Running;
                attacker.Tasks.Flee(Game.LocalPlayer.Character, int.MaxValue, int.MaxValue);
            }
            else if(attackerStatus == AttackerStatus.Running && Game.LocalPlayer.Character.Position.DistanceTo(attacker.Position) < 20f)
            {
                Vector3 firingPosition = new Vector3(Game.LocalPlayer.Character.Position.X, Game.LocalPlayer.Character.Position.Y - 10f, Game.LocalPlayer.Character.Position.Z);
                attackerStatus = AttackerStatus.Attacking;
                attacker.Tasks.FireWeaponAt(firingPosition, int.MaxValue, FiringPattern.SingleShot);
            }
        }

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

            if (attacker.Exists())
            {
                attacker.Dismiss();

                if (attackerBlip.Exists())
                    attackerBlip.Delete();
            }
        }
    }
}

 

Share this post


Link to post
Share on other sites

You attached the ped to the Pursuit, therefore LSPDFR will be controlling the ped as well.

Try doing ped.Tasks.Clear() and then set the shoot/fight task.

Share this post


Link to post
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...