From 3f61a41be36eddd46e296137c1d9c296e84c6bca Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:16:42 -0300 Subject: [PATCH] Common/CSW - Use status effect for `enableWeaponDisassembly` (#9413) * uuse weaponDisassemblyEnabled * convert to status effect * fix edge conditions * Update addons/common/functions/fnc_claim.sqf Co-authored-by: PabstMirror * Update addons/common/XEH_postInit.sqf Co-authored-by: PabstMirror * Update addons/common/XEH_postInit.sqf Co-authored-by: PabstMirror * Update XEH_postInit.sqf * Update addons/common/functions/fnc_claimSafeServer.sqf Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * Update fnc_claimSafeServer.sqf * change status effect key * status effect key --------- Co-authored-by: PabstMirror Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/common/XEH_postInit.sqf | 12 ++++++++++++ addons/common/functions/fnc_claim.sqf | 7 ------- addons/common/functions/fnc_claimSafeServer.sqf | 7 ------- addons/csw/XEH_postInit.sqf | 6 ------ addons/csw/functions/fnc_assemble_deployTripod.sqf | 3 +-- addons/csw/functions/fnc_assemble_deployWeapon.sqf | 4 +--- addons/csw/functions/fnc_staticWeaponInit.sqf | 4 ++-- 7 files changed, 16 insertions(+), 27 deletions(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index c250bda652..414a0ff7b5 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -28,6 +28,7 @@ ["setHidden", true, ["ace_unconscious"]] call FUNC(statusEffect_addType); ["blockRadio", false, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered), "ace_unconscious"]] call FUNC(statusEffect_addType); ["blockSpeaking", false, ["ace_unconscious"]] call FUNC(statusEffect_addType); +["disableWeaponAssembly", false, ["ace_common", "ace_common_lockVehicle", "ace_csw"]] call FUNC(statusEffect_addType); ["lockInventory", true, []] call FUNC(statusEffect_addType); [QGVAR(forceWalk), { @@ -121,6 +122,11 @@ _object setMass _mass; }] call CBA_fnc_addEventHandler; +[QGVAR(disableWeaponAssembly), { + params ["_object", "_set"]; + _object enableWeaponDisassembly (_set < 1); +}] call CBA_fnc_addEventHandler; + [QGVAR(lockInventory), { params ["_object", "_set"]; TRACE_2("lockInventory EH",_object,_set); @@ -161,10 +167,16 @@ if (isServer) then { [QGVAR(lockVehicle), { _this setVariable [QGVAR(lockStatus), locked _this]; _this lock 2; + if ([] isNotEqualTo getArray (configOf _this >> "assembleInfo" >> "dissasembleTo")) then { + [_this, "disableWeaponAssembly", QGVAR(lockVehicle), true] call FUNC(statusEffect_set); + }; }] call CBA_fnc_addEventHandler; [QGVAR(unlockVehicle), { _this lock (_this getVariable [QGVAR(lockStatus), locked _this]); + if ([] isNotEqualTo getArray (configOf _target >> "assembleInfo" >> "dissasembleTo")) then { + [_this, "disableWeaponAssembly", QGVAR(lockVehicle), false] call FUNC(statusEffect_set); + }; }] call CBA_fnc_addEventHandler; [QGVAR(setDir), {(_this select 0) setDir (_this select 1)}] call CBA_fnc_addEventHandler; diff --git a/addons/common/functions/fnc_claim.sqf b/addons/common/functions/fnc_claim.sqf index 06b13d0778..997d54f33b 100644 --- a/addons/common/functions/fnc_claim.sqf +++ b/addons/common/functions/fnc_claim.sqf @@ -30,17 +30,10 @@ _target setVariable [QGVAR(owner), _unit, true]; // lock target object if (_lockTarget) then { - private _canBeDisassembled = ([] isNotEqualTo getArray (configOf _target >> "assembleInfo" >> "dissasembleTo")) && { !([false, true] select (_target getVariable [QEGVAR(csw,assemblyMode), 0])) }; if (!isNull _unit) then { [QGVAR(lockVehicle), _target, _target] call CBA_fnc_targetEvent; - if (_canBeDisassembled) then { - _target enableWeaponDisassembly false; - }; } else { [QGVAR(unlockVehicle), _target, _target] call CBA_fnc_targetEvent; - if (_canBeDisassembled) then { - _target enableWeaponDisassembly true; - }; }; }; diff --git a/addons/common/functions/fnc_claimSafeServer.sqf b/addons/common/functions/fnc_claimSafeServer.sqf index b8d761c22a..e24a421549 100644 --- a/addons/common/functions/fnc_claimSafeServer.sqf +++ b/addons/common/functions/fnc_claimSafeServer.sqf @@ -36,17 +36,10 @@ _target setVariable [QGVAR(owner), _unit, true]; // lock target object if (_lockTarget) then { - private _canBeDisassembled = ([] isNotEqualTo getArray (configOf _target >> "assembleInfo" >> "dissasembleTo")) && { !([false, true] select (_target getVariable [QEGVAR(csw,assemblyMode), 0])) }; if (!isNull _unit) then { [QGVAR(lockVehicle), _target, _target] call CBA_fnc_targetEvent; - if (_canBeDisassembled) then { - _target enableWeaponDisassembly false; - }; } else { [QGVAR(unlockVehicle), _target, _target] call CBA_fnc_targetEvent; - if (_canBeDisassembled) then { - _target enableWeaponDisassembly true; - }; }; }; diff --git a/addons/csw/XEH_postInit.sqf b/addons/csw/XEH_postInit.sqf index a1aa348659..8a0f92ce47 100644 --- a/addons/csw/XEH_postInit.sqf +++ b/addons/csw/XEH_postInit.sqf @@ -12,12 +12,6 @@ GVAR(vehicleMagCache) = createHashMap; // Event handlers: -[QGVAR(disableVanillaAssembly), { - params ["_staticWeapon"]; - TRACE_1("disableVanillaAssembly eh",_staticWeapon); - _staticWeapon enableWeaponDisassembly false; -}] call CBA_fnc_addEventHandler; - [QGVAR(addTurretMag), LINKFUNC(reload_handleAddTurretMag)] call CBA_fnc_addEventHandler; [QGVAR(removeTurretMag), LINKFUNC(reload_handleRemoveTurretMag)] call CBA_fnc_addEventHandler; [QGVAR(returnAmmo), LINKFUNC(reload_handleReturnAmmo)] call CBA_fnc_addEventHandler; diff --git a/addons/csw/functions/fnc_assemble_deployTripod.sqf b/addons/csw/functions/fnc_assemble_deployTripod.sqf index b2ba0e4ea5..2d292a52c3 100644 --- a/addons/csw/functions/fnc_assemble_deployTripod.sqf +++ b/addons/csw/functions/fnc_assemble_deployTripod.sqf @@ -40,8 +40,7 @@ _cswTripod setVariable [QGVAR(secondaryWeaponMagazine), _secondaryWeaponMagazine]; }; if (!GVAR(defaultAssemblyMode)) then { - TRACE_1("global disableVanillaAssembly event",_cswTripod); // handles it being assembled when setting is disabled - [QGVAR(disableVanillaAssembly), [_cswTripod]] call CBA_fnc_globalEvent; + [_cswTripod, "disableWeaponAssembly", "ace_csw", true] call EFUNC(common,statusEffect_set); }; private _posATL = _player getRelPos [2, 0]; diff --git a/addons/csw/functions/fnc_assemble_deployWeapon.sqf b/addons/csw/functions/fnc_assemble_deployWeapon.sqf index f646047da2..e34e5d19d8 100644 --- a/addons/csw/functions/fnc_assemble_deployWeapon.sqf +++ b/addons/csw/functions/fnc_assemble_deployWeapon.sqf @@ -46,8 +46,7 @@ // Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default] _csw setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set advanced assembly mode + unload, and broadcast if (!GVAR(defaultAssemblyMode)) then { - TRACE_1("global disableVanillaAssembly event",_csw); // handles it being assembled when setting is disabled - [QGVAR(disableVanillaAssembly), [_csw]] call CBA_fnc_globalEvent; + [_csw, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); }; _csw setDir _tripodDir; _csw setPosATL _tripodPos; @@ -75,4 +74,3 @@ [TIME_PROGRESSBAR(_deployTime), [_tripod, _player, _assembledClassname, _carryWeaponClassname], _onFinish, _onFailure, localize LSTRING(AssembleCSW_progressBar), _codeCheck] call EFUNC(common,progressBar); }, _this] call CBA_fnc_execNextFrame; - diff --git a/addons/csw/functions/fnc_staticWeaponInit.sqf b/addons/csw/functions/fnc_staticWeaponInit.sqf index fcef5df08e..6ffd170d47 100644 --- a/addons/csw/functions/fnc_staticWeaponInit.sqf +++ b/addons/csw/functions/fnc_staticWeaponInit.sqf @@ -50,8 +50,8 @@ if (_assemblyConfig) then { if (!alive _staticWeapon) exitWith { TRACE_1("dead/deleted",_staticWeapon); }; private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select (_staticWeapon getVariable [QGVAR(assemblyMode), 3]); TRACE_2("assemblyConfig present",_staticWeapon,_assemblyMode); - if (_assemblyMode) then { // Disable vanilla assembly if assemblyMode eanbled - [QGVAR(disableVanillaAssembly), [_staticWeapon]] call CBA_fnc_localEvent; + if (_assemblyMode) then { // Disable vanilla assembly if assemblyMode enabled + [_staticWeapon, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); }; }, [_staticWeapon]] call CBA_fnc_execNextFrame; // need to wait a frame to allow setting object vars during assembly };