Jump to content
Sign in to follow this  
garnett21a

Tactical single building search script

Recommended Posts

UPDATED:deleted as many unnecessary variables as possible

This is not used for a random AI patrol function but a specific tactical move.

The idea is from search and rescue/capture mission, to give the player an order to his team to storm a building in combat status.

It is heavily referenced the AHP scripts and simplised it. At least I think it looks more smooth or I say more "tactical".

What this script does:

Give player the action (or use use on AI leader's closest building)===========> 4 of the group members would search the building the leader is aiming at from two directions and meet eventually =========> while some others would patrol outside the house. ======> and would fall back to formation after the search at the same behaviour before script.

Only automatically stops when 2 or more men were killed during the search. I was making this one for player grp leader. and if use on AI group, use "StarSearch.sqf" only.

I tested some buildings on Takistan and Za. Not sure how throughly the team would clear the house, but at least they are always on the move :p.

Questions

1. Can someone tell how to add some lines so that this script could be MP Capatible? I'm totally new to that.

2. When using "moveToCompleted/Failed" to check status, I always get no value back when using hint commands to debug, and units just stuck there. What phrase can I use to check the value when a unit radios " No can do / Negative"?

Script Intro

init.sqf:

mysrchaction = 1;

player addAction ["Clear Target Building", "StartSearch.sqf", [group player], 1, 
 false, true, "", "mysrchaction == 1"];

player addAction ["Stop the Search", "StopSearch.sqf", [group player], 1, 
 false, true, "", "mysrchaction == 0"];

StartSearch.sqf:

		// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
	//   nil = [groupname] execVM "StartSearch.sqf"
	// = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


private ["_grp1", "_cB", "_cnt", "_unitsInGrp", "_srchunit1", "_srchunit2", "_srchunit3", "_srchunit4", "_srchteam", "_bh", "_sryteam", "_cBParray", "_i", "_cBP", "_cBP1", "_bBX", "_bBY", "_timeout"];



_grp1 = _this select 0;

if ((leader _grp1) == player) then { _cB = cursorTarget} else { _cB = nearestBuilding (leader _grp1) };

sleep 0.1;

mysrchaction = 0;

	// = = = = = = = = = = = = = = = = = = 
	//  SETTING GROUP MEMBERS
	// = = = = = = = = = = = = = = = = = =

_unitsInGrp = (units _grp1) - [(leader _grp1)];

_cnt = count _unitsInGrp;

if (_cnt < 2) exitWith { leader _grp1 groupchat "No enough men"; mysrchaction = 1; };

if (_cnt >= 2) then
{
_srchunit1 = _unitsInGrp call BIS_fnc_selectRandom;
_srchunit2 = (_unitsInGrp - [_srchunit1]) call BIS_fnc_selectRandom;
_srchteam = [_srchunit1, _srchunit2];	
};

if (_cnt >= 3) then 
{
_srchunit3 = (_unitsInGrp - [_srchunit1, _srchunit2]) call BIS_fnc_selectRandom;
_srchteam = _srchteam + [_srchunit3];
};

if (_cnt >= 4) then 
{
_srchunit4 = (_unitsInGrp - [_srchunit1 ,_srchunit2, _srchunit3]) call BIS_fnc_selectRandom;
_srchteam = _srchteam + [_srchunit4];
};

if (_cnt >= 5) then {_sryteam = (_unitsInGrp - _srchteam) } else {_sryteam = nil};


_bh = behaviour _srchunit1;

sleep 0.5;

	// = = = = = = = = = = = = = = = = = = 
	//  GET ALL POSITIONS OF BUILDING
	// = = = = = = = = = = = = = = = = = = 

_cBParray = [];
_i = 0;

while {format ["%1",_cB buildingPos _i] != "[0,0,0]"} do
{
_cBParray = _cBParray + [_i];
_i = _i + 1;
};

sleep 1;
leader _grp1 groupchat "Clear the building";

	// = = = = = = = = = = = = = = = = = = = = = =
	//  SELECT BUILDING POS OF CURRENT BUILDING
	// = = = = = = = = = = = = = = = = = = = = = =  

_i = 0;

while {(_i < count _cBPArray) and (mysrchaction != 1) } do
{

sleep 0.5;

if ( _cnt - ({alive _x} count _unitsInGrp) >= 2 ) exitWith
{
	leader _grp1 groupchat "Taking heavy enemy fire in building. Terminate the Searching procedure immediately. out";
	sleep 0.5;
	{_x setUnitPos "AUTO"} foreach _srchteam;
	{_x setBehaviour _bh} foreach _unitsInGrp;
	{_x setSpeedMode "NORMAL"} foreach _unitsInGrp;
	SLEEP 0.5;
	{_x dofollow leader _grp1} foreach _unitsInGrp;
	mysrchaction = 1;
};

sleep 0.2;

_cBP = _cBPArray select _i;
_cBP1 = _cBPArray select ( ((count _cBPArray) -1) - _i);

_i = _i + 1;

_bbX= (((boundingBox _cB) select 1) select 0)+ round random 5;
_bbY= (((boundingBox _cB) select 1) select 1) + round random 5;

_bbX = if (random 1 < 0.5) then {_bbX} else {_bbX*-1};
_bbY = if (random 1 < 0.5) then {_bbY} else {_bbY*-1};

sleep 1;

		// = = = = = = = = = = = = = = = 
		//  SEARCHING TEAM MOVE TO BUILDING POSITIONS
		// = = = = = = = = = = = = = = =  

_srchunit1 domove (_cB buildingPos _cBP);
if (_cnt >= 3) then {_srchunit3 doMove (_cB buildingPos _cBP1);};

sleep 1;

_srchunit2 doMove (_cB buildingPos _cBP);
if (_cnt >= 4) then {_srchunit4 doMove (_cB buildingPos _cBP1);};

		// = = = = = = = = = = = = = = = 
		//  SERCURITY TEAM MOVE AROUND THE BUILDING
		// = = = = = = = = = = = = = = =  	

sleep 1;
if (_cnt >= 5) then {_sryteam call BIS_fnc_selectRandom domove [(getpos _cB select 0)+_bbX ,(getpos _cB select 1)+_bbY,0]};	

		// = = = = = = = = = = = = = = = 
		//  WAIT WHILE GROUP MEMBERS MOVING
		// = = = = = = = = = = = = = = =  	

sleep 0.1;
waitUntil { unitReady _srchunit1 or (_srchunit1 distance (_cB buildingPos _cBP)) <= 5 };

{_x setBehaviour "COMBAT"} foreach _unitsInGrp;
{_x setSpeedMode "NORMAL"} foreach _srchtram;
{_x setUnitPos "UP"} foreach _srchteam;	
{_x setSpeedMode "LIMITED"} foreach _sryteam;
sleep 0.1;

if (_cnt >= 3) then
{
	waitUntil { unitReady _srchunit3 or (_srchunit3 distance (_cB buildingPos _cBP1)) <= 5 or !(alive _srchunit3) };
};

sleep 0.1;	

_timeout = time + 20;	

sleep 0.1;

while { _timeout > time } do
{
	waitUntil 
	{ 	
		{ unitReady _x or !(canMove _x) or stopped _x or !(alive _x) } foreach _srchteam;
	};
	hint "1";
	_timeout = time - 20;
};

if ((_cBP1 - _cBP) <= 1) exitWith 
{
		leader _grp1 groupchat "Building secured";
		sleep 0.5;
		{_x setUnitPos "AUTO"} foreach _srchteam;
		{_x setBehaviour _bh} foreach _unitsInGrp;
		{_x setSpeedMode "NORMAL"} foreach _unitsInGrp;
		SLEEP 0.5;
		{_x dofollow leader _grp1} foreach _unitsInGrp;
		mysrchaction = 1;
} ;

sleep 0.5;	
_srchteam call BIS_fnc_selectRandom groupchat "Sector clear. Proceeding";
sleep 0.5;	
_sryteam call BIS_fnc_selectRandom groupchat " Securing the perimeter";


};

sleep 0.5;

if (mysrchaction == 0) exitWith 
{ 

leader _grp1 groupchat "Building secured";
sleep 1;
{_x setUnitPos "AUTO"} foreach _srchteam;
{_x dofollow leader _grp1} foreach _unitsInGrp;
{_x setBehaviour _bh} foreach _unitsInGrp;
{_x setSpeedMode "NORMAL"} foreach _unitsInGrp;
mysrchaction = 1;
};

StopSearch.sqf: (in case player want to stop it manually)

private ["_grp0"];


_grp0 = _this select 0;

sleep 1;

if (true) then 
{ 

mysrchaction = 1;
leader _grp0 groupchat "Stop the Search Procedure and return to formation";
sleep 1;
{_x setUnitPos "AUTO"} foreach units _grp0;
{_x dofollow leader _grp0} foreach units _grp0;
{_x setBehaviour "AWARE"} foreach units _grp0;
};

Pls take a test if anyone is interested in this. and by the way, I'm quite new too scripting, so guess all the credits to those who created the great scripts I have referenced !!!! A lot thanks if you could leave any feedback or comments:butbut::butbut::butbut:. ;)

Edited by garnett21a
deleted as many unnecessary variables as possible and shortened the structure with better commands

Share this post


Link to post
Share on other sites

Hi mate... You should use the "code" or "php" tags to post code. It will be easier for us to read.

You can still use the "spoiler" tags... just wrap it around the code tags.

Share this post


Link to post
Share on other sites

Made some improvements

to change the statuse check so the team moves more time effeciently.

and fixed some bugs I found

that happens when grp number varies from 2 to N or died during search.

Updated version on #1.

Pls some one give some feedback to me if this really works

Edited by garnett21a

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  

×