From 54320eb451795f87761b6ad69580a484e08517b2 Mon Sep 17 00:00:00 2001
From: Jo David <github@jonathandavid.de>
Date: Wed, 27 Dec 2017 00:20:43 +0100
Subject: [PATCH] Fix(explosives): Selecting a cellphone as an IEDs trigger
 would throw an error (#5963)

* move code var to outer scope

* run closeDialog only for the player
---
 addons/explosives/functions/fnc_addCellphoneIED.sqf | 7 ++++++-
 addons/explosives/functions/fnc_onIncapacitated.sqf | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/addons/explosives/functions/fnc_addCellphoneIED.sqf b/addons/explosives/functions/fnc_addCellphoneIED.sqf
index beca3d3246..88da983be9 100644
--- a/addons/explosives/functions/fnc_addCellphoneIED.sqf
+++ b/addons/explosives/functions/fnc_addCellphoneIED.sqf
@@ -27,15 +27,18 @@ private _config = (_this select 3) select (count (_this select 3) - 1);
 private _requiredItems = getArray(_config >> "requires");
 private _hasRequired = true;
 private _detonators = [_unit] call FUNC(getDetonators);
+
 {
     if !(_x in _detonators) exitWith{
         _hasRequired = false;
     };
 } count _requiredItems;
 
+private _code = "";
 private _codeSet = false;
+
 while {!_codeSet} do {
-    private _code = str(round (random 9999));
+    _code = str(round (random 9999));
     _count = 4 - count (toArray _code);
     while {_count > 0} do {
         _code = "0" + _code;
@@ -43,9 +46,11 @@ while {!_codeSet} do {
     };
     _codeSet = (count ([_code] call FUNC(getSpeedDialExplosive))) == 0;
 };
+
 if (isNil QGVAR(CellphoneIEDs)) then {
     GVAR(CellphoneIEDs) = [];
 };
+
 private _count = GVAR(CellphoneIEDs) pushBack [_explosive,_code,GetNumber(ConfigFile >> "CfgMagazines" >> _magazineClass >> "ACE_Triggers" >> "Cellphone" >> "FuseTime")];
 _count = _count + 1;
 publicVariable QGVAR(CellphoneIEDs);
diff --git a/addons/explosives/functions/fnc_onIncapacitated.sqf b/addons/explosives/functions/fnc_onIncapacitated.sqf
index 6f9a9f498a..7e2cb249cc 100644
--- a/addons/explosives/functions/fnc_onIncapacitated.sqf
+++ b/addons/explosives/functions/fnc_onIncapacitated.sqf
@@ -19,6 +19,11 @@
 params ["_unit"];
 TRACE_1("params",_unit);
 
+if (_unit == ace_player) then {
+    // close cellphone if open
+    closeDialog 0;
+};
+
 // Exit if no item:
 if (({_x == "ACE_DeadManSwitch"} count (items _unit)) == 0) exitWith {};