From 5d07029db770335726e299d577af5711a6981ce4 Mon Sep 17 00:00:00 2001 From: Cyruz143 Date: Tue, 5 Nov 2019 17:55:15 +0000 Subject: [PATCH] Cookoff - Allow enabling only on player crewed vehicles (#7147) * Add setting for cookoff to only run for player crewed vehicles * No point having per vehicle selection * Merging mutliple settings in to one * Fixing missing comma * Using LSTRING for settings * merging suggested fixes * Moving enabled check to fnc * Use existing strings for CBA options * Reverting change to support legacy eden attribute settings * Adding Pabsts fix for 3den attribute * Update addons/cookoff/CfgEden.hpp Co-Authored-By: PabstMirror --- addons/cookoff/CfgEden.hpp | 2 +- addons/cookoff/XEH_postInit.sqf | 14 ++++---------- addons/cookoff/functions/fnc_handleDamage.sqf | 6 ++++++ addons/cookoff/initSettings.sqf | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/cookoff/CfgEden.hpp b/addons/cookoff/CfgEden.hpp index caffc6b90b..2b58daa304 100644 --- a/addons/cookoff/CfgEden.hpp +++ b/addons/cookoff/CfgEden.hpp @@ -12,7 +12,7 @@ class Cfg3DEN { expression = QUOTE(if !(_value) then {_this setVariable [ARR_3('%s',_value,true)];};); typeName = "BOOL"; condition = "objectVehicle"; - defaultValue = QUOTE(GETMVAR(QGVAR(enable),true)); + defaultValue = QUOTE((GETMVAR(QGVAR(enable),0)) in [ARR_2(1,2)]); }; class GVAR(enableAmmoCookoff) { property = QGVAR(enableAmmoCookoff); diff --git a/addons/cookoff/XEH_postInit.sqf b/addons/cookoff/XEH_postInit.sqf index fad901982d..1c93ee501c 100644 --- a/addons/cookoff/XEH_postInit.sqf +++ b/addons/cookoff/XEH_postInit.sqf @@ -27,9 +27,7 @@ GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace; }; _vehicle addEventHandler ["HandleDamage", { - if ((_this select 0) getVariable [QGVAR(enable), GVAR(enable)]) then { - ["tank", _this] call FUNC(handleDamage); - }; + ["tank", _this] call FUNC(handleDamage); }]; }, nil, nil, true] call CBA_fnc_addClassEventHandler; @@ -53,9 +51,7 @@ GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace; }; _vehicle addEventHandler ["HandleDamage", { - if ((_this select 0) getVariable [QGVAR(enable), GVAR(enable)]) then { - ["tank", _this] call FUNC(handleDamage); - }; + ["tank", _this] call FUNC(handleDamage); }]; }, nil, nil, true] call CBA_fnc_addClassEventHandler; @@ -63,9 +59,7 @@ GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace; params ["_vehicle"]; _vehicle addEventHandler ["HandleDamage", { - if ((_this select 0) getVariable [QGVAR(enable), GVAR(enable)]) then { - ["car", _this] call FUNC(handleDamage); - }; + ["car", _this] call FUNC(handleDamage); }]; }, nil, ["Wheeled_APC_F"], true] call CBA_fnc_addClassEventHandler; @@ -89,7 +83,7 @@ GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace; // blow off turret effect ["Tank", "killed", { - if ((_this select 0) getVariable [QGVAR(enable),GVAR(enable)]) then { + if ((_this select 0) getVariable [QGVAR(enable), GVAR(enable)] in [1, 2, true]) then { if (random 1 < 0.15) then { (_this select 0) call FUNC(blowOffTurret); }; diff --git a/addons/cookoff/functions/fnc_handleDamage.sqf b/addons/cookoff/functions/fnc_handleDamage.sqf index e9765805cb..60dffa452b 100644 --- a/addons/cookoff/functions/fnc_handleDamage.sqf +++ b/addons/cookoff/functions/fnc_handleDamage.sqf @@ -21,6 +21,12 @@ _thisHandleDamage params ["_vehicle", "", "_damage", "_source", "_ammo", "_hitIn // it's already dead, who cares? if (damage _vehicle >= 1) exitWith {}; +// If cookoff is disabled exit +if (_vehicle getVariable [QGVAR(enable), GVAR(enable)] in [0, false]) exitWith {}; + +// Check for players and exit if none found and the enable for players only setting is true +if (_vehicle getVariable [QGVAR(enable), GVAR(enable)] isEqualTo 2 && {fullCrew [_vehicle, "", false] findIf {isPlayer (_x select 0)} == -1}) exitWith {}; + // get hitpoint name private _hitpoint = "#structural"; diff --git a/addons/cookoff/initSettings.sqf b/addons/cookoff/initSettings.sqf index b29d213427..ce510a299d 100644 --- a/addons/cookoff/initSettings.sqf +++ b/addons/cookoff/initSettings.sqf @@ -1,10 +1,10 @@ // CBA Settings [ADDON: ace_cookoff]: [ - QGVAR(enable), "CHECKBOX", + QGVAR(enable), "LIST", [LSTRING(enable_hd_name), LSTRING(enable_hd_tooltip)], LSTRING(category_displayName), - false, // default value + [[0, 1, 2], ["STR_A3_OPTIONS_DISABLED", ELSTRING(common,playerOnly), ELSTRING(common,playersAndAI)], 0], true, // isGlobal {[QGVAR(enable), _this] call EFUNC(common,cbaSettings_settingChanged)}, true // Needs mission restart