Jump to content

Spawned Ped not Attacking Active Peds


Vampyre

Recommended Posts

I have tried everything I can find thus far and no matter what the spawned ped will just stand there with gun in hand and do nothing, won't even attack me as a Cop while standing next to them.

 

I'm just trying to practice functions at the moment if someone can help let me know what I'm missing or is wrong.

 

namespace CalloutPack.Callouts
{
    //Name the callout, and set the probability.
    [CalloutInfo("Suspect with Gun", CalloutProbability.Low)]

    public class UnderFire : Callout
    {
		public Vector3 SpawnPoint;
        public Blip myBlip;
        public Ped mySuspect;
        public PedInventory SuspectInv;
        private RelationshipGroup red;

        public override bool OnBeforeCalloutDisplayed()
        {
            //Get a valid spawnpoint for the callout.
            SpawnPoint = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(300f));

            //Set myVehicle as persistent, so it doesn't randomly disappear.
            //myVehicle.IsPersistent = true;

            //Spawn mySuspect at SpawnPoint.
            mySuspect = new Ped(SpawnPoint);
            mySuspect.IsPersistent = true;
            mySuspect.BlockPermanentEvents = true;
            mySuspect.StaysInGroups = true;
            mySuspect.RelationshipGroup = Red;
            Game.SetRelationshipBetweenRelationshipGroups("Red", "COP", Relationship.Hate);
            Game.SetRelationshipBetweenRelationshipGroups("Red", "CIVMALE", Relationship.Hate);
            Game.SetRelationshipBetweenRelationshipGroups("Red", "CIVFEMALE", Relationship.Hate);
            mySuspect.CanAttackFriendlies = true;
            mySuspect.CanBeTargetted = true;

            //Give Ped Weapon
            mySuspect.Inventory.GiveNewWeapon(WeaponHash.Pistol, ammoCount: 999, equipNow: true);

            //If for some reason, the spawning of mySuspect failed, don't display the callout.
            if (!mySuspect.Exists()) return false;

            //If the peds are valid, display the area that the callout is in.
            this.ShowCalloutAreaBlipBeforeAccepting(SpawnPoint, 15f);
            this.AddMinimumDistanceCheck(5f, SpawnPoint);

            //Set the callout message(displayed in the notification), and the position(also shown in the notification)
            this.CalloutMessage = "Report of Armed Person(s)";
            this.CalloutPosition = SpawnPoint;

            return base.OnBeforeCalloutDisplayed();
        }

		public override void Process()
        {
            base.Process();
            {
                //This states that if the player is less than or equal to 100 meters away from SpawnPoint, then it will do whatever is in the brackets.
                if (Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)
                {
                    mySuspect.Tasks.FightAgainstClosestHatedTarget(1000f);
                    mySuspect.Tasks.Wander();
                }
            }
        }

 

Link to comment
Share on other sites

Update: If I use "mySuspect.Tasks.FightAgainst(Game.LocalPlayer.Character);" it will attack me at least; however, I want the ped to also attack nearby peds while I'm still on the way so you can hear the shots being fired.

 

Any assistance or even ideas to test are appreciated.

Link to comment
Share on other sites

Tasks.FightAgainstClosestHatedTarget(1000f);

 

When it says HatedTarget it is referring to a relationship with nearby peds. If it doesn't find a "HatedTarget" within the vicinity, it won't conduct the task (to my knowledge). You have to make a nearby ped hated, and I believe that can be done through relationship groups. I only skimmed over your code, but I believe this is what is happening.

Link to comment
Share on other sites

2 hours ago, ToastinYou said:

Tasks.FightAgainstClosestHatedTarget(1000f);

 

When it says HatedTarget it is referring to a relationship with nearby peds. If it doesn't find a "HatedTarget" within the vicinity, it won't conduct the task (to my knowledge). You have to make a nearby ped hated, and I believe that can be done through relationship groups. I only skimmed over your code, but I believe this is what is happening.

Thank you for responding, was starting to think no one was going to help.

 

I did set the spawned Ped's group to hate both CivMale and CivFemale, but I'm not sure if all existing peds are automatically members of those groups and as far as I have found so far there's no easy way to just find all nearby peds within a radius. I can't recall the name right now but there was a Get All Entities function but I believe that would literally return ALL entities not just peds and to find peds in that list then find all nearby or just set all peds to groups would probably be too much for RPH/LSPDFR to handle.

Link to comment
Share on other sites

public static Ped[] GetAllPedsInArea(Vector3 location, float radius)
        {
            Ped[] allpeds = Rage.World.GetAllPeds();

            List<Ped> PedsInRadius = new List<Ped>();
            foreach (Ped p in allpeds)
            {
                if(p.DistanceTo(location) <= radius)
                {
                    PedsInRadius.Add(p);
                }
            }
            if(PedsInRadius.Count <= 1)
            {
                PedsInRadius.Add(new Ped(location));
            }

            return PedsInRadius.ToArray();
        }

no guarantee that it works, but Rage.World has GetAllEntities method.

(the code came from an old callout of mine, so it might not work or not be the best way of doing it)

Edited by epicmrjuan

Thank you

Link to comment
Share on other sites

4 hours ago, epicmrjuan said:

public static Ped[] GetAllPedsInArea(Vector3 location, float radius)
        {
            Ped[] allpeds = Rage.World.GetAllPeds();

            List<Ped> PedsInRadius = new List<Ped>();
            foreach (Ped p in allpeds)
            {
                if(p.DistanceTo(location) <= radius)
                {
                    PedsInRadius.Add(p);
                }
            }
            if(PedsInRadius.Count <= 1)
            {
                PedsInRadius.Add(new Ped(location));
            }

            return PedsInRadius.ToArray();
        }

no guarantee that it works, but Rage.World has GetAllEntities method.

(the code came from an old callout of mine, so it might not work or not be the best way of doing it)

Thank you! I was aware of the GetAllEntities method but as I said in my previous post I was worried about the resource intensiveness of having to store that then sort it for getting all peds.

 

However, in your code you used a method I did not see before, GetAllPeds, this may be the way to do it - I will test out your code and see if this still works! Thank you again, I will be back if this doesn't work.

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