Jump to content

Getting Random Ped to not Flee


ThornabySean

Recommended Posts

Hey, I was wondering if someone could help me out with what could well be a simple issue (take it easy I am new to game mods!).

I am trying to create my first mod. As part of the mod I have a conversation with a random ped (not ped spawned by script).  The outcome of the conversation could be a fight but every time I get to that point the ped just runs away (flees).  I have been looking at this a while and struggling to find out how to stop this behavior and make him stay and fight.  I currently have this to try and make him stay and fight:

NativeFunction.CallByName<uint>("SET_BLOCKING_OF_NON_TEMPORARY_EVENTS", NPC, 1);
NativeFunction.CallByName<uint>("SET_PED_FLEE_ATTRIBUTES", NPC, 0, 0);
NativeFunction.CallByName<uint>("SET_PED_COMBAT_ATTRIBUTES", NPC, 46, true);

NPC is the variable of the ped.

I have tried giving the ped a weapon first but they still flee; and also playing about with the parameters being passed but still no luck.

Any help would be much appreciated.

Link to comment
Share on other sites

Thank you for replying.

Appologies, I never sent the whole code segment but thought it better not to put too much in my first post.  I do already have that native function included further down.  I have the below but the Peds still continue to flee:

             NativeFunction.CallByName<uint>("SET_BLOCKING_OF_NON_TEMPORARY_EVENTS", NPC, 1);
          NativeFunction.CallByName<uint>("SET_PED_FLEE_ATTRIBUTES", NPC, 1, 1);
            //NativeFunction.CallByName<uint>("SET_PED_COMBAT_ATTRIBUTES", NPC, 46, true);
           
            NPC.RelationshipGroup = "MYENEMY";
            WeaponAsset NPC_Knife = new WeaponAsset("WEAPON_BAT");
            NPC.GiveNewWeapon(NPC_Knife, 1, true);
            Game.SetRelationshipBetweenRelationshipGroups("MYENEMY", Game.LocalPlayer.Character.RelationshipGroup.Name, Relationship.Hate);
            NativeFunction.CallByName<uint>("TASK_COMBAT_PED", NPC, Game.LocalPlayer.Character, 0, 1);

As you can see I have also created the group relationships; and I presume this works because when the code runs and the Ped is set to the Enemy group and the relationship is 'Enemy'; some other peds in the area run away as they see two enemies (I am presuming this is a default action for peds who see 2 enemies within their vicinity).

P.S. Ignore the variable stating knife but weapon being a bat - playing about!

Link to comment
Share on other sites

We will start with trying to get your ped to attack.

Do you have a section call "public override void Process()" withing you code?

If you do, then place this a line beneath "base.Process();", It should look something like this.

            base.Process();
            if (this.myPed.IsAlive)
                NativeFunction.CallByName<uint>("TASK_COMBAT_PED", myPed, Game.LocalPlayer.Character, 0, 1);

replace "myPed" with NPC.

 

Link to comment
Share on other sites

This is just a testing project where I can test code works before adding it into the main project!

The code is just located in the Main() section of the single class file (which is the only class file in the project - testing!):
private static void Main()

I have a check for a keypress which then grabs the closest ped (as in the officer speaking to the ped) then the code above is executed .... all in one class and one Main() function for testing.

Apologies if this is a bit 'noob'; I am just getting back into dev after about 10 years out!

Link to comment
Share on other sites

I have 2 completely separate projects; 1 is my actual callout, the other is testing - I have done it this way so I don't need to run through full scenarios in-game to test a new set of code - I just put the new code into the Testing project, compile and run so I can test the code straight away.  Once I have am happy the new code works (like this this piece of code); I will then add it into my working callout project :-)

Link to comment
Share on other sites

Ok so try this:

Replace this:

            Game.SetRelationshipBetweenRelationshipGroups("MYENEMY", Game.LocalPlayer.Character.RelationshipGroup.Name, Relationship.Hate);
            NativeFunction.CallByName<uint>("TASK_COMBAT_PED", NPC, Game.LocalPlayer.Character, 0, 1);

With this:

            Game.SetRelationshipBetweenRelationshipGroups("MYENEMY", Game.LocalPlayer.Character.RelationshipGroup.Name, Relationship.Hate);

            if (this.NPC.IsAlive)
            {
                NativeFunction.CallByName<uint>("TASK_COMBAT_PED", NPC, Game.LocalPlayer.Character, 0, 1);
            }

This will make then fight the player for as long as they are alive.

Does this work?

Link to comment
Share on other sites

Instead of using all those natives, use the following:

NPC.BlockPermanentEvents = true;
NPC.Tasks.FightAgainst(Game.LocalPlayer.Character); //something like this, can't remember the exact function name

You can simply remove those flee things you added in, they're not necessary.

My YouTube: Click here. 

My Discord Server - https://discord.gg/0taiZvBSiw5qGAXU

Useful post? Let me and others know by clicking the Like button.
Check out my many script modifications! 
Having issues? LSPDFR Troubleshooter by Albo1125.

Link to comment
Share on other sites

Thank you all for your help, after a lot of playing about the answer I have just tested was very close to what Albo said (not that I ever expect anything Albo says to be wrong!)
NPC.BlockPermanentEvents = true;
NPC.GiveNewWeapon("WEAPON_BAT", 20, true);
NPC.RelationshipGroup = MyEnemyGroup;
Rage.Native.NativeFunction.Natives.TaskCombatPed(NPC, Game.LocalPlayer.Character, 0, 16); <------ setting this to 16 was the difference, setting back to 1 meant they ran away again

The enemy group will come in handy later in a different scenario where the ped 'calls in his mates' :-)

Thank you all for taking the time to respond.

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