From b9ce02acf937edb2fc7307503b8be11b6a5699de Mon Sep 17 00:00:00 2001 From: Whigital Date: Sat, 10 Sep 2022 20:02:53 +0200 Subject: [PATCH] Explosives - Fix cellphone ringing if RF blocking present (#8991) --- addons/explosives/XEH_PREP.hpp | 1 + .../functions/fnc_checkDetonateHandlers.sqf | 38 +++++++++++++++++++ .../functions/fnc_detonateExplosive.sqf | 8 +--- addons/explosives/functions/fnc_dialPhone.sqf | 12 ++++-- .../explosives/functions/fnc_dialingPhone.sqf | 9 ++++- 5 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 addons/explosives/functions/fnc_checkDetonateHandlers.sqf diff --git a/addons/explosives/XEH_PREP.hpp b/addons/explosives/XEH_PREP.hpp index d549118623..319bd2fec2 100644 --- a/addons/explosives/XEH_PREP.hpp +++ b/addons/explosives/XEH_PREP.hpp @@ -39,3 +39,4 @@ PREP(startTimer); PREP(triggerType); PREP(allowDefuse); PREP(isAllowedDefuse); +PREP(checkDetonateHandlers); diff --git a/addons/explosives/functions/fnc_checkDetonateHandlers.sqf b/addons/explosives/functions/fnc_checkDetonateHandlers.sqf new file mode 100644 index 0000000000..bd3eff7586 --- /dev/null +++ b/addons/explosives/functions/fnc_checkDetonateHandlers.sqf @@ -0,0 +1,38 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror, Whigital + * Check if there is a handler blocking detonation + * + * Arguments: + * 0: Unit + * 1: Max range (-1 to ignore) + * 2: Explosive + * 3: Fuse time + * 4: Trigger Item Classname + * + * Return Value: + * Detonation Allowed + * + * Example: + * [player, -1, Explosive, 1, "ACE_Cellphone"] call ACE_Explosives_fnc_checkDetonateHandlers; + * + * Public: No + */ + +params ["_unit", "_range", "_explosive", "_fuseTime", ["_triggerClassname", "#unknown", [""]]]; +TRACE_5("checkDetonateHandlers",_unit,_range,_explosive,_fuseTime,_triggerClassname); + +private _detonationAllowed = true; + +{ + // Pass [Unit, MaxRange , Explosive , FuzeTime , TriggerItem ] + private _handlerResult = [_unit, _range, _explosive, _fuseTime, _triggerClassname] call _x; + + if (_handlerResult isEqualTo false) then { + TRACE_1("Handler Blocking",_forEachIndex); + _detonationAllowed = false; + break; + }; +} forEach GVAR(detonationHandlers); + +_detonationAllowed diff --git a/addons/explosives/functions/fnc_detonateExplosive.sqf b/addons/explosives/functions/fnc_detonateExplosive.sqf index 8edc83f0ff..de7772d4de 100644 --- a/addons/explosives/functions/fnc_detonateExplosive.sqf +++ b/addons/explosives/functions/fnc_detonateExplosive.sqf @@ -28,12 +28,8 @@ private _ignoreRange = (_range == -1); if (!_ignoreRange && {(_unit distance (_item select 0)) > _range}) exitWith {TRACE_1("out of range",_range); false}; private _result = true; -{ - // Pass [Unit, MaxRange , Explosive , FuzeTime , TriggerItem ] - private _handlerResult = [_unit, _range, _item select 0, _item select 1, _triggerClassname] call _x; - if (_handlerResult isEqualTo false) then {TRACE_1("Handler Failed",_forEachIndex); _result = false}; -} forEach GVAR(detonationHandlers); -if (!_result) exitWith {false}; + +if !([_unit, _range, _item select 0, _item select 1, _triggerClassname] call FUNC(checkDetonateHandlers)) exitWith {false}; if (getNumber (ConfigFile >> "CfgAmmo" >> typeOf (_item select 0) >> "TriggerWhenDestroyed") == 0) then { private _previousExp = _item select 0; diff --git a/addons/explosives/functions/fnc_dialPhone.sqf b/addons/explosives/functions/fnc_dialPhone.sqf index e4292f60b3..a081abb1f1 100644 --- a/addons/explosives/functions/fnc_dialPhone.sqf +++ b/addons/explosives/functions/fnc_dialPhone.sqf @@ -35,9 +35,15 @@ if (_unit == ace_player) then { private _explosive = [_code] call FUNC(getSpeedDialExplosive); if ((count _explosive) > 0) then { [{ - playSound3D [QUOTE(PATHTO_R(Data\Audio\Cellphone_Ring.wss)),objNull, false, getPosASL (_this select 1),3.16228,1,75]; - (_this select 0) setVariable [QGVAR(Dialing), false, true]; - }, [_unit,_explosive select 0], 0.25 * (count _arr - 4)] call CBA_fnc_waitAndExecute; + params ["_unit", "_item"]; + + if ([_unit, -1, (_item # 0), (_item # 2), "ACE_Cellphone"] call FUNC(checkDetonateHandlers)) then { + playSound3D [QUOTE(PATHTO_R(Data\Audio\Cellphone_Ring.wss)), objNull, false, (getPosASL (_item # 0)), 3.16228, 1, 75]; + }; + + _unit setVariable [QGVAR(Dialing), false, true]; + }, [_unit, _explosive], 0.25 * (count _arr - 4)] call CBA_fnc_waitAndExecute; + [_explosive select 0,(0.25 * (count _arr - 1)) + (_explosive select 2), "ACE_Cellphone", _unit] call FUNC(startTimer); }; }; diff --git a/addons/explosives/functions/fnc_dialingPhone.sqf b/addons/explosives/functions/fnc_dialingPhone.sqf index 0a30a298bb..a4c2f59f48 100644 --- a/addons/explosives/functions/fnc_dialingPhone.sqf +++ b/addons/explosives/functions/fnc_dialingPhone.sqf @@ -39,9 +39,14 @@ if (_i >= (count _arr + 2)) then { ctrlSetText [1400,"Call Ended!"]; }; }; + if (_i == (count _arr)) then { - if ((count _explosive) > 0) then { - playSound3D [QUOTE(PATHTO_R(Data\Audio\Cellphone_Ring.wss)),objNull, false, getPosASL (_explosive select 0),3.16228,1,75]; + if ( + ((count _explosive) > 0) && + {[_unit, -1, (_explosive # 0), (_explosive # 2), "ACE_Cellphone"] call FUNC(checkDetonateHandlers)} + ) then { + playSound3D [QUOTE(PATHTO_R(Data\Audio\Cellphone_Ring.wss)), objNull, false, (getPosASL (_explosive # 0)), 3.16228, 1, 75]; }; }; + _args set [1, _i + 1];