Jump to content

[SOLVED] How to make a ped flee or cower properly?


HughJanus
 Share

Recommended Posts

I cant get the fleeing to work.

I have tried

AI::TASK_SMART_FLEE_PED(peds, playerPed, 100.0f, 100, false, false, 0);

AI::TASK_SMART_FLEE_PED(peds, playerPed, 100.0f, 100, true, false, 0);

AI::TASK_SMART_FLEE_PED(peds, playerPed, 100.0f, 100, false, true, 0);

AI::TASK_SMART_FLEE_PED(peds, playerPed, 100.0f, 100, true, true, 0);

 

But the NPCs only turn their back on me but keep standing still.

When using the cowering task, it looks like NPCs are doing squats (they cower, get up, cower, get up,..):

AI::TASK_COWER(peds, 50, 0, 0);

AI::TASK_COWER(peds, 50, 1, 0);

 

I have also tried this method, but it makes NPCs run in one direction, crashing into trees, stones, objects, etc.:

AI::_0xE86A537B5A3C297C(peds, playerPed);

 

Does anyone know how to make a ped flee or cower properly?

Edited by HughJanus
Link to comment
Share on other sites

I've used this one successfully (_TASK_SMART_FLEE_STYLE_PED):

 

0xFD45175A6DFD7CE9(ped, pedToFleeFrom, 3, 0, -1.0f, -1, 0);

 

It is also important to note that fleeing behavior can be altered using flags, but I don't think those are documented yet.

  • Like 1
Link to comment
Share on other sites

Mine does essentially the same, not sure about the internal differences. And no, unfortunately I do not know about the flags, but hopefully someone will clear that up soon.

Link to comment
Share on other sites

3 hours ago, HughJanus said:

If I use your method, the fleeing ped returns after a few minutes and wants to attack me. If I use the value 4 instead of 3, it doesnt.

Just for information^^

 

Interesting, it could be a fleeing style then (potentially bitfield). I think I got mine from the game scripts, I wonder why they chose that value then. Maybe 3 is something like "flee but still react to new threats" whereas 4 would be just "flee forever".

Link to comment
Share on other sites

  • 4 weeks later...

i use 

	void combat_state(Ped ped, Ped player) {
		PED::SET_PED_COMBAT_RANGE(ped, 2);
		PED::SET_PED_COMBAT_MOVEMENT(ped, 2);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 28, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 50, true);
		WEAPON::SET_PED_DROPS_WEAPONS_WHEN_DEAD(ped, false);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 32768, false);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 16384, true);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 512, true);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 1024, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 5, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 17, false);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 14, false);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 58, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 46, true);
		PED::SET_PED_CONFIG_FLAG(ped, 225, false);
		TASK::TASK_COMBAT_PED(ped, player, 0, 0);
		PED::SET_PED_KEEP_TASK(ped, 1);
	}

to make them not flee xd most peds flee on there own 

Link to comment
Share on other sites

21 hours ago, adv0cate said:

i use 


	void combat_state(Ped ped, Ped player) {
		PED::SET_PED_COMBAT_RANGE(ped, 2);
		PED::SET_PED_COMBAT_MOVEMENT(ped, 2);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 28, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 50, true);
		WEAPON::SET_PED_DROPS_WEAPONS_WHEN_DEAD(ped, false);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 32768, false);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 16384, true);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 512, true);
		PED::SET_PED_FLEE_ATTRIBUTES(ped, 1024, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 5, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 17, false);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 14, false);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 58, true);
		PED::SET_PED_COMBAT_ATTRIBUTES(ped, 46, true);
		PED::SET_PED_CONFIG_FLAG(ped, 225, false);
		TASK::TASK_COMBAT_PED(ped, player, 0, 0);
		PED::SET_PED_KEEP_TASK(ped, 1);
	}

to make them not flee xd most peds flee on there own 

 

Could you explain your code? What do the flags and attributes mean?

Link to comment
Share on other sites

  • 1 year later...
14 hours ago, SAC said:

 

Is this solved? How do you make the ped flee?

 

 

I use this native:

static void xTASK_FLEE(Any p0, Any p1, Any p2, Any p3, float p4, Any p5, Any p6) { invoke<Void>(0xFD45175A6DFD7CE9, p0, p1, p2, p3, p4, p5, p6); }

 

Like this:

AI::xTASK_FLEE(PedToFlee, PedToFleeFrom, 4, 0, -1.0f, -1, 0);

 

Link to comment
Share on other sites

2 hours ago, HughJanus said:

 

I use this native:

static void xTASK_FLEE(Any p0, Any p1, Any p2, Any p3, float p4, Any p5, Any p6) { invoke<Void>(0xFD45175A6DFD7CE9, p0, p1, p2, p3, p4, p5, p6); }

 

Like this:

AI::xTASK_FLEE(PedToFlee, PedToFleeFrom, 4, 0, -1.0f, -1, 0);

 

 

 

