//Checks for contact by using the findNearestEnemy command: in short it returns <null> if there are no enemies, otherwise it will return an enemy. The command checks each unit in the array separately, and if anyone has a contact, they will cry out. They will cry contact only if it's a new enemy group that is 'spotted': if the enemy group has been spotted before, it won't cause the sound to play. It will also play a random second sound when there are null nearest enemies.;

_array = _this select 0;
_units = _this select 1;

_j=0;
_i= {alive _x} count _units;
_curEnemyGrp = GrpNUll;
_lastEnemyGrp = GrpNull;
_isContact = false;

while {{alive _x} count _units > 0 && RUG_DSAI_TerminalDistance != -1} do
{
_i = {alive _x} count _units;
_curUnit = _units select _j;

	if (!isNull (_curUnit findNearestEnemy _curUnit)) then
	{
	_contact = _curUnit findNearestEnemy _curUnit;
	_isContact = true;
	_sameGrp = true;
	_curEnemyGrp = group (_contact);
	if (_curEnemyGrp != _lastEnemyGrp && alive _contact) then {_lastEnemyGrp = _curEnemyGrp; _sameGrp = false};
	private ["_Sounds", "_unit", "_random2"];
	_Sounds = (call _Array) select 0;
	_random2 = floor (random (count _Sounds));
	_unit = _curUnit;
	if (_unit !=Player && !_sameGrp && vehicle _unit == _unit) then {_unit say (_Sounds select _random2)};
	sleep ((random 5) + 10);
	};

	if (isNull (_curUnit findNearestEnemy _curUnit) && _isContact) then
	{
	sleep 5;
	_isContact = false;
	private ["_Sounds", "_unit", "_random2"];
	_Sounds = (call _Array) select 1;
	_random2 = floor (random (count _Sounds));
	_unit = _curUnit;
	if (_unit !=Player && isNull (_curUnit findNearestEnemy _curUnit) && vehicle _unit == _unit) then {_unit say (_Sounds select _random2)};
	};

if (_j < _i) then {_j = _j + 1} else {_j = 0};
sleep 2;		
};