Jump to content
Sign in to follow this  
NakedSquirrel

AI, Guerrilla Tactics

Recommended Posts

I've been trying to get AI to do more 'hit and run' style attacks for some of my missions, but I've found myself at a bit of a road block because I've mostly been using triggers and waypoints.

The trouble with the in game AI is that they will usually do a full on assault and maybe flank the enemy, but they tend to try and stay in the engagement until the enemy is dead or until they've taken considerable casualties. I would like it more if I could get the AI to do a short attack (maybe a minute or two of fire) and then disengage (maybe to come back later once they've re-grouped).

Does anyone know of a script that would make the AI do more of a hit and run style attack instead of a full on assault? Or does anyone at least know of a script I can use as a starting point to try and get the AI to do this sort of behavior?

What I would basically want to do is get a script that sets their behavior to 'danger' and give them a seek and destroy waypoint near the player group (or nearest enemy group). (Perhaps give the AI a suppressive fire command for more volume of fire) Then after a minute or two, have the script set a waypoint far away from the player group and in the opposite direction.

Edited by trueapothecary

Share this post


Link to post
Share on other sites

Was having a play to see if I could do this easily for you. I was trying scripted waypoints and setWaypointTimeOut. That just won't work!

I think the script will have to detect when the squad starts engaging and then start a timer. After the timer times out... then give them a waypoint with behaviour careless etc... to pull back to.

I went digging and it's not going to be that simple to find out when the squad is engaging! There's this script here in a post from ruebe... but other than that the only other thing I can think of is to add a "fired" evenhandler to each member of the group.

As with everything else...maybe somebody else will have a clearer view to an easier solution.

Share this post


Link to post
Share on other sites

Apart from Ruebe's method or fired EH (probably sufficent however), to determine, when group is "engaging" can be used several factors, optionally (optimally?) combined somehow with previous mentioned, dependent of needs. Two of them, that come to my mind at the moment:

1. Knowledge factor - if opposite groups know about each other;

2. and/or if distance between closest units from these groups is small enough.

As for "run" after "hit" - as for my experience this is impossible to perform only with waypoints/behaviour. This is needed too, but not sufficient - group will often remain "stick" to the enemy. Tested that some time ago, also with "GREEN" or even "BLUE" combat modes. Best known to me method is messing with allowFleeing and maybe setSkill "courage" (not know, what is the difference between these two). Reduce courage to minimum and/or set allowFleeing to 1 for running behaviour, after some time (distance/knowledge conditions met), reset them. I'm planning to test such methods for HAC's guerilla Leader mode. Placing some smoke, if available, may help too. You can also try with some invisible view blockers, I saw such things somewhere, can't remember, where exactly.

Edited by Rydygier

Share this post


Link to post
Share on other sites

to check if group is attacking, i would say the easiest way is to check what behaviour the units are in, afaik ai automaticly goes to danger when they start firing, and if you dont want the group running in to contact in aware mode you could maybe use stealth behaviour in the WP assignment.

Edit:

As for making the units run away after the fight i would use a WP with behaviour careless combined with setspeedmode full and combatmode never fire for a couple of 100m (or so depending on LOS to the enemy) to get the ai to break the contact, after that you could set the behaviour back to aware to react to units chasing them

Edited by subroc
added some stuff

Share this post


Link to post
Share on other sites
As for making the units run away after the fight i would use a WP with behaviour careless combined with setspeedmode full and combatmode never fire for a couple of 100m (or so depending on LOS to the enemy) to get the ai to break the contact,

This doesn't work. Well. This doesn't work in my case, when tried in HAC such method for withdrawal. Tested on A2 1.10, maybe in OA 1.60 something is different here.

Share this post


Link to post
Share on other sites

ok, then my best guess is the moveTo i dont know how this command works though, but as it seems to be a lowlevel command it might make it top prio to actually move instead of fighting enemies.

Share this post


Link to post
Share on other sites

Ok, revisiting this old thread to let you guys know I finally figured out a way to do it. by changing the friendstate. Unfortunately, it didn't let me change the friendstate of individual units (except for civilians), so you have to do it to an entire side.

It's cheating, but it seems to be the only way that I have been able to come up with that works. You simply have a trigger of 'bluefor detects opfor' set the timeout duration of how long you want the firefight to happen before OPFOR will disengage, and then on activation use the set friend command "EAST setFriend [WEST, 1];" Once they reach a secure area you can return their friendstate to 0.

In theory, the AI should stop and shoot any any 'Rambo' players that sprint up to catch them, because he will lose his friendstate with them after they see him shoot a couple of comrads

Domove, setting waypoints, and messing around with their courage didn't seem to have any effect. I've also tried setting a group leader that is on the other side of a map, but he seems to issue commands for them to engage (no matter what I do with "Disableai "xxx"" commands). That was my most promising because it works for the player, but the AI won't just sit there and shut his trap.

The only other mild success I've had is physically removing their weapons and ammo, but I find that to be a bit extreme because if I want them to re-enter combat I have to individually re-arm them with specific loadouts.

