Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Getting Random Ped to not Flee

Featured Replies

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.

  • Author

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!

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.

 

  • Author

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!

Ah ok

Right so let me get this straight, you have the main callout project with all the files required for it to work, then you have a separate class file in which your building the code which you then transfer over to the main project?

  • Author

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 :-)

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?

  • Author

No this has the same results, all Ped just ran away.  I have added a line above to give the Ped a weapon but that is just so that I can see something happen on screen.  I have removed this line as well but no difference in Ped reaction.

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.

  • Author

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

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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.