From 2fe155f990a749a7ba108d186360a4af2d12523c Mon Sep 17 00:00:00 2001 From: Garth L-H de Wet Date: Mon, 19 Jan 2015 10:34:49 +0200 Subject: [PATCH] Converted a couple PFHs to use the waitAndExecute function as that is what they were doing. Fixed a couple bugs. --- addons/goggles/XEH_postInit.sqf | 29 +++++++++++-------- addons/goggles/functions/fnc_applyDust.sqf | 11 +++---- addons/goggles/functions/fnc_clearGlasses.sqf | 6 ++-- addons/goggles/functions/fnc_dustHandler.sqf | 12 ++++---- addons/goggles/functions/fnc_onEachFrame.sqf | 20 +++++++------ 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/addons/goggles/XEH_postInit.sqf b/addons/goggles/XEH_postInit.sqf index 5861de26aa..a7c40bb4b5 100644 --- a/addons/goggles/XEH_postInit.sqf +++ b/addons/goggles/XEH_postInit.sqf @@ -37,7 +37,7 @@ GVAR(PostProcessEyes) ppEffectEnable false; GVAR(EffectsActive) = false; SETGLASSES(ace_player,GLASSESDEFAULT); GVAR(Current) = "None"; -GVAR(EyesDamageScript) = 0 spawn {}; +GVAR(EyesDamageScript) = -1; GVAR(FrameEvent) = [false, [false,20]]; GVAR(PostProcessEyes_Enabled) = false; GVAR(DustHandler) = -1; @@ -77,9 +77,13 @@ player addEventHandler ["Killed",{ call FUNC(removeGlassesEffect); GVAR(EffectsActive)=false; ace_player setVariable ["ACE_EyesDamaged", false]; - terminate GVAR(EyesDamageScript); - [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); - GVAR(DustHandler) = -1; + if (GVAR(EyesDamageScript) != -1) then { + [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); + }; + if (GVAR(DustHandler) != -1) then { + [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); + GVAR(DustHandler) = -1; + }; }]; player addEventHandler ["Fired",{[_this select 0, _this select 1] call FUNC(dustHandler);}]; player AddEventHandler ["Take",{call FUNC(checkGlasses);}]; @@ -99,20 +103,21 @@ player AddEventHandler ["Put", {call FUNC(checkGlasses);}]; ["GlassesCracked",{ if (_this select 0 != ace_player) exitWith {}; ace_player setVariable ["ACE_EyesDamaged", true]; - if !(scriptDone GVAR(EyesDamageScript)) then { - terminate GVAR(EyesDamageScript); + if (GVAR(EyesDamageScript) != -1) then { + [GVAR(EyesDamageScript)] call CALLSTACK(cba_fnc_removePreFrameHandler); }; GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [0.5,0.5,0.5,0.5],[1,1,1,0]]; GVAR(PostProcessEyes) ppEffectCommit 0; GVAR(PostProcessEyes) ppEffectEnable true; - GVAR(EyesDamageScript) = [] spawn { - sleep 25; + GVAR(EyesDamageScript) = [{ GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [1,1,1,1],[1,1,1,0]]; GVAR(PostProcessEyes) ppEffectCommit 5; - sleep 5; - GVAR(PostProcessEyes) ppEffectEnable false; - ace_player setVariable ["ACE_EyesDamaged", false]; - }; + GVAR(EyesDamageScript) = [{ + GVAR(PostProcessEyes) ppEffectEnable false; + ace_player setVariable ["ACE_EyesDamaged", false]; + GVAR(EyesDamageScript) = -1; + }, [], 5, 1] call EFUNC(common,waitAndExecute); + }, [], 25, 5] call EFUNC(common,waitAndExecute); }] call EFUNC(common,addEventHandler); call FUNC(checkGlasses); [FUNC(CheckGoggles), 1, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/goggles/functions/fnc_applyDust.sqf b/addons/goggles/functions/fnc_applyDust.sqf index 62eeed19ab..53e75ba274 100644 --- a/addons/goggles/functions/fnc_applyDust.sqf +++ b/addons/goggles/functions/fnc_applyDust.sqf @@ -33,10 +33,12 @@ _amount = 1 - (GETDUSTT(DAMOUNT) * 0.125); GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [_amount,_amount,_amount,_amount],[1,1,1,0]]; GVAR(PostProcessEyes) ppEffectCommit 1; GVAR(PostProcessEyes) ppEffectEnable true; +SETDUST(DBULLETS,0); + if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); + GVAR(DustHandler) = -1; }; -SETDUST(DBULLETS,0); GVAR(DustHandler) = [{ if (diag_tickTime >= GETDUSTT(DTIME) + 3) then { SETDUST(DAMOUNT,CLAMP(GETDUSTT(DAMOUNT)-1,0,2)); @@ -49,12 +51,7 @@ GVAR(DustHandler) = [{ if (GETDUSTT(DAMOUNT) <= 0) then { GVAR(PostProcessEyes) ppEffectAdjust[1, 1, 0, [0,0,0,0], [1,1,1,1],[1,1,1,0]]; GVAR(PostProcessEyes) ppEffectCommit 2; - [{ - if (diag_tickTime >= ((_this select 0) select 0)) then { - GVAR(PostProcessEyes) ppEffectEnable false; - [(_this select 1)] call CALLSTACK(cba_fnc_removePerFrameHandler); - }; - },0.5,[diag_tickTime+2]] call CALLSTACK(cba_fnc_addPerFrameHandler); + [{GVAR(PostProcessEyes) ppEffectEnable false;}, [], 2, 0.5] call EFUNC(common,waitAndExecute); SETDUST(DACTIVE,false); SETDUST(DBULLETS,0); [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); diff --git a/addons/goggles/functions/fnc_clearGlasses.sqf b/addons/goggles/functions/fnc_clearGlasses.sqf index 6d1c77e580..4072e7c68a 100644 --- a/addons/goggles/functions/fnc_clearGlasses.sqf +++ b/addons/goggles/functions/fnc_clearGlasses.sqf @@ -27,13 +27,11 @@ SETGLASSES(ace_player,_effects); if ((stance ace_player) != "PRONE") then { ace_player playActionNow "gestureWipeFace"; }; - -null = [] spawn { - sleep 0.3; +[{ if (cameraView == "INTERNAL") then { addCamShake [5, 1.75, 2]; }; -}; +}, [], 0.3, 0] call EFUNC(common,waitAndExecute); call FUNC(removeDirtEffect); call FUNC(removeRainEffect); diff --git a/addons/goggles/functions/fnc_dustHandler.sqf b/addons/goggles/functions/fnc_dustHandler.sqf index 2923412f11..aae722d50f 100644 --- a/addons/goggles/functions/fnc_dustHandler.sqf +++ b/addons/goggles/functions/fnc_dustHandler.sqf @@ -18,11 +18,13 @@ See http://community.bistudio.com/wiki/ArmA_3:_Event_Handlers#Fired */ #include "script_component.hpp" -private ["_bullets", "_position", "_surface", "_found", "_weapon", "_cloudType"]; -_weapon = _this select 1; +private ["_bullets", "_position", "_surface", "_found", "_weapon", "_cloudType", "_unit"]; +EXPLODE_2_PVT(_this,_unit,_weapon); +if (_unit != ace_player) exitWith {true}; _cloudType = ""; -if ((_this select 0) != ace_player) exitWith {true}; +if (rain > 0.1) exitWith {true}; +if ((stance _unit) != "PRONE") exitWith {true}; if (isClass(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "FirstEffect")) then { _cloudType = getText(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "FirstEffect" >> "effectName"); @@ -33,10 +35,8 @@ if (isClass(configFile >> "CfgWeapons" >> _weapon >> "GunParticles" >> "FirstEff }; if (_cloudType == "") exitWith {true}; -if (rain > 0.1) exitWith {true}; -if ((stance ace_player) != "PRONE") exitWith {true}; -_position = getPosATL ace_player; +_position = getPosATL _unit; if (surfaceIsWater _position) exitWith {}; if ((_position select 2) > 0.2) exitWith {}; diff --git a/addons/goggles/functions/fnc_onEachFrame.sqf b/addons/goggles/functions/fnc_onEachFrame.sqf index 25be148a61..cd361e38cf 100644 --- a/addons/goggles/functions/fnc_onEachFrame.sqf +++ b/addons/goggles/functions/fnc_onEachFrame.sqf @@ -28,15 +28,16 @@ _safe = false; if !(_rotorWash select 0) exitWith { if (GVAR(PostProcessEyes_Enabled)) then { GVAR(PostProcessEyes_Enabled) = false; - if (!scriptDone (GVAR(DustHandler))) then { - terminate GVAR(DustHandler); + if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA + [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); + GVAR(DustHandler) = -1; }; - GVAR(DustHandler) = [] spawn { - GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0,0,0,0], [0,0,0,1],[1,1,1,0]]; - GVAR(PostProcessEyes) ppEffectCommit 2; - sleep 2; + GVAR(PostProcessEyes) ppEffectAdjust [1, 1, 0, [0,0,0,0], [0,0,0,1],[1,1,1,0]]; + GVAR(PostProcessEyes) ppEffectCommit 2; + GVAR(DustHandler) = [{ GVAR(PostProcessEyes) ppEffectEnable false; - }; + GVAR(DustHandler) = -1; + }, [], 2, 0.5] call EFUNC(common,waitAndExecute); }; }; if ((headgear ace_player) != "") then { @@ -66,8 +67,9 @@ if ((_rotorWash select 1) <= 15) then { _scale = 0.1; }; _scale = 1 - _scale; - if (!scriptDone (GVAR(DustHandler))) then { - terminate GVAR(DustHandler); + if (GVAR(DustHandler) != -1) then { // should be fixed in dev CBA + [GVAR(DustHandler)] call CALLSTACK(cba_fnc_removePerFrameHandler); + GVAR(DustHandler) = -1; }; if !(ace_player getVariable ["ACE_EyesDamaged", false]) then { GVAR(PostProcessEyes_Enabled) = true;