Anyhow, hopefully this helps someone else out there. I think it would be pretty useful for guerrilla warfare scenarios, convoy attacks, feigned assaults, traps, and ambushes.

Share this post


Link to post
Share on other sites

Let's do some necromancy here... Recently I started seriously with guerilla/occupation ambient project, so also tried to solve disengage problem. Subroc was close, but moveTo is for FSMs, here is used doMove. With not bad results. Here is the code:

RYD_Disengage = 
{
private ["_gp","_tgt","_side","_cnt","_mode","_group","_tempGps","_units","_start","_tgtPos","_units","_alive","_enabledA","_beh","_cm","_units0","_isStuck"];

_gp = _this select 0;
_start = getPosATL (vehicle (leader _gp));
_tgt = _this select 1;
_side = side _gp;
_mode = 0;
if ((count _this) > 2) then {_mode = _this select 2};

[_gp, (currentWaypoint _gp)] setWaypointPosition [position (vehicle (leader _gp)), 0];

while {((count (waypoints _gp)) > 0)} do
	{
	 deleteWaypoint ((waypoints _gp) select (count (waypoints _gp) - 1))
	};

_enabledA = attackEnabled _gp;
_gp enableAttack false;

_beh = "CARELESS";
_cm = "BLUE";

if (_mode >= 1) then
	{
	_beh = "AWARE";
	_cm = "GREEN"
	};

_tempGps = [];
_units = units _gp;

	{
	_x setUnitPos "UP";
	_x disableAI "TARGET";
	_x disableAI "AUTOTARGET";

	if (_mode >= 2) then
		{
		_group = createGroup _side;
		_tempGps set [(count _tempGps),_group];
		[_x] joinSilent _group;
		};

	_tgtPos = [(_tgt select 0) + (random 20) - 10,(_tgt select 1) + (random 20) - 10,0];
	_x doMove _tgtPos;
	_x setVariable ["tgtPos",_tgtPos];
	_x setVariable ["isStuck",0];

	if (_mode >= 2) then
		{
		_group setBehaviour _beh;
		_group setSpeedMode "FULL";
		_group setCombatMode _cm
		}
	}
foreach (units _gp);

if (_mode < 2) then
	{
	_gp setBehaviour _beh;
	_gp setSpeedMode "FULL";
	_gp setCombatMode _cm
	}
else
	{
	deleteGroup _gp
	};

waitUntil
	{
	sleep 5;

	_units0 = +_units;

		{
		if (isNull _x) then 
			{
			_units = _units - [_x]
			}
		else
			{
			if not (alive _x) then
				{
				_units = _units - [_x]
				}
			else
				{
				if ((abs (speed _x)) < 0.01) then 
					{
					_isStuck = _x getVariable "isStuck";
					if (_isStuck > 12) exitWith
						{
						_units = _units - [_x];
						_x setVariable ["tgtPos",nil];
						_x setVariable ["isStuck",nil];
						};

					_x setVariable ["isStuck",_isStuck + 1];
					_tgtPos = _x getVariable "tgtPos";
					_x doMove _tgtPos;
					}
				else
					{
					_x setVariable ["isStuck",0]
					}
				}
			}
		}
	foreach _units0;

	_cnt = {(((_x distance _tgt) > 30) and ((_x distance _start) < (_start distance _tgt)))} count _units;

	(_cnt == 0)
	};

if (_mode >= 2) then
	{
	_gp = createGroup _side;

		{
		[(leader _x)] joinSilent _gp;
		deleteGroup _x
		}
	foreach _tempGps
	};

	{
	_x setVariable ["tgtPos",nil];
	_x setVariable ["isStuck",nil];
	_x setUnitPos "AUTO";
	_x enableAI "TARGET";
	_x enableAI "AUTOTARGET";
	}
foreach (units _gp);

_gp setBehaviour "AWARE";
_gp setSpeedMode "NORMAL";
_gp setCombatMode "YELLOW";
_gp setFormation "WEDGE";

if (_enabledA) then {_gp enableAttack true}
};

Usage:

Mode 0 - group alredy engaged in combat will just run towards set position (most reliable, works fine even on minimal distance between fighting groups):

[_group,_runPos,0] spawn RYD_Disengage

Mode 1 - group alredy engaged in combat will run towards set position with some covering fire (not as reliable, as 0, because some units still can stuck (perhaps these with already active engage (Rambo-like-sturm-alone-urra!) order, before code disbles this thing; the closer to the enemy, the less reliable). There is anti-stuck code, but effect is less elegant anyway):

[_group,_runPos,1] spawn RYD_Disengage

Mode 2 - as above, but with additional thing, that can help sometimes, eg on minimal distances, - groups is divided to the pack of one-man groups, so we have in fact dozen or so disengaging groups. When target reached - group is re-established again:

[_group,_runPos,2] spawn RYD_Disengage

Edited by Rydygier

Share this post


Link to post
Share on other sites

another way is using nearTargets and running a check every x amount of time on the threat level(to check when they engage)

Share this post


Link to post
Share on other sites

Nice work, dude! I've been tinkering with that myself without ever getting any satisfying results. Will check out soon!

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
Sign in to follow this  

×