Jump to content
johnnyboy

Prevent AI team leader from ordering team to board a vehicle

Recommended Posts

I'm working on some AI revive and AI control scripts where player is team leader.  When player is wounded bad and goes unconscious, AI buddies will come to heal him.  While in incapacitated state, player is no longer team leader and some AI takes over team.  During this time the AI team sometimes orders AI to board some vehicle.  I think it might be the insert/evac chopper which is miles away, but it could be some other vehicle.  This causes team to run into danger and get slaughtered sometimes.  I need team to stay put while player is down, until player is healed and resumes being team leader.

 

How can I prevent the temporary AI team leader from ordering team to board some vehicle?

 

How can I prevent AI team leader from ordering team to move around?

Share this post


Link to post
Share on other sites

I've been tossing around the idea of coming up with my own "fake" unconsciousness to get around that behavior (player leaves group and AI is promoted to group leader, I assume this was done so orders would keep getting issued so the squad doesn't sit around doing nothing). To keep them from trying to enter a vehicle, try leaveVehicle?

 

The vanilla revive stuff is pretty convenient for scripting, but is just not meant for AI. In an all-player squad it makes zero difference who the squad leader is, because every one is using VoIP anyway. But as soon as you put an AI in charge then SHTF and who can say what's about to happen

  • Thanks 1

Share this post


Link to post
Share on other sites

Unless there are some special waypoints or AI mods at play, it looks like you're dealing with two behaviours:

1. AI mounts up into their assigned vehicle

2. AI moves to engage assigned targets

 

To prevent 1, as dreaded suggested you can use leaveVehicle or achieve a similar effect using allowGetin. More on that here https://community.bistudio.com/wiki/AI_Group_Vehicle_Management

To prevent 2, you can do disableAI "TARGET" for each unit in the group. TARGET prevents them from actively hunting enemy but they will still fight and seek cover. If you wanna be super strict then there's always doStop.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks guys.  Since posting this, I think I have solved this by adding this eventHandler to all units in player's squad.  Previously, I had unassignVehicle in this Event Handler, and that was not solving the problem.

params ["_unit"];
_unit  addEventHandler ["GetOutMan", 
{ 
	params ["_unit", "_role", "_vehicle", "_turret"]; 
	_unit leaveVehicle _vehicle;
}];

 

Share this post


Link to post
Share on other sites

Just be aware with this method that if the group should still use the vehicle at all, you will need to addVehicle to the group again. For a player-led group this is most likely pointless, but for AI-led groups, which I assume you are supporting with this, it is the difference between them never using "their" vehicle again or not

 

Also, was thinking about this. If this is a revive system then you probably have a HandleDamage EH somewhere, in that EH code is probably the best place for this, rather than a GetOutMan EH on a per-unit basis, supposedly leaveVehicle can have a group as input but I have had issues recently on another project with some of these commands working as described on the wiki, unfortunately I did not document this, but with apply this is still a one-liner:

(units _unit) apply { _x leaveVehicle (vehicle _x) }

 

  • Thanks 1

Share this post


Link to post
Share on other sites
19 minutes ago, dreadedentity said:

Just be aware with this method that if the group should still use the vehicle at all, you will need to addVehicle to the group again. For a player-led group this is most likely pointless, but for AI-led groups, which I assume you are supporting with this, it is the difference between them never using "their" vehicle again or not

Thanks!

 

I regret to report that on further testing my solution above does not solve the problem.  The AI still remembers the vehicle and sows "disembark" as their action in command bar, with one AI unit running kilometers chasing the helicopter.  Arggh!

Share this post


Link to post
Share on other sites

Here's what I do to my AI on disembark (no code because it's old):

  • Clear all their waypoints. deleteWaypoint (see Mr. H example)
  • Spawn unassignVehicle followed by orderGetIn.
  • Spawn waitUntil everybody is on foot or dead (objectParent) and then leaveVehicle for each assignedVehicle of the group (each unit might have different vehicle).
  • And finally one crazy thing that happened on Arma 2 and I don't know if it still happens, but AI would panic if group got too small AND lost their vehicles, so:
    (leader _group) setSkill "courage" 0.8
    (leader _group) allowFleeing 0
  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, johnnyboy said:

Thanks!

 

I regret to report that on further testing my solution above does not solve the problem.  The AI still remembers the vehicle and sows "disembark" as their action in command bar, with one AI unit running kilometers chasing the helicopter.  Arggh!

 