I found this one, does the trick (ped runs away from itself, basically random fleeing)

 

    TASK::CLEAR_PED_TASKS_IMMEDIATELY(ped, false, false);
    TASK::TASK_SMART_FLEE_PED(ped, ped, -1, -1, 0, 3.0f, 0);

 

Now what I'd like to do is make peds flee towards the PC.

 

My Fallout 4 and Skyrim mods: SAC - LoversLab

 

Link to comment
Share on other sites

2 hours ago, SAC said:

 

 

I found this one, does the trick (ped runs away from itself, basically random fleeing)

 

    TASK::CLEAR_PED_TASKS_IMMEDIATELY(ped, false, false);
    TASK::TASK_SMART_FLEE_PED(ped, ped, -1, -1, 0, 3.0f, 0);

 

Now what I'd like to do is make peds flee towards the PC.

 

I know there is a native with which you can send a ped to a position. Would that suffice?

Link to comment
Share on other sites

2 hours ago, SAC said:

 

So, which native?

 

 

Oh, I thought you were already trying stuff, sorry.

 

 

I have not used these functions, so I cant give any instructions on how to use them, unfortunately 😕

  • Like 1
Link to comment
Share on other sites

TASK::TASK_GO_TO_COORD_ANY_MEANS(ped, coords.x, coord.y, coord.z, 1.0f, 0, 0, 786603, 0xbf800000);

TASK::TASK_FOLLOW_NAV_MESH_TO_COORD(ped, coords.x, coord.y, coord.z, 1.0f, -1, 0.5f, 1048580, 40000.0f);

These are the ones I'm using. The params are: ped, coordinates, speed, timeout I think but not use, don't know the rest...

1.0 is walk speed, 2.0 should be jog and 3.0 is sprint.

edit: oh the parameter after the timeout I think is how close they're supposed to stop to the given coords. 0 is exactly the coords. 

Edited by crossed99
  • Like 1
Link to comment
Share on other sites

On 1/3/2022 at 7:00 PM, crossed99 said:
TASK::TASK_GO_TO_COORD_ANY_MEANS(ped, coords.x, coord.y, coord.z, 1.0f, 0, 0, 786603, 0xbf800000);

TASK::TASK_FOLLOW_NAV_MESH_TO_COORD(ped, coords.x, coord.y, coord.z, 1.0f, -1, 0.5f, 1048580, 40000.0f);

These are the ones I'm using. The params are: ped, coordinates, speed, timeout I think but not use, don't know the rest...

1.0 is walk speed, 2.0 should be jog and 3.0 is sprint.

edit: oh the parameter after the timeout I think is how close they're supposed to stop to the given coords. 0 is exactly the coords. 

 

    Vector3 playerpos = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(PLAYER::PLAYER_PED_ID(), 0.0f + 5, 0.0f + 5, 0.0f + 0);

    TASK::TASK_GO_TO_COORD_ANY_MEANS(ped, playerpos.x, playerpos.y, playerpos.z, 3.0f, 0, 0, 3, 0);

 

This works just fine (the offset is just cosmetic so they don't run into the player). Questions is how to make them do some other stuff when they complete the walking. The "go to coord" function does not return a bool on completion - I suppose a while which breaks only when coordinates are near the player?

 

 

 

My Fallout 4 and Skyrim mods: SAC - LoversLab

 

Link to comment
Share on other sites

Yes, I guess something like checking if he's moving with TASK::IS_PED_STILL and waiting until he stopped should work but you can also do a sequence of actions like this:

 

int changePosSeq;
TASK::OPEN_SEQUENCE_TASK(&changePosSeq);
TASK::CLEAR_PED_TASKS(0, 1, 1);
TASK::TASK_FOLLOW_NAV_MESH_TO_COORD(0, guardPos.x, guardPos.y, guardPos.z, 0.8f, -1, 0.05f, 1048580, 40000.0f);
TASK::TASK_ACHIEVE_HEADING(0, guardPos.h, 1500);
TASK::TASK_START_SCENARIO_IN_PLACE_HASH(0, MICS::GET_HASH_KEY(scenario), -1, true, true, 0.0f, true);
TASK::CLOSE_SEQUENCE_TASK(changePosSeq);
TASK::TASK_PERFORM_SEQUENCE(ped, changePosSeq);
TASK::CLEAR_SEQUENCE_TASK(&changePosSeq);

I use this in my gang hideouts to make them move around and do stuff. Put zeros in the sequence in place of the ped handles, only use the actual ped in the perform sequence line.

Edited by crossed99
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, crossed99 said:

I use this in my gang hideouts to make them move around and do stuff. Put zeros in the sequence in place of the ped handles, only use the actual ped in the perform sequence line.

 

Will this sequence execution block the rest of the script until it completes, or does it execute as a parallel thread?

 

 

My Fallout 4 and Skyrim mods: SAC - LoversLab

 

Link to comment
Share on other sites

No, it doesn't block the rest, you can do anything else while the ped is doing the sequence.

Also, you don't have to clear the sequence immediately like I did, you can use the same sequence multiple times.

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

 Share

×
×
  • Create New...