From 1d083aa0726480171cf3a36f8734587b0cf1e14d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 14 Jan 2015 14:40:37 -0600 Subject: [PATCH] Convert Spawned/Sleep --- addons/grenades/XEH_postInitClient.sqf | 16 +---- addons/grenades/XEH_preInit.sqf | 2 +- .../functions/fnc_flashbangEffectStages.sqf | 65 ++++++++++++++--- .../functions/fnc_flashbangExplosionEH.sqf | 71 +++++++++---------- .../functions/fnc_flashbangThrownFuze.sqf | 1 - addons/grenades/functions/fnc_nextMode.sqf | 1 + addons/grenades/script_component.hpp | 5 ++ 7 files changed, 95 insertions(+), 66 deletions(-) diff --git a/addons/grenades/XEH_postInitClient.sqf b/addons/grenades/XEH_postInitClient.sqf index 364c7bfde8..5f5b569050 100644 --- a/addons/grenades/XEH_postInitClient.sqf +++ b/addons/grenades/XEH_postInitClient.sqf @@ -5,21 +5,9 @@ GVAR(flashbangPPEffectCC) = ppEffectCreate ["ColorCorrections", 4265]; GVAR(flashbangPPEffectCC) ppEffectForceInNVG true; -// class ACE_Core_Default_Keys { -// class switchGrenadeMode { -// displayName = "$STR_ACE_Grenades_SwitchGrenadeMode"; -// condition = "[_player] call ACE_Core_fnc_canUseWeapon"; -// statement = "call ACE_Grenades_fnc_nextMode"; -// key = 9;//34; -// shift = 0; -// control = 0; -// alt = 0;//1; -// }; -// }; - ["ACE3", localize "STR_ACE_Grenades_SwitchGrenadeMode", {_this call FUNC(nextMode)}, -[17, [false, false, false]], //8 key +[9, [false, false, false]], //8 key false, -"keydown"] call cba_fnc_registerKeybind; \ No newline at end of file +"keydown"] call cba_fnc_registerKeybind; diff --git a/addons/grenades/XEH_preInit.sqf b/addons/grenades/XEH_preInit.sqf index f6f1eb6ffe..10f91ec012 100644 --- a/addons/grenades/XEH_preInit.sqf +++ b/addons/grenades/XEH_preInit.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" -PREP(flashbangEffect); +PREP(flashbangEffectStages); PREP(flashbangExplosionEH); PREP(flashbangThrownFuze); PREP(nextMode); diff --git a/addons/grenades/functions/fnc_flashbangEffectStages.sqf b/addons/grenades/functions/fnc_flashbangEffectStages.sqf index 8ab4d09f94..c2ee7a6841 100644 --- a/addons/grenades/functions/fnc_flashbangEffectStages.sqf +++ b/addons/grenades/functions/fnc_flashbangEffectStages.sqf @@ -1,14 +1,57 @@ /* - * Author: KoffeinFlummi - * - * Creates the flashbang effect locally/knocks out AI units. - * - * Arguments: - * 0: The unit (Object) - * 1: The grenade (Object) - * - * Return Value: - * None - */ +* Author: KoffeinFlummi, Pabst Mirror +* +* Handles the different stages of the flash bang effect recovery +* +* Arguments: +* ARRAY[ +* 0-ARRAY - PARAMS: +* 0: NUMBER - Stage, controls a case statement +* 1: NUMBER - Time To Wait Until +* 2: VARIES - Stage's Variable +* 1-NUMBER perFrame handle +* Return Value: +* None +*/ #include "script_component.hpp" + +private ["_stage", "_waitUntilTime"]; + +_stage = (_this select 0) select 0; +_waitUntilTime = (_this select 0) select 1; + +if (_waitUntilTime > time) exitWith {}; + +//remove frameEH +[(_this select 1)] call cba_fnc_removePerFrameHandler; + +switch (_stage) do { + case(EFFECT_STAGE_RESETAI): { + private "_unit"; + _unit = (_this select 0) select 2; + _unit enableAI "MOVE"; + _unit enableAI "ANIM"; + _unit enableAI "AUTOTARGET"; + _unit enableAI "TARGET"; + _unit enableAI "FSM"; + _unit setSkill (skill _unit * 50); + }; + case(EFFECT_STAGE_DELETELIGHT): { + private "_light"; + _light = (_this select 0) select 2; + deleteVehicle _light; + }; + case(EFFECT_STAGE_PARTIALRECOVERY): { + private "_strength"; + _strength = (_this select 0) select 2; + GVAR(flashbangPPEffectCC) ppEffectAdjust [1,1,0,[1,1,1,0],[0,0,0,1],[0,0,0,0]]; + GVAR(flashbangPPEffectCC) ppEffectCommit (10 * _strength); + }; + case(EFFECT_STAGE_FULLRECOVERY): { + GVAR(flashbangPPEffectCC) ppEffectEnable false; + }; + default { + TRACE_1("EffectStage Bad Stage", _stage); + }; +}; diff --git a/addons/grenades/functions/fnc_flashbangExplosionEH.sqf b/addons/grenades/functions/fnc_flashbangExplosionEH.sqf index 528c3fef7c..7323329f33 100644 --- a/addons/grenades/functions/fnc_flashbangExplosionEH.sqf +++ b/addons/grenades/functions/fnc_flashbangExplosionEH.sqf @@ -1,7 +1,17 @@ -#include "script_component.hpp" +/* + * Author: KoffeinFlummi + * + * Creates the flashbang effect locally/knocks out AI units. + * + * Arguments: + * 0: The unit (Object) + * 1: The grenade (Object) + * + * Return Value: + * None + */ -#define EFFECT_STAGE_RESETAI 0 -#define EFFECT_STAGE_DELETELIGHT 1 + #include "script_component.hpp" _unit = _this select 0; _grenade = _this select 1; @@ -13,34 +23,27 @@ if (damage _unit >= 1) exitWith {}; _strength = 1 - ((_unit distance _grenade) min 15) / 15; if (_unit != ACE_player) exitWith { - //must be AI - _unit disableAI "MOVE"; - _unit disableAI "ANIM"; - _unit disableAI "AUTOTARGET"; - _unit disableAI "TARGET"; - _unit disableAI "FSM"; - _unit setSkill (skill _unit / 50); + //must be AI + _unit disableAI "MOVE"; + _unit disableAI "ANIM"; + _unit disableAI "AUTOTARGET"; + _unit disableAI "TARGET"; + _unit disableAI "FSM"; + _unit setSkill (skill _unit / 50); - sleep (7 * _strength); - - _unit enableAI "MOVE"; - _unit enableAI "ANIM"; - _unit enableAI "AUTOTARGET"; - _unit enableAI "TARGET"; - _unit enableAI "FSM"; - _unit setSkill (skill _unit * 50); + [FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_RESETAI, (time + (7 * _strength)), _unit]] call CBA_fnc_addPerFrameHandler; }; // is there line of sight to the grenade? _posGrenade = getPosASL _grenade; _posGrenade set [2, (_posGrenade select 2) + 0.2]; // compensate for grenade glitching into ground if (lineIntersects [_posGrenade, getPosASL _unit, _grenade, _unit]) then { - _strength = _strength / 10; + _strength = _strength / 10; }; // beeeeeeeeeeeeeeeeeeeeeeeeeeeeep if (isClass (configFile >> "CfgPatches" >> "ACE_Hearing") and _strength > 0) then { - [_unit, 0.5 + (_strength / 2)] call EFUNC(hearing,earRinging); + [_unit, 0.5 + (_strength / 2)] call EFUNC(hearing,earRinging); }; // account for people looking away by slightly @@ -65,25 +68,15 @@ _light setLightAmbient [1,1,1]; _light setLightColor [1,1,1]; _light setLightDayLight true; +[FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_DELETELIGHT, (time + (0.1)), _light]] call CBA_fnc_addPerFrameHandler; + + // blind player if (_strength > 0.1) then { - GVAR(flashbangPPEffectCC) ppEffectEnable true; - GVAR(flashbangPPEffectCC) ppEffectAdjust [1,1,(0.8 + _strength) min 1,[1,1,1,0],[0,0,0,1],[0,0,0,0]]; - GVAR(flashbangPPEffectCC) ppEffectCommit 0.01; -}; - -[] spawn { - sleep 0.1; - deleteVehicle _light; -}; - -sleep (7 * _strength); - -if (_strength > 0.1) then { - GVAR(flashbangPPEffectCC) ppEffectAdjust [1,1,0,[1,1,1,0],[0,0,0,1],[0,0,0,0]]; - GVAR(flashbangPPEffectCC) ppEffectCommit (10 * _strength); - - sleep (10 * _strength); - - GVAR(flashbangPPEffectCC) ppEffectEnable false; + GVAR(flashbangPPEffectCC) ppEffectEnable true; + GVAR(flashbangPPEffectCC) ppEffectAdjust [1,1,(0.8 + _strength) min 1,[1,1,1,0],[0,0,0,1],[0,0,0,0]]; + GVAR(flashbangPPEffectCC) ppEffectCommit 0.01; + + [FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_PARTIALRECOVERY, (time + (7 * _strength)), _strength]] call CBA_fnc_addPerFrameHandler; + [FUNC(flashbangEffectStages), 0, [ EFFECT_STAGE_FULLRECOVERY, (time + (17 * _strength))]] call CBA_fnc_addPerFrameHandler; }; diff --git a/addons/grenades/functions/fnc_flashbangThrownFuze.sqf b/addons/grenades/functions/fnc_flashbangThrownFuze.sqf index ce08ed466d..c71034b28d 100644 --- a/addons/grenades/functions/fnc_flashbangThrownFuze.sqf +++ b/addons/grenades/functions/fnc_flashbangThrownFuze.sqf @@ -15,7 +15,6 @@ if (alive _projectile) then { _affected = _projectile nearEntities ["CAManBase", 50]; { - // [[_x, _projectile], "ACE_Grenades_fnc_flashbangEffect", _x] call ACE_Core_fnc_execRemoteFnc; [QGVAR(flashbangExplosionEvent), [_x, _projectile]] call EFUNC(common,globalEvent); } forEach _affected; }; \ No newline at end of file diff --git a/addons/grenades/functions/fnc_nextMode.sqf b/addons/grenades/functions/fnc_nextMode.sqf index e9618f8993..da8392b6ab 100644 --- a/addons/grenades/functions/fnc_nextMode.sqf +++ b/addons/grenades/functions/fnc_nextMode.sqf @@ -41,3 +41,4 @@ _hint = [ GVAR(currentThrowMode) = _mode; +true diff --git a/addons/grenades/script_component.hpp b/addons/grenades/script_component.hpp index 27e9e04db6..f3d89216ba 100644 --- a/addons/grenades/script_component.hpp +++ b/addons/grenades/script_component.hpp @@ -12,3 +12,8 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define EFFECT_STAGE_RESETAI 0 +#define EFFECT_STAGE_DELETELIGHT 1 +#define EFFECT_STAGE_PARTIALRECOVERY 2 +#define EFFECT_STAGE_FULLRECOVERY 3