From 4bb16c043c604433797a2477592f1f41fd7c9966 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Tue, 2 Jan 2018 16:18:12 +0000 Subject: [PATCH] Optimise cellphone IED function slightly (#6005) * Optimise cellphone IED function slightly * Fix distribution and use CBA function --- .../functions/fnc_addCellphoneIED.sqf | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/addons/explosives/functions/fnc_addCellphoneIED.sqf b/addons/explosives/functions/fnc_addCellphoneIED.sqf index 88da983be9..f577490933 100644 --- a/addons/explosives/functions/fnc_addCellphoneIED.sqf +++ b/addons/explosives/functions/fnc_addCellphoneIED.sqf @@ -24,7 +24,7 @@ TRACE_4("params",_unit,_explosive,_magazineClass,_extra); // Config is the last item in the list of passed in items. private _config = (_this select 3) select (count (_this select 3) - 1); -private _requiredItems = getArray(_config >> "requires"); +private _requiredItems = getArray (_config >> "requires"); private _hasRequired = true; private _detonators = [_unit] call FUNC(getDetonators); @@ -35,28 +35,21 @@ private _detonators = [_unit] call FUNC(getDetonators); } count _requiredItems; private _code = ""; -private _codeSet = false; - -while {!_codeSet} do { - _code = str(round (random 9999)); - _count = 4 - count (toArray _code); - while {_count > 0} do { - _code = "0" + _code; - _count = _count - 1; - }; - _codeSet = (count ([_code] call FUNC(getSpeedDialExplosive))) == 0; +while {true} do { + _code = [floor(random 10000), 4] call CBA_fnc_formatNumber; + if (([_code] call FUNC(getSpeedDialExplosive)) isEqualTo []) exitWith {}; }; if (isNil QGVAR(CellphoneIEDs)) then { GVAR(CellphoneIEDs) = []; }; -private _count = GVAR(CellphoneIEDs) pushBack [_explosive,_code,GetNumber(ConfigFile >> "CfgMagazines" >> _magazineClass >> "ACE_Triggers" >> "Cellphone" >> "FuseTime")]; +private _count = GVAR(CellphoneIEDs) pushBack [_explosive, _code, getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "ACE_Triggers" >> "Cellphone" >> "FuseTime")]; _count = _count + 1; publicVariable QGVAR(CellphoneIEDs); //display IED number message: -[format ["IED %1 code: %2", _count,_code]] call EFUNC(common,displayTextStructured); +[format ["IED %1 code: %2", _count, _code]] call EFUNC(common,displayTextStructured); if !(_hasRequired) exitWith {}; -[format ["IED %1", _count],_code] call FUNC(addToSpeedDial); +[format ["IED %1", _count], _code] call FUNC(addToSpeedDial);