From 6523b715fe6eb3a436f665eb22e41baf0c89291a Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 20 Feb 2016 11:57:47 -0300 Subject: [PATCH] Delay captivity until 0.05s after settings are initialized --- addons/captives/XEH_postInit.sqf | 7 +++++++ addons/captives/XEH_preInit.sqf | 2 ++ addons/captives/functions/fnc_moduleHandcuffed.sqf | 10 +++------- addons/captives/functions/fnc_moduleSurrender.sqf | 10 +++------- addons/captives/functions/fnc_setHandcuffed.sqf | 12 ++++++++++++ addons/captives/functions/fnc_setSurrendered.sqf | 11 +++++++++++ 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/addons/captives/XEH_postInit.sqf b/addons/captives/XEH_postInit.sqf index 26f84e6bd9..8f7109b81f 100644 --- a/addons/captives/XEH_postInit.sqf +++ b/addons/captives/XEH_postInit.sqf @@ -34,3 +34,10 @@ if (!hasInterface) exitWith {}; ["isNotEscorting", {!(GETVAR(_this select 0,GVAR(isEscorting),false))}] call EFUNC(common,addCanInteractWithCondition); ["isNotHandcuffed", {!(GETVAR(_this select 0,GVAR(isHandcuffed),false))}] call EFUNC(common,addCanInteractWithCondition); ["isNotSurrendering", {!(GETVAR(_this select 0,GVAR(isSurrendering),false))}] call EFUNC(common,addCanInteractWithCondition); + +["SettingsInitialized", { + // Hold on a little bit longer to ensure anims will work + [{ + GVAR(captivityEnabled) = true; + }, [], 0.05] call EFUNC(common,waitAndExecute); +}] call EFUNC(common,addEventHandler); diff --git a/addons/captives/XEH_preInit.sqf b/addons/captives/XEH_preInit.sqf index dcc585ef8e..e419d4d11b 100644 --- a/addons/captives/XEH_preInit.sqf +++ b/addons/captives/XEH_preInit.sqf @@ -32,4 +32,6 @@ PREP(setSurrendered); PREP(vehicleCaptiveMoveIn); PREP(vehicleCaptiveMoveOut); +GVAR(captivityEnabled) = false; + ADDON = true; diff --git a/addons/captives/functions/fnc_moduleHandcuffed.sqf b/addons/captives/functions/fnc_moduleHandcuffed.sqf index 4c6cc4c6fc..6b7fc3be15 100644 --- a/addons/captives/functions/fnc_moduleHandcuffed.sqf +++ b/addons/captives/functions/fnc_moduleHandcuffed.sqf @@ -24,12 +24,8 @@ TRACE_3("params",_logic,_units,_activated); if (!_activated) exitWith {}; if (!isServer) exitWith {}; -//Modules run before postInit can instal the event handler, so we need to wait a little bit -[{ - params ["_units"]; - { - ["SetHandcuffed", [_x], [_x, true]] call EFUNC(common,targetEvent); - } forEach _units; -}, [_units], 0.05] call EFUNC(common,waitAndExecute); +{ + ["SetHandcuffed", [_x], [_x, true]] call EFUNC(common,targetEvent); +} forEach _units; deleteVehicle _logic; diff --git a/addons/captives/functions/fnc_moduleSurrender.sqf b/addons/captives/functions/fnc_moduleSurrender.sqf index f5c091a78a..9e9f9d056c 100644 --- a/addons/captives/functions/fnc_moduleSurrender.sqf +++ b/addons/captives/functions/fnc_moduleSurrender.sqf @@ -24,12 +24,8 @@ TRACE_3("params",_logic,_units,_activated); if (!_activated) exitWith {}; if (!isServer) exitWith {}; -//Modules run before postInit can instal the event handler, so we need to wait a little bit -[{ - params ["_units"]; - { - ["SetSurrendered", [_x], [_x, true]] call EFUNC(common,targetEvent); - } forEach _units; -}, [_units], 0.05] call EFUNC(common,waitAndExecute); +{ + ["SetSurrendered", [_x], [_x, true]] call EFUNC(common,targetEvent); +} forEach _units; deleteVehicle _logic; diff --git a/addons/captives/functions/fnc_setHandcuffed.sqf b/addons/captives/functions/fnc_setHandcuffed.sqf index 0a17e0378c..d4f84730e6 100644 --- a/addons/captives/functions/fnc_setHandcuffed.sqf +++ b/addons/captives/functions/fnc_setHandcuffed.sqf @@ -22,6 +22,18 @@ TRACE_2("params",_unit,_state); if (!local _unit) exitWith { ERROR("running setHandcuffed on remote unit"); }; + +if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith { + // It's to soon to call this function, delay it + if (EGVAR(common,settingsInitFinished)) then { + // Settings are already initialized, but the small wait isn't over + [DFUNC(setHandCuffed), _this, 0.05] call EFUNC(common,waitAndExecute); + } else { + // Settings are not initialized yet + [DFUNC(setHandCuffed), _this] call EFUNC(common,runAfterSettingsInit); + }; +}; + if ((_unit getVariable [QGVAR(isHandcuffed), false]) isEqualTo _state) exitWith { ERROR("setHandcuffed: current state same as new"); }; diff --git a/addons/captives/functions/fnc_setSurrendered.sqf b/addons/captives/functions/fnc_setSurrendered.sqf index e65bd86bd0..ffc3c35081 100644 --- a/addons/captives/functions/fnc_setSurrendered.sqf +++ b/addons/captives/functions/fnc_setSurrendered.sqf @@ -23,6 +23,17 @@ if (!local _unit) exitWith { ERROR("running surrender on remote unit"); }; +if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith { + // It's to soon to call this function, delay it + if (EGVAR(common,settingsInitFinished)) then { + // Settings are already initialized, but the small wait isn't over + [DFUNC(setSurrendered), _this, 0.05] call EFUNC(common,waitAndExecute); + } else { + // Settings are not initialized yet + [DFUNC(setSurrendered), _this] call EFUNC(common,runAfterSettingsInit); + }; +}; + if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) exitWith { ERROR("Surrender: current state same as new"); };