PHP Code:
/*
TPWC AI SUPPRESSION
Authors: TPW & -Coulum-
Last changed: 20120623
*/
////////////
//VARIABLES
///////////
//Suppression type. 1 = basic , 2 = light, 3 = full
tpwc_ai_sup_type = 3;
//Delay before suppression functions start. Allows time for other AI mods to set unit skills
tpwc_ai_sup_sleep = 25;
//Debugging. Will display red balls over any suppressed units. Set to 1 for debugging
tpwc_ai_sup_debug = 0;
//Bullet detection radius (m). Bullets must pass within this distance of unit to suppress them. If set much below 10m, bullets may not be detected
tpwc_ai_sup_br = 10;
//Bullet ignore radius (m). Bullets from a shooter closer than this will not suppress.
tpwc_ai_sup_ir = 25;
//Shot threshold. More shots than this will cause unit to drop/crawl
tpwc_ai_sup_st = 5;
//Pistol and SMG ammo to ignore. Add custom ammo (eg suppressed) or change to taste
tpwc_ai_sup_mags =["30rnd_9x19_MP5",
"30rnd_9x19_MP5SD",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9SD",
"7Rnd_45ACP_1911",
"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"];
//////////
// SET UP
//////////
//Declare private variables
private ["_stanceregain","_skillregain","_unit","_bc","_shots","_originalaccuracy","_originalshake","_originalcourage","_general","_ball"];
//Allow time for ASR AI skills to propagate
sleep tpwc_ai_sup_sleep;
//Start hint
0 = [] spawn {sleep 3; hintsilent "AI Suppress Active"; sleep 3; hintsilent ""};
//////////////////
// MAIN FUNCTIONS
//////////////////
//Basic version
tpwc_ai_sup_basic =
{
{
if (alive _x) then
{
_unit = _x;
_stanceregain = _unit getvariable ["stanceregain", -1];
if (_stanceregain == -1) then
{
_unit setvariable ["stanceregain", diag_ticktime];
_unit addeventhandler ["fired",{tpwc_ai_sup_fired = _this select 0;tpwc_ai_sup_bullet = _this select 6}];
_ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["supball",_ball];
};
if ( diag_ticktime >= _stanceregain) then
{
_ball = _unit getvariable "supball"; _ball hideobject true;
_unit setvariable ["supshots", 0];
_unit setunitpos "auto";
};
if !(isnull tpwc_ai_sup_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["bulletbase",tpwc_ai_sup_br]);
if (_bc > 0) then
{
if ((tpwc_ai_sup_fired distance _unit) > tpwc_ai_sup_ir) then
{
_unit setvariable ["stanceregain", diag_ticktime + 10];
_shots = _unit getvariable "supshots";
_unit setvariable ["supshots", _shots + _bc];
_shots = _unit getvariable "supshots";
_unit setunitpos "middle";
if (tpwc_ai_sup_debug == 1) then
{
_ball = _unit getvariable "supball";_ball hideobject false;
};
if (_shots > tpwc_ai_sup_st) then
{
_unit setunitpos "down";
};
};
};
};
};
} foreach allunits;
};
//Lite version
tpwc_ai_sup_ai_sup_lite =
{
{
if (alive _x) then
{
_unit = _x;
_stanceregain = _unit getvariable ["stanceregain", -1];
if (_stanceregain == -1) then
{
_unit setvariable ["stanceregain", diag_ticktime];
_unit addeventhandler ["fired",{tpwc_ai_sup_fired = _this select 0;tpwc_ai_sup_mag = _this select 5; tpwc_ai_sup_bullet = _this select 6}];
_ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["supball",_ball];
};
if ( diag_ticktime >= _stanceregain) then
{
_ball = _unit getvariable "supball"; _ball hideobject true;
_unit setvariable ["supshots", 0];
_unit setunitpos "auto";
};
if !(isnull tpwc_ai_sup_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["bulletbase",tpwc_ai_sup_br]);
if (_bc > 0) then
{
if ((tpwc_ai_sup_fired distance _unit) > tpwc_ai_sup_ir) then
{
if !(tpwc_ai_sup_mag in tpwc_ai_sup_mags) then
{
_unit setvariable ["stanceregain", diag_ticktime + 10];
_shots = _unit getvariable "supshots";
_unit setvariable ["supshots", _shots + _bc];
_shots = _unit getvariable "supshots";
_unit setunitpos "middle";
if ((side tpwc_ai_sup_fired != side _unit) && (vehicle _unit == _unit)) then
{
if (tpwc_ai_sup_debug == 1) then
{
_ball = _unit getvariable "supball";_ball hideobject false;
};
if (_shots > tpwc_ai_sup_st) then
{
_unit setunitpos "down";
};
};
};
};
};
};
};
} foreach allunits;
};
//Full version
tpwc_ai_sup_full =
{
{
if (alive _x) then
{
_unit = _x;
_skillregain = _unit getvariable ["skillregain", -1];
_stanceregain = _unit getvariable ["stanceregain", -1];
if (_stanceregain == -1) then
{
_unit setvariable ["stanceregain", diag_ticktime];
_unit setvariable ["skillregain", diag_ticktime];
_unit addeventhandler ["fired",{tpwc_ai_sup_fired = _this select 0;tpwc_ai_sup_mag = _this select 5; tpwc_ai_sup_bullet = _this select 6}];
_originalaccuracy = _unit skill "aimingaccuracy";
_unit setvariable ["originalaccuracy", _originalaccuracy];
_originalshake = _unit skill "aimingshake";
_unit setvariable ["originalshake", _originalshake];
_originalcourage = _unit skill "courage";
_unit setvariable ["originalcourage", _originalcourage];
_general = _unit skill "general";
_unit setvariable ["general", _general];
_ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["supball",_ball];
};
if ( diag_ticktime >= _stanceregain) then
{
_ball = _unit getvariable "supball"; _ball hideobject true;
_unit setvariable ["supshots", 0];
_unit setunitpos "auto";
_originalcourage = _unit getvariable "originalcourage";
_general = _unit getvariable "general";
if((_unit skill "courage") < _originalcourage) then
{
_unit setskill ["courage",(_unit skill "courage")+(_general)*(0.003)];
};
};
if (diag_ticktime >= _skillregain) then
{
_originalaccuracy = _unit getvariable "originalaccuracy";
_originalshake = _unit getvariable "originalshake";
_originalcourage = _unit getvariable "originalcourage";
_general = _unit getvariable "general";
if((_unit skill "aimingaccuracy") < _originalaccuracy) then
{
_unit setskill ["aimingaccuracy",(_unit skill "aimingaccuracy")+((_originalaccuracy-(_unit skill "aimingaccuracy"))*.01)];
};
if((_unit skill "aimingshake") < _originalshake) then
{
_unit setskill ["aimingshake",(_unit skill "aimingshake")+((_originalshake-(_unit skill "aimingshake"))*.01)];
};
};
if !(isnull tpwc_ai_sup_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["bulletbase",tpwc_ai_sup_br]);
if (_bc > 0) then
{
if ((tpwc_ai_sup_fired distance _unit) > tpwc_ai_sup_ir) then
{
if !(tpwc_ai_sup_mag in tpwc_ai_sup_mags) then
{
_unit setvariable ["skillregain", diag_ticktime + (random 4)-((_unit getvariable "general")+(_unit getvariable "originalcourage"))];
_unit setvariable ["stanceregain", diag_ticktime + 10];
_shots = _unit getvariable "supshots";
_unit setvariable ["supshots", _shots + _bc];
_shots = _unit getvariable "supshots";
_originalaccuracy = _unit getvariable "originalaccuracy";
_originalshake = _unit getvariable "originalshake";
_originalcourage = _unit getvariable "originalcourage";
_general = _unit getvariable "general";
_unit setunitpos "middle";
if ((side tpwc_ai_sup_fired != side _unit) && (vehicle _unit == _unit)) then
{
_unit setskill ["aimingaccuracy",_originalaccuracy*_originalcourage*_general-(_shots*(1-_general)*.003)];
_unit setskill ["aimingshake",_originalshake*_originalcourage*_general-(_shots*(1-_general)*.003)];
_unit setskill ["courage",_originalcourage*_originalcourage*_general-(_shots*(1-_general)*.003)];
if (tpwc_ai_sup_debug == 1) then
{
_ball = _unit getvariable "supball";_ball hideobject false;
};
if (_shots > tpwc_ai_sup_st) then
{
_unit setunitpos "down";
};
};
};
};
};
};
};
} foreach allunits;
};
//CALL APPROPRIATE FUNCTION USING PER FRAME EVENTHANDLER SO COMPUTER DOESN'T EXPLODE
if (tpwc_ai_sup_type == 1) then {[tpwc_ai_sup_basic,0] call cba_fnc_addPerFrameHandler};
if (tpwc_ai_sup_type == 2) then {[tpwc_ai_sup_lite,0] call cba_fnc_addPerFrameHandler};
if (tpwc_ai_sup_type == 3) then {[tpwc_ai_sup_full,0] call cba_fnc_addPerFrameHandler};