Jump to content
RCA3

Force AT/AA specialists forget enemy vehicles when ordered hold fire

Recommended Posts

Took a bit of code from LAMBS fnc_tacticsHide and did this. It runs on player's group AIs only and it's a separate script from LAMBS. It's just an example, a proof of concept (although fully functional).


Note: unfortunately forgetTarget makes the whole group forget it's targets (even if used on unit), it would be nice if individual units could forget targets and let others retain the memory, this way we could order individual AT/AA to engage, now you have to make all your AT/AA's open fire (within this script), guys without launchers can remain hold fire though 👍. (no need if we use _unit disableAI "AUTOTARGET").

 

/*
	Force AT/AA specialists disableAI "AUTOTARGET" when ordered hold fire

	Description:
	Allows AI in player's group to remain prone and regroup faster on the presence of enemy vehicles.

	Execute from initPlayerLocal.sqf
*/

TAG_fnc_forgetATAAtargets = {
	params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"];

	if (commandingMenu isNotEqualTo "RscMenuEngage") exitWith{};

	switch (_key) do{
		//Open fire
		case 2:{
			[] spawn {
				// find launchers
				private _launchers = (units group player) select {(secondaryWeapon _x) isNotEqualTo "" && {!(isPlayer _x)}};
				if (_launchers isNotEqualTo []) then{
					sleep 2;
					{
						if !(unitCombatMode _x in ["BLUE","GREEN"]) then{
							_x enableAI "AUTOTARGET";
						};
					}forEach _launchers;
				};
			};
		};
		//Hold fire
		case 3:{
			[] spawn {
				// find launchers
				private _launchers = (units group player) select {(secondaryWeapon _x) isNotEqualTo "" && {!(isPlayer _x)}};
				if (_launchers isNotEqualTo []) then{
					sleep 2;
					{
						if (unitCombatMode _x in ["BLUE","GREEN"]) then{
							_x disableAI "AUTOTARGET";
						};
					}forEach _launchers;
				};
			};
		};
		default {};
	};
};

waituntil {sleep 0.1; !isNull (findDisplay 46)};
null = (findDisplay 46) displayAddEventHandler ["KeyDown", "call TAG_fnc_forgetATAAtargets"];

 

Edited by RCA3
new code without loops
  • Thanks 1

Share this post


Link to post
Share on other sites

Would it be possible then to remember what targets the team had, then get them to forget, and then give them all the target again (except the AT/AA) ?  Sorry not a coder.

  • Like 1

Share this post


Link to post
Share on other sites

@kremator, I think you want the script to reveal previous known targets that they forgot (to hide, regroup, etc) as soon as they are not hold fire anymore, correct?

This part confuses me though:

7 hours ago, kremator said:

(except the AT/AA)

Right now you do have to re-mark/identify targets (default T?) after you let them open fire, unless they are obvious and AI can clearly seem them, then AI engages as always. But only armor/air targets are forgotten (actually, I should add cars and boats too 😏), so i'm not sure if you're worried about infantry or not, those are not forgotten.

If it's scripted memory that you want and to be restored fully after ordered open fire, i'm sure it can be done, but there's also the question if they should still know about their targets after "some time" has passed and how accurate that reveal should be.

If anybody has suggestions please post them.

Share this post


Link to post
Share on other sites
On 4/2/2021 at 5:14 PM, RCA3 said:

Note: unfortunately forgetTarget makes the whole group forget it's targets (even if used on unit), it would be nice if individual units could forget targets and let others retain the memory, this way we could order individual AT/AA to engage, now you have to make all your AT/AA's open fire (within this script), guys without launchers can remain hold fire though .

 


 

["forgetThat","onEachFrame", {
  {
    _unit = _x;
    if (secondaryWeapon _unit isNotEqualTo "" && unitCombatMode _unit in ["BLUE","GREEN","WHITE"]) then {
      {_unit forgetTarget _x } count ((_unit targets []) select {_x in vehicles});
    };
  } forEach (units player select {!isPlayer _x})
 }] call bis_fnc_addStackedEventHandler;

 

if:   _unit forgetTarget _x   seems too global for the group, you could try with:   _unit reveal [_x,0]  (not tested)

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks @pierremgi, optimized code a bit more thanks to you and was able to remove permanent eachFrame EH thanks to @serena 's post.

Haven't tested reveal 0 yet.

Cheers.

Share this post


Link to post
Share on other sites

Updated the script for no loops (replaced forgetTarget with disableAI "AUTOTARGET") and the group still retains the target's memory so AI engages faster.

 

On 4/4/2021 at 6:55 PM, kremator said:

Would it be possible then to remember what targets the team had, then get them to forget, and then give them all the target again (except the AT/AA) ?

Now they can!

 

Cheers!

  • Like 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

×