Jump to content
Blitzen88

Need Help Exiting an AI clear building script

Recommended Posts

Greetings,

 

I am fooling around with a very basic script, called via a radio trigger, which orders a player's AI squad mates to "clear" a targeted building.  AI squad mates "clear" the building by moving, one after another, to each building position.

 

Although the AI can clear small buildings relatively well, with the AI being what it is, they sometimes get hung up.  Is there anyway to build in an "If condition exitwith" statement which will exit the script if the squad mates are given a return to formation command (ie dofollow player)?

 

I tried something like:

 if (_Playersquadmates !dofollow player) then {} else {exit}

With the idea being that the AI squad mates are not following the player when they are moving to a position.  If they were issued a regroup command then they would be following the player and the script would end.  However, it didnt work.  Does anyone have any ideas?

 

Here is what I got:

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

_PlayerSquadMates = (units _PlayersGroup - [player]);

_PlayerSide = side Player;

_OriginalFormation = formation _PlayersGroup;

//Save the Cursor target building
_Building = Cursorobject;

//Get Building positions from the building and count them
_BuildingPos = _Building buildingPos -1;
_BuildingPosCount = count _BuildingPos;

//Try to sort the Building Positions in ascending order (closest to farthest) 
_BuildingPos sort true;

//Dont try to run the loop if all of the squadmates are dead
if ((count _PlayerSquadMates) == 0) exitWith {};

//Dont try to run the loop if there are no building positions
if ((count _BuildingPos) == 0) exitWith {player groupchat "Unable to clear the building - no builiding positions detected"};

//Acknowledge the command
Player groupChat " Roger, Clearing building";

//Put the units into a File formation before they clear the building
{_x setformation "FILE"} foreach _PlayerSquadMates;

//Start the Loop
while {_BuildingPosCount > 0} do {



	//Select the first Building Position
	_position = _BuildingPos select 0;
	
	//Remove the Building Position from the array	
	_BuildingPos = _BuildingPos - [_position];

	//Subtract a Building Position/Number from the Building Count
	_BuildingPosCount = _BuildingPosCount - 1;

	//Order the Units to the designated Position		
	{_x doMove _position; sleep 1} foreach _PlayerSquadMates;

		waituntil { 

			{unitReady _x} foreach _PlayerSquadMates;

			};
		
		sleep 1;

};


Player groupChat "Building cleared, returning to formation";

{_x dofollow leader _PlayersGroup} foreach _PlayerSquadMates;

{_x setformation _OriginalFormation} foreach _PlayerSquadMates;

 

Share this post


Link to post
Share on other sites

I think the script could be exited by using the currentCommand feature.  Something like:

if ( currentCommand _unit == "STOP" ) then { exit } else { *code*}

However,  I cant figure out how to implement it into the code.

 

This way, the script should end if the units are given a stop command.

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

×