BUG

That's the problem I encountered for an age with my own revive heal script. I never found a way to stop the stupid "deputy" leader ordering stupid move, even for unconscious units of its group.

Not a simple question for vehicles, but overall behavior of these AIs. There are, lets say "AI deputy leaders", which put the mess with stupid orders but also regroup  other AIs on their positions when there are stuck inside something (house,rocks,AI's obstacles). That occurs also with JIP players onto "AI deputy leader", like marksman in a weapon squad. (The AIs will follow the played marksman, no more the player leader).

At start, I thought it was a rank question, but that didn't solve this bug (behavior bad design), reliable.

 

Similar topics:

https://feedback.bistudio.com/T80907

https://feedback.bistudio.com/T120658

https://feedback.bistudio.com/T161166

https://forums.bohemia.net/forums/topic/215411-vanilla-weapons-squad-leader-player-orders-on-ais-are-broken-by-deputy-leader/

 

Good luck!

  • Thanks 1

Share this post


Link to post
Share on other sites

Also how about applying stopping stuff on AI subordinates, like disableAI "PATH" and/or forceSpeed 0? And if "acting GL" annoys us with his stupid orders, possibly we could make him shut up with disableAI "RADIOPROTOCOL". So he will still give orders around, but silently and those orders should be ignored. 

  • Like 1

Share this post


Link to post
Share on other sites

I tried everything above in a  very long frustrating day, but AI still would want to do something stupid after player resumes control of team.  So I have resorted to simulating setting player unconscious, and simulating reviving player.  For AI units, I still use setUnconscious.  Hat tip to @dreadedentity for this idea.  The key is that AI never becomes leader of the team, and therefore never goes crazy.

 

Simulate player being set unconscious:

Spoiler

// jboy_playerSimulateUnconscious.sqf
/*
We can't set player unconscious, because then AI unit takes over team, and does crazy shit with them.
Even after player revived and player resumes control of AI, they still do crazy shit like run towards last
vehicle they ever boarded (no matter how far away).
So instead we use animations to put player down until "healed", and we disable user input until healed.
*/
params ["_unit"];
_unit setDamage 0; // prvents showing heal icon
_unit setVariable ["jboy_isSimulatingUnconscious",true];
_unit setMimic "danger";
_unit setFaceAnimation 1;
_unit setRandomLip true;

//disableUserInput true;
_unit disableai "ANIM";
_unit switchMOve "AcinPknlMwlkSlowWrflDb_death2"; // Falls to the side
sleep 1;
_unit switchMove 'AinjPpneMrunSnonWnonDb'; // Lies injured on back
sleep .5;
_unit playActionNow "GestureAgonyCargo";  // Holds gut and hunches over

 

 

Simulate reviving player:

Spoiler

// jboy_playerSetConscious.sqf
// Revive the player.
params ["_unit"];
disableUserInput false;
_unit switchMove "UnconsciousFaceUp"; // Roll over
_unit enableai "ANIM";
sleep .3;
_unit playActionNow "gestureHi"; // Need another gesture to clear the GestureAgonyCargo gesture, else unit runs around holding gut
_unit setRandomLip false;
_unit setVariable ["jboy_isSimulatingUnconscious",false,true];

 

 

So this works pretty well.  I decided not to disableUserInput.  The player can't move, but he can look around and still give orders.  If you disableUserInput, then player's view is restricted and he can't give orders.  I like it that player can look around and see the action around him.

 

Also I discovered that this gesture is awesome:

_unit playActionNow "GestureAgonyCargo";  // Holds gut and hunches over

You can use on player or any AI unit.  After running this, the unit will have weapon on back and hold his stomach and hunch over.  The gesture works while prone, sitting, crouching, standing, and actually walking and running.  So if you want to see an injured unit move (like a captive that is hurt), use this gesture.  The unit (including player) can't use a weapon while the gesture is running, so to clear the gesture, issue another gesture that uses arms, like the following, and unit returns to normal:

_unit playActionNow "gestureHi"; // Need another gesture to clear the GestureAgonyCargo gesture, else unit runs around holding gut

 

  • Like 3

Share this post


Link to post
Share on other sites

Glad that worked out for you, it was the only way I could think getting around having an AI squadmate take leadership; I will probably implement something similar in my own revive system eventually

  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×