PHP Code:
// ALL INFANTRY UNITS ON MAP WILL DROP IF ANY BULLETS PASS WITHIN 10m
// BULLETS FIRED FROM LESS THAN 20m ARE IGNORED
// BULLETS FROM SMG AND PISTOLS ARE IGNORED
// Original code idea by -Coulum-
// TPW 20120620
//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};
private ["_supnextime","_unit","_bc","_shots","_dist"];
//Pistol and SMG ammo to ignore
tpw_mags =["30rnd_9x19_MP5",
"30rnd_9x19_MP5SD",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9SD",
"7Rnd_45ACP_1911",
"8Rnd_9x18_Makarov",
"8Rnd_9x18_MakarovSD",
"64Rnd_9x19_Bizon",
"64Rnd_9x19_SD_Bizon",
"13Rnd_9mm_SLP",
"17Rnd_9x19_glock17",
"6Rnd_45ACP",
"30Rnd_9x19_UZI",
"30Rnd_9x19_UZI_SD"];
//Main function
tpw_sup =
{
{
_unit = _x;
if (vehicle _x == _x) then
{
_SupNextTime = _unit getVariable ["SupNextTime", -1];
if (_SupNextTime == -1) then
{
_unit setvariable ["SupAccuracy",_unit skill "aimingAccuracy"];
_unit setvariable ["SupShake",_unit skill "aimingshake"];
_unit setVariable ["SupNextTime", diag_tickTime];
_unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
};
if (diag_tickTime >= _SupNextTime) then {_unit setVariable ["Shots", 0]};
_bc = 0;
if !(isnull tpw_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["Bulletbase",10])
};
if (_bc > 0) then
{
_dist = tpw_fired distance _unit;
if (_dist > 25) then
{
if !(tpw_mag in tpw_mags) then {
_unit setVariable ["SupNextTime", diag_tickTime + 3 + random 5];
_shots = _unit getVariable "Shots";
_unit setVariable ["Shots", _shots + _bc];
}
}
};
_shots = _unit getVariable "Shots";
_accuracy = _unit getvariable "SupAccuracy";
_shake = _unit getvariable "SupShake";
if (_shots == 0) then {_unit setunitpos "auto"};
if (_shots > 0) then {_unit setunitpos "middle"; _accuracy = _accuracy * 0.75; _shake = _shake * 0.75};
if (_shots > 5) then {_unit setunitpos "down"; _accuracy = _accuracy * 0.5; _shake = _shake * 0.5};
_unit setskill ["AimingAccuracy",_accuracy];
_unit setskill ["AimingShake",_shake];
}
} forEach allunits;
};
//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;