Check my ROMM_IA script, for readability I have replaced all the letters with appropriate variable names, the basis of this script is to make AI hit the deck when under fire and stay down while under continuous fire; and to make the AI fire back in your general direction.
/*
ROMM_IA.sqf;
Version: 112 [14, 06, 2008];
Author(s): Rommel
Execution: nul = [group this] call compile preProcessFile "ROMM_IA.sqf";
*/
if !(isServer) exitWith {};
_formA =
{
_grp = _this select 0;
_spd = _this select 1;
_beh = _this select 2;
_form = _this select 3;
_leader = leader _grp;
{_x doFollow _leader; _x setUnitPos "AUTO";} forEach units _grp;
_grp setCombatMode _beh;
_grp setSpeedMode _spd;
_grp setFormation _form;
_bool = false;
};
_formB =
{
private ["_grp", "_dir", "_ovrwtch", "_unit"];
_grp = _this select 0;
_dir = _this select 1;
_grp setCombatMode "YELLOW";
_grp setSpeedMode "FULL";
_grp setFormation "LINE";
_ovrwtch = [];
{_unit = _x; {if (_unit hasWeapon _x) then {_ovrwtch = _ovrwtch + [_unit]};} forEach ["M249","M240","PK"];} forEach units _grp;
{[_x, _bool, _dir] spawn _formC} forEach units _grp;
_bool = true;
{[_x, _dir] spawn _formD} forEach _ovrwtch;
sleep 8.0;
{[_x, _dir] spawn _formD} forEach units _grp - _ovrwtch;
};
_formC =
{
private ["_unit", "_bool", "_dir", "_y"];
_unit = _this select 0;
_bool = _this select 1;
if (_bool) exitWith {};
_unit setUnitPos "DOWN";
if (count _this > 1) then
{
_dir = _this select 2;
_unit commandWatch [(getPos _unit select 0)+ sin(_dir) * 43,(getPos _unit select 1)+ cos(_dir) * 43, (getPos _unit select 2) + 1];
};
_bool = _unit findCover [getPos _unit, getPos _unit, 43];
_y = (_unit distance _bool) / 2;
_unit commandMove getPos _bool;
sleep _y;
commandStop _unit;
sleep _y;
_unit commandMove getPos _bool;
if (floor(random 10) > 9) then
{
_unit setUnitPos "AUTO";
};
};
_formD =
{
private ["_unit", "_dir", "_i", "_t", "_form","_v"];
_unit = _this select 0;
if (primaryWeapon _unit in ["M24", "M107", "SVD"]) exitWith {};
_dir = _this select 1;
_t = "Logic" createVehicleLocal [0,0,0];
_form = _unit findNearestEnemy getPos _unit;
if !(vehicle _form in crew _form) exitWith {};
_i = 0;
while {(alive _unit) AND (_i < 14)} do
{
_unit commandWatch position _form;
sleep (random 7.0);
_v = (((getPos _form select 0) - (getPos _unit select 0)) atan2 ((getPos _form select 1) - (getPos _unit select 1))) +360 % 360;
if (abs _v < 25) then
{
_t action ["useWeapon",_unit,_unit,1];
};
_i = _i + 1;
};
deleteVehicle _t;
};
private ["_grp", "_i", "_bool","_spd", "_beh", "_leader", "_dir", "_t", "_ovrwtch", "_ovrwtchd", "_c"];
_grp = _this select 0;
_i = {alive _x} count units _grp;
_bool = false;
_spd = speedMode _grp;
_beh = combatMode _grp;
_form = formation _grp;
_c = -1;
While {_i > 0} do
{
if (isNull _grp) exitWith {};
If (_i > count units _grp) then
{
{[_x, _bool] spawn _formC} forEach units _grp;
_c = _t + 143;
_i = {alive _x} count units _grp;
};
_leader = leader _grp;
_dir = getDir _leader;
_t = time;
if (!(isNull _leader)) then
{
_ovrwtch = nearestObject [_leader, "BulletBase"];
If (!(isNull _ovrwtch)) exitWith
{
_ovrwtchd = getDir _ovrwtch - 180;
If ((_ovrwtchd < _dir + 109 AND _ovrwtchd > _dir - 109) OR (_ovrwtchd > _dir + 109 AND _ovrwtchd < _dir - 109)) then
{
[_grp, _ovrwtchd] call _formB;
_c = _t + 143;
};
};
_ovrwtch = nearestObject [_leader, "GrenadeHand"];
If (!(isNull _ovrwtch)) exitWith
{
{[_x, _bool] spawn _formC} forEach units _grp;
_bool = true;
_c = _t + 43;
};
_ovrwtch = nearestObject [_leader, "G_40mm_HE"];
If (!(isNull _ovrwtch)) exitWith
{
{[_x, _bool] spawn _formC} forEach units _grp;
_bool = true;
_c = _t + 23;
};
_ovrwtch = nearestObject [_leader, "RocketCore"];
If (!(isNull _ovrwtch)) exitWith
{
{[_x, _bool] spawn _formC} forEach units _grp;
_bool = true;
_c = _t + 33;
};
_ovrwtch = nearestObject [_leader, "ShellCore"];
If (!(isNull _ovrwtch)) exitWith
{
{[_x, _bool] spawn _formC} forEach units _grp;
_bool = true;
_c = _t + 23;
};
_ovrwtch = nearestObject [_leader, "MissileCore"];
If (!(isNull _ovrwtch)) exitWith
{
{[_x, _bool] spawn _formC} forEach units _grp;
_bool = true;
_c = _t + 43;
};
};
If (_c != -1 AND _t > _c) then
{
[_grp, _spd, _beh] call _formA;
_c = -1;
};
sleep 1.0;
};