Jump to content
Blitzen88

AI Squadmates not moving to a Building Position Occupied by Enemy AI?

Recommended Posts

Got a "clear building script" that orders friendly squad mates to move from building position to building position to clear a building.  Script works great but squad mates will not move to a building position that is occupied by an enemy AI.  For example, if an enemy AI is in building position #5 then the AI squad mates will move to positions 1, 2, 3, 4, and then stop at #4.

 

Is there anyway to fix this?  Here is the script:

 

/*==========================================================================================

			Arma III AI Squad Mates Clear Building

Created by WWI AI Mod

Edited by Blitzen

===========================================================================================

* WARNING: Script can be BUGGY!

* Orders a player's AI squad mates to clear the building that the player is looking at

* Intended to allow a player to quickly and, with as little headaches as possible, clear a building

* Call with (Radio Trigger): Null = execVM "Scripts\Support\Support_PlayerGrpGarrison.sqf"

===========================================================================================*/

// Define Variables for the Clear Building Function
//---------------------------------------

//Define some variables for the rest of the script
_PlayersGroup = group player;

_PlayerSquadMates = (units _PlayersGroup - [player]);

//Save the Cursor target building
_TargetedBuilding = Cursorobject;

//Get Building positions from the building & count them
_BuildingPos = _TargetedBuilding buildingpos -1;

_BuildingPosCount = count _BuildingPos;

//Call out / ID the building
Player groupChat format ["Roger, clearing %1. Setting status to Careless",getText (configFile >> "CfgVehicles" >> (typeOf _TargetedBuilding) >> "displayName")];

//Cancel the script if no building positions are found
if ((_BuildingPosCount) == 0) exitWith {Player groupChat "Unable to clear building - No building positions detected";};

// Create a Clear Building Function
//---------------------------------------

Blitz_fnc_ClearBuilding =
{
	//Define/Re-Define "New" Variables and make them private variables for the function

	private ["_unit","_BuildingPosCount", "_CurrentBuildingPos", "_Building"];

	_unit = _this select 0;

	_BuildingPosCount = _this select 1;

	_Building = _this select 2;
	
	_CurrentBuildingPos = 0;

	_unit setbehaviour "CARELESS";

	//Start the Movement Loop
	while {_CurrentBuildingPos <= _BuildingPosCount} do {
		
		_unit doMove (_Building buildingpos _CurrentBuildingPos);
		
		waitUntil {( unitReady _unit ) || !( alive _unit ) || (((expectedDestination _unit) select 1)!= "DoNotPlan" && ((expectedDestination _unit) select 1)!= "LEADER PLANNED")};

		if(((expectedDestination _unit) select 1)!= "DoNotPlan" && ((expectedDestination _unit) select 1)!= "LEADER PLANNED") exitWith {};

		_CurrentBuildingPos = _CurrentBuildingPos + 1;

	//End the Movement Loop
	};

	_unit setbehaviour "AWARE";
	
	[_unit] joinSilent (group player);

};


// Have Units Call/Exec the Newly Created Function
//---------------------------------------
{ [_x, _BuildingPosCount, _TargetedBuilding] spawn Blitz_fnc_ClearBuilding }foreach _PlayerSquadMates;

 

Share this post


Link to post
Share on other sites

Idk if it solves ur problem but after reading the comments of the biki entries for setBehavior and doMove I would suggest to move the line with setBehavior right after the doMove line inside the while loop.

 

Also there should be another mistake related to building position indexes. If you have 5 positions then the indexes will be 0, 1, 2, 3, 4. In the script you are processing the while from 0 to 5. This should produce an error for the last, not existing position.

The fix is simple. Just use < instead of <= in ur while condition.

Share this post


Link to post
Share on other sites

I was on an advanced waypoint for clearing buildings. Very similar to your script, with repartition of near buildings on team mates disembarking or not from vehicles.
In short, I gave up because:

- buildings have or not building positions...

- even if building have positions, that doesn't mean these positions are reachable (need paths to them)...

- even if buildings have position(s) and path(s), that doesn't mean a unit can't be stuck, by steps, doors, ladders... I played with little teleportations, detecting as I can a unit stuck (endless animation on top of ladder, destination not reached...). That really sucks;

- but the cherry on the cake is the weird behaviors when AIs fall in combat state (AIs jumping to ground from 3rd floor as example)

So, if you succeed in this kind of script, please share.

 

Share this post


Link to post
Share on other sites

Idk if you guys know bout @johnnyboys attempt to move ai through buildings.

I never tested it but its the most promising i ever saw:

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
9 hours ago, sarogahtyp said:

Idk if you guys know bout @johnnyboys attempt to move ai through buildings.

I never tested it but its the most promising i ever saw:

Thanks.  It definitely works, but requires pre-recording paths through buildings.  So can be useful for scripted missions and cutscenes, but not good for dynamic play.

  • Like 1

Share this post


Link to post
Share on other sites
On 7/6/2021 at 3:36 AM, sarogahtyp said:

Idk if it solves ur problem but after reading the comments of the biki entries for setBehavior and doMove I would suggest to move the line with setBehavior right after the doMove line inside the while loop.

 

Also there should be another mistake related to building position indexes. If you have 5 positions then the indexes will be 0, 1, 2, 3, 4. In the script you are processing the while from 0 to 5. This should produce an error for the last, not existing position.

The fix is simple. Just use < instead of <= in ur while condition.

Would disabling the default AI combat behavior work?

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

×