Jump to content
RCA3

AI walking with weapon lowered in formation

Recommended Posts

Here's a workaround for making AI lower their weapons and keep formation:

  1. Select all your units.
  2. Set them to UP (standing).
  3. Select all your units again and set them to SAFE.
  4. Select all your units again and set them to AWARE.

 

Your AI units will walk with lowered weapon on selected formation.

  • Like 3

Share this post


Link to post
Share on other sites

OMG. thanks a bunch! Any idea why this hack to get it working like that? How to get editor placed units to do the same?

  • Like 1

Share this post


Link to post
Share on other sites

My idea here is that there's something telling the AI that Automatic Stance is NOT Standing (which while Aware, it is 😐) so we got to force Standing first for the engine to know.


This seems to be working. Enjoy 😉.

 

On the group's Init field:

Option 1

Works only once until AI changes behaviour.

null = this spawn{ 
 _this setBehaviour "SAFE"; 
 
 { 
  _x setUnitPos "UP"; 
  waitUntil {(unitPos _x) isEqualTo "Up"};
 }forEach units _this; 
 
 {
   waitUntil {weaponLowered _x};
 }forEach units _this; 
  
 _this setBehaviour "AWARE"; 
 
 waitUntil {!(behaviour (leader _this) isEqualTo "AWARE") || (units _this findIf {alive _x} isEqualTo -1)}; 
 
 { 
  _x setUnitPos "AUTO"; 
 }forEach units _this; 
};

 

Option 2

Permanent throughout the mission:

Note that AI will stay in forced "AWARE" mode after contact, preventing the code to activate "SAFE" mode (lowering the weapons), at ~5 minutes mark they'll lower rifles again.

TAG_arr_rasanims = ["amovpercmwlksraswrfldf", "amovpercmwlksraswrfldf_ver2", "amovpercmrunsraswrfldf", "amovpercmrunsraswrfldf_ldst"];
TAG_arr_lowbehaviour = ["AWARE", "CARELESS"];

{
	if !(isPlayer _x) then{
		_x addEventHandler ["AnimChanged", { 
			params ["_unit", "_anim"];

			if (_anim in TAG_arr_rasanims) then{
				if !(behaviour _unit in TAG_arr_lowbehaviour) exitWith{_unit setUnitPos "AUTO"};
				if (_unit getVariable ["ai_walk_lowered", false]) exitWith{};
				_unit setVariable ["ai_walk_lowered", true];
				_unit spawn{
					_this setBehaviour "SAFE";
					_this setUnitPos "UP";
					waitUntil {sleep 0.1; weaponLowered _this || {_this distance (formationPosition _this) > 5} || {!(alive _this)}};
					_this setBehaviour "AWARE";
					_this setVariable ["ai_walk_lowered", false];
				};
			};
		}];
	};
}forEach units this;

(Moderators you might want to move this to Editing & Scripting, Idk, it's up to you. Thanks).

Edited by RCA3
Changed code (weaponLowered). Added Option 2.

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

×