From 20120209 - 20120618 Outdated
Spoiler:
Spoiler:
Hello,
So I found this neat script on armaholic and basically what it does is make the player's vision blur and darken when rounds pass nearby, kind of like in VBS2. Now I am not very knowledgeable in scripting but I managed to make it so not only does the screen blur but the player's aim jerks a little bit from incoming rounds. I put it altogether and ran it as an addon and it worked fine, making it a bit harder for the player in a firefight when suppressed. Heres the scripts.
I'm guessing this is what triggers the main script by detecting whenever a shot is fired and when one is, firing up the "wizz.sqf" below. But does anybody know what the apuVBS2style is? I searched it and found nothing._unit = _this select 0;
player setVariable ["apuStress",0];
_apuVBS2style = _unit addEventHandler ["Fired",{_this execVM "\Wizz\Scripts\wizz.sqf"}];
This is the script that detects whether the round is close and triggers the blurred screen and shaky aim(camera shake)._unit = _this select 0;
_ammo = _this select 4;
_radius = 15;
if (playerSide == side _unit) exitWith {};
if (_unit == player) exitWith {};
_bullet= nearestObject [_unit, _ammo];
while {(speed _bullet) > 0.1} do {
_dist = _bullet distance player;
if (_dist < _radius) then {
_freq = 0.5-(_dist/100);
_rand = 2;
if (_rand < 5) then {
_freq = 0.4-(_dist/100);
addCamShake [1, 3, 5];
_ppColor = ppEffectCreate ["ColorCorrections", 1001];
_ppColor ppEffectEnable true;
_ppColor ppEffectAdjust [0, -1, 0, [0,0,0,0], [0,0,0,0], [0,0,0,0]];
_ppColor ppEffectCommit 1;
sleep _freq;
_ppColor ppEffectEnable false;
ppEffectDestroy _ppColor;
};
_ppBlur = ppEffectCreate ["dynamicBlur", 1001];
_ppBlur ppEffectEnable true;
_ppBlur ppEffectAdjust [1.5];
_ppBlur ppEffectCommit 1;
sleep _freq;
_ppBlur ppEffectEnable false;
ppEffectDestroy _ppBlur;
};
sleep 0.05;
};
Now what I would like help on, is how to extend this to the ai as well. I was thinking that when a round comes close to an ai his accuracy skill will be temporarily decreased and he will have setunitpos "down" applied to him temporarily to make him go prone for a while, instead of the camera shake and blurryiness the player experiences. The problem is I have no idea how to detect when rounds pass by the ai. Is it possibly to do what I am suggesting and if so does anybody here have some advice on how I would go about it. Keep in mind I really don't know much about scripting.Thanks.
From 20120618 Outdated
Spoiler:
This thread has really developed alot from when it started. A script that makes the ai react to suppressive fire has been created. The script basically makes it so if a bullet snaps by an ai soldier he takes a knee. If several shots snap by rapidly (5 in a 5 second period right now) the ai will go prone. Here's what it looks like. Note that pistol and submachinegun rounds, whether silenced or not will not cause suppression effects.
There are two versions of the script. AIsuppress1.sqf prevents a unit from being suppressed by any friendly fire. AIsuppress2.sqf prevents a unit from being suppressed by any fire from less than 20m away.
To use either scripts, simply put the following into the init.sqf of a mission or into the init of a unit. If you want to use aisuppress2, just replace the 1 with a 2 in the following code.
Then place aisuppress1.sqf or aisuppress2.sqf respectively in the mission folder. When you run the mission you should see "ai suppress active" in the top right of the screen after a few seconds have passed. If anyone needs further help with the setup just ask, I know I'm not the greatest at explaining things.PHP Code:nul = [] execvm "aisuppress1.sqf"
CBA is required to use this script!
For those interested, here are the scripts within each of those files.
Spoiler:
aisuppress1.sqfaisuppress2.sqfPHP Code:// ALL INFANTRY UNITS ON MAP WILL DROP IF BULLETS FROM ENEMIES AWAY PASS WITHIN 10m
// BULLETS FROM OWN SIDE ARE IGNORED
// BULLETS FROM SMG AND PISTOLS ARE IGNORED
// Original code idea by -Coulum-
// TPW 20120619
//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};
private ["_supnextime","_unit","_bc","_shots","_side"];
//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 ["SupNextTime", diag_tickTime];
_unit setvariable ["SIDE", (side _unit)];
_unit addeventhandler ["Fired",{tpw_fired = (_this select 0) getvariable "SIDE";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
{
_side = _unit getvariable "SIDE";
if (_side != tpw_fired) 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";
if (_shots == 0) then {_unit setunitpos "auto"};
if (_shots > 0) then {_unit setunitpos "middle"};
if (_shots > 5) then {_unit setunitpos "down"};
};
} forEach allunits;
};
//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;
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 20120619
//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 ["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";
if (_shots == 0) then {_unit setunitpos "auto"};
if (_shots > 0) then {_unit setunitpos "middle"};
if (_shots > 5) then {_unit setunitpos "down"};
}
} forEach allunits;
};
//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;
And a huge thanks to tpw who basically wrote the whole script and Orcinus for his great ideas.
This definitely isn't a finished product, so we are still very open to feedback, suggestions and ideas. I am also interested to know how the script holds up with large numbers of ai in firefights.
From 20120619 Outdated
Spoiler:
The scripts have been updated and there is now a mod version of the script thanks to tpw:
Based on side
Based on distance
Remember, CBA is required.
From 20120618Updated
There are three versions of the script available:
Basic (stance modifier)
Spoiler:
PHP Code:/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED
Authors: TPW & -Coulum-
Last changed: 20120622
*/
//Allow time for ASR AI skills to propagate
sleep 30;
//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};
private ["_stanceregain","_unit","_bc","_shots","_ball"];
//Main function
tpw_ai_sup =
{
{
if (alive _x) then
{
_unit = _x;
_stanceregain = _unit getvariable ["stanceregain", -1];
if (_stanceregain == -1) then
{
_unit setvariable ["stanceregain", diag_ticktime];
_unit addeventhandler ["fired",{tpw_fired = _this select 0;tpw_bullet = _this select 6}];
};
if ( diag_ticktime >= _stanceregain) then
{
_unit setvariable ["supshots", 0];
_unit setunitpos "auto";
};
if !(isnull tpw_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["bulletbase",10]);
if (_bc > 0) then
{
if ((tpw_fired distance _unit) > 25) then
{
_unit setvariable ["stanceregain", diag_ticktime + 10];
_shots = _unit getvariable "supshots";
_unit setvariable ["supshots", _shots + _bc];
_shots = _unit getvariable "supshots";
_unit setunitpos "middle";
if (_shots > 5) then
{
_unit setunitpos "down";
};
};
};
};
};
} foreach allunits;
};
//Call function using per frame eventhandler so computer doesn't explode
[tpw_ai_sup,0] call cba_fnc_addPerFrameHandler;
-Units react to bullets passing within 10m
-Affects all units, in vehicles or not
-Units react identically to any kind of bullet fired from more than 25m away
-Units react to identically bullets from any side
-1-5 bullets -->kneel/crouch
->5 bullets --> drop/crawl
-Units regain previous stance after 10 seconds without nearby bullets
Light (stance modifier)
Spoiler:
PHP Code:/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED
BULLETS FROM SMG AND PISTOLS ARE IGNORED
BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH
BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP
Authors: TPW & -Coulum-
Last changed: 20120622
*/
//Allow time for ASR AI skills to propagate
sleep 30;
//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};
private ["_stanceregain","_unit","_bc","_shots","_ball"];
//Pistol and SMG ammo to ignore
tpw_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"];
//Main function
tpw_ai_sup =
{
{
if (alive _x) then
{
_unit = _x;
_stanceregain = _unit getvariable ["stanceregain", -1];
if (_stanceregain == -1) then
{
_unit setvariable ["stanceregain", diag_ticktime];
_unit addeventhandler ["fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
};
if ( diag_ticktime >= _stanceregain) then
{
_unit setvariable ["supshots", 0];
_unit setunitpos "auto";
};
if !(isnull tpw_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["bulletbase",10]);
if (_bc > 0) then
{
if ((tpw_fired distance _unit) > 25) then
{
if !(tpw_mag in tpw_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 tpw_fired != side _unit) && (vehicle _unit == _unit)) then
{
if (_shots > 5) then
{
_unit setunitpos "down";
};
};
};
};
};
};
};
} foreach allunits;
};
//Call function using per frame eventhandler so computer doesn't explode
[tpw_ai_sup,0] call cba_fnc_addPerFrameHandler;
-Units react to bullets passing within 10m
-Only units not in vehicles are affected
-Bullets fired from less than 25m away are ignored
-Bullets from small calibre pistols and SMG are ignored
-Units react differently according to the side of the shooter
-1-5 bullets --> kneel/crouch
->5 bullets --> drop/crawl only if enemy shooter fired bullets
-Units regain previous stance after 10 seconds without nearby bullets
Full (stance and skill modifier)
Spoiler:
PHP Code:/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED
BULLETS FROM SMG AND PISTOLS ARE IGNORED
BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH
BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND A TEMPORARY DECREASE IN SKILL
SKILLS WILL GRADUALLY RETURN ONCE UNIT IS NOT SUPPRESSED
Authors: TPW & -Coulum-
Last changed: 20120622
*/
//Allow time for ASR AI skills to propagate
sleep 30;
//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};
private ["_stanceregain","_skillregain","_unit","_bc","_shots","_originalaccuracy","_originalshake","_originalcourage","_general","_ball"];
//Pistol and SMG ammo to ignore
tpw_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"];
//Main function
tpw_ai_sup =
{
{
//hint format["accuracy = %1, shake = %2, courage = %3, general = %4",(ai skill "aimingaccuracy"),(ai skill "aimingshake"),(ai skill "courage"),(ai skill "general")]; // Dsiplay skills for unit named "AI"
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",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_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];
};
if ( diag_ticktime >= _stanceregain) then
{
_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 tpw_bullet) then
{
_bc = count ((getposatl _unit) nearobjects ["bulletbase",10]);
if (_bc > 0) then
{
if ((tpw_fired distance _unit) > 25) then
{
if !(tpw_mag in tpw_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 tpw_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 (_shots > 5) then
{
_unit setunitpos "down";
};
};
};
};
};
};
};
} foreach allunits;
};
//Call function using per frame eventhandler so computer doesn't explode
[tpw_ai_sup,0] call cba_fnc_addPerFrameHandler;
-Units react to bullets passing within 10m
-Only units not in vehicles are affected
-Bullets fired from less than 25m away are ignored
-Bullets from small calibre pistols and SMG are ignored
-Units react differently according to the side of the shooter
-Friendly shooter: >0 bullets --> kneel/crouch
-Enemy shooter: 1-5 bullets --> kneel/crouch, >5 bullets -->drop/crawl
-Friendly shooter: no skill reduction
-Enemy shooter: skills reduced according to number of bullets
-Units regain previous stance after 10 seconds without nearby bullets
-Units gradually regain skills after 5 or so seconds without bullets
Each script only needs to be initialized once per mission. CBA is required.
Oh and I almost forgot to mention:
tpw is the one responsible for the magority of the script. Credit should really go to him. He's done an excellent job, and I believe he plans to release this as a mod soon.
HOME
Reply With Quote



