From 5a836591363a5ed45da9e2fcf9d18a24fbce4f80 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 23 Aug 2016 02:57:54 -0500 Subject: [PATCH] Don't cookoff when commander turret is hit (#4280) --- addons/cookoff/XEH_postInit.sqf | 18 +++++++++++++++++- addons/cookoff/functions/fnc_handleDamage.sqf | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/cookoff/XEH_postInit.sqf b/addons/cookoff/XEH_postInit.sqf index b241eed532..411f9d5a78 100644 --- a/addons/cookoff/XEH_postInit.sqf +++ b/addons/cookoff/XEH_postInit.sqf @@ -3,9 +3,25 @@ [QGVAR(engineFire), FUNC(engineFire)] call CBA_fnc_addEventHandler; [QGVAR(cookOff), FUNC(cookOff)] call CBA_fnc_addEventHandler; +GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace; + // cookoff and burning engine ["Tank", "init", { - (_this select 0) addEventHandler ["HandleDamage", { + params ["_vehicle"]; + private _typeOf = typeOf _vehicle; + if (isNil {GVAR(cacheTankDuplicates) getVariable _typeOf}) then { + private _hitpoints = (getAllHitPointsDamage _vehicle param [0, []]) apply {toLower _x}; + private _duplicateHitpoints = []; + { + if ((_x != "") && {_x in (_hitpoints select [0,_forEachIndex])}) then { + _duplicateHitpoints pushBack _forEachIndex; + }; + } forEach _hitpoints; + TRACE_2("dupes",_typeOf,_duplicateHitpoints); + GVAR(cacheTankDuplicates) setVariable [_typeOf, _duplicateHitpoints]; + }; + + _vehicle addEventHandler ["HandleDamage", { if (GVAR(enable)) then { ["tank", _this] call FUNC(handleDamage); }; diff --git a/addons/cookoff/functions/fnc_handleDamage.sqf b/addons/cookoff/functions/fnc_handleDamage.sqf index f1eb8542d9..2a0f2d54bc 100644 --- a/addons/cookoff/functions/fnc_handleDamage.sqf +++ b/addons/cookoff/functions/fnc_handleDamage.sqf @@ -60,6 +60,10 @@ if (_simulationType == "tank") exitWith { // determine ammo storage location private _ammoLocationHitpoint = getText (_vehicle call CBA_fnc_getObjectConfig >> QGVAR(ammoLocation)); + if (_hitIndex in (GVAR(cacheTankDuplicates) getVariable (typeOf _vehicle))) then { + _hitpoint = "#subturret"; + }; + // ammo was hit, high chance for cook-off if (_hitpoint == _ammoLocationHitpoint) then { if (_damage > 0.5 && {random 1 < 0.7}) then {