diff --git a/addons/arsenal/XEH_postInit.sqf b/addons/arsenal/XEH_postInit.sqf index ee03bff9a9..ac6283e604 100644 --- a/addons/arsenal/XEH_postInit.sqf +++ b/addons/arsenal/XEH_postInit.sqf @@ -18,6 +18,15 @@ GVAR(lastSortDirectionRight) = DESCENDING; [QGVAR(removeDefaultLoadout), LINKFUNC(removeDefaultLoadout)] call CBA_fnc_addEventHandler; [QGVAR(renameDefaultLoadout), LINKFUNC(renameDefaultLoadout)] call CBA_fnc_addEventHandler; +[QGVAR(refresh), { + params ["_object"]; + + // If the arsenal is already open, refresh arsenal display + if (!isNil QGVAR(currentBox) && {GVAR(currentBox) isEqualTo _object}) then { + [true, true] call FUNC(refresh); + }; +}] call CBA_fnc_addEventHandler; + [QGVAR(broadcastFace), { params ["_unit", "_face"]; _unit setFace _face; diff --git a/addons/arsenal/functions/fnc_addVirtualItems.sqf b/addons/arsenal/functions/fnc_addVirtualItems.sqf index c8b270ea6a..19859f619c 100644 --- a/addons/arsenal/functions/fnc_addVirtualItems.sqf +++ b/addons/arsenal/functions/fnc_addVirtualItems.sqf @@ -125,6 +125,8 @@ if (_items isEqualType true) then { _object setVariable [QGVAR(virtualItems), _cargo, _global]; // If the arsenal is already open, refresh arsenal display -if (!isNil QGVAR(currentBox) && {GVAR(currentBox) isEqualTo _object}) then { - [true, true] call FUNC(refresh); +if (_global) then { + [QGVAR(refresh), _object] call CBA_fnc_globalEvent; +} else { + [QGVAR(refresh), _object] call CBA_fnc_localEvent; }; diff --git a/addons/arsenal/functions/fnc_attributeInit.sqf b/addons/arsenal/functions/fnc_attributeInit.sqf index 1e44dc579f..42e72056fc 100644 --- a/addons/arsenal/functions/fnc_attributeInit.sqf +++ b/addons/arsenal/functions/fnc_attributeInit.sqf @@ -24,14 +24,12 @@ if (_mode > 0) then { // Blacklist: add full arsenal and take items away [_object, true, true] call FUNC(initBox); - // Need to delay removal by 2 frames + // Wait until all items have been added, so that the blacklisted items can be removed [{ - [{ - params ["_object", "_items"]; - - [_object, _items, true] call FUNC(removeVirtualItems); - }, _this] call CBA_fnc_execNextFrame; - }, [_object, _items]] call CBA_fnc_execNextFrame; + !isNil {(_this select 0) getVariable QGVAR(virtualItems)} + }, { + [_this select 0, _this select 1, true] call FUNC(removeVirtualItems); + }, [_object, _items], 20] call CBA_fnc_waitUntilAndExecute; // 20s timeout in case of failure } else { // Exit on whitelist mode with no items if (_items isEqualTo []) exitWith {}; diff --git a/addons/arsenal/functions/fnc_initBox.sqf b/addons/arsenal/functions/fnc_initBox.sqf index 446438d2b5..8651d25db8 100644 --- a/addons/arsenal/functions/fnc_initBox.sqf +++ b/addons/arsenal/functions/fnc_initBox.sqf @@ -51,7 +51,10 @@ if (_global && {isMultiplayer} && {isNil {_object getVariable QGVAR(initBoxJIP)} ] call EFUNC(interact_menu,createAction); [_object, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToObject); - [_object, _items, false] call FUNC(addVirtualItems); + // If items were set globally, do not add items locally + if (isNil {_object getVariable QGVAR(virtualItems)}) then { + [_object, _items, false] call FUNC(addVirtualItems); + }; [QGVAR(boxInitialized), [_object, _items]] call CBA_fnc_localEvent; }; diff --git a/addons/arsenal/functions/fnc_openBox.sqf b/addons/arsenal/functions/fnc_openBox.sqf index bb1dd66ad1..dd983776d1 100644 --- a/addons/arsenal/functions/fnc_openBox.sqf +++ b/addons/arsenal/functions/fnc_openBox.sqf @@ -28,13 +28,15 @@ if ( ) exitWith {}; // If object has no arsenal and chosen option is to not ignore virtual items of object, exit -if (isNil {_object getVariable QGVAR(virtualItems)} && {!_mode}) exitWith { +private _virtualItems = _object getVariable QGVAR(virtualItems); + +if (isNil "_virtualItems" && {!_mode}) exitWith { [LLSTRING(noVirtualItems), false, 5, 1] call EFUNC(common,displayText); }; // Don't execute in scheduled environment if (canSuspend) exitWith { - [{_this call FUNC(openBox)}, _this] call CBA_fnc_directCall; + [FUNC(openBox), _this] call CBA_fnc_directCall; }; private _displayToUse = findDisplay IDD_RSCDISPLAYCURATOR; @@ -46,6 +48,7 @@ if (isNull _displayToUse || {!isNil QGVAR(camera)}) exitWith { [LLSTRING(CantOpenDisplay), false, 5, 1] call EFUNC(common,displayText); }; +GVAR(center) = _center; GVAR(currentBox) = _object; if (_mode) then { @@ -56,29 +59,12 @@ if (_mode) then { GVAR(ignoredVirtualItems) = true; } else { // Add only specified items to the arsenal - private _virtualItems = _object getVariable QGVAR(virtualItems); - - GVAR(virtualItems) = if (isNil "_virtualItems") then { - _virtualItems = [ - [IDX_VIRT_WEAPONS, createHashMapFromArray [[IDX_VIRT_PRIMARY_WEAPONS, createHashMap], [IDX_VIRT_SECONDARY_WEAPONS, createHashMap], [IDX_VIRT_HANDGUN_WEAPONS, createHashMap]]], - [IDX_VIRT_ATTACHMENTS, createHashMapFromArray [[IDX_VIRT_OPTICS_ATTACHMENTS, createHashMap], [IDX_VIRT_FLASHLIGHT_ATTACHMENTS, createHashMap], [IDX_VIRT_MUZZLE_ATTACHMENTS, createHashMap], [IDX_VIRT_BIPOD_ATTACHMENTS, createHashMap]]] - ]; - - _virtualItems = createHashMapFromArray _virtualItems; - - for "_index" from IDX_VIRT_ITEMS_ALL to IDX_VIRT_MISC_ITEMS do { - _virtualItems set [_index, createHashMap]; - }; - } else { - +_virtualItems - }; + GVAR(virtualItems) = +_virtualItems; // Flatten out hashmaps for easy checking later call FUNC(updateVirtualItemsFlat); }; -GVAR(center) = _center; - if (is3DEN) then { _displayToUse createDisplay QGVAR(display); } else { diff --git a/addons/arsenal/functions/fnc_removeBox.sqf b/addons/arsenal/functions/fnc_removeBox.sqf index 50eb28d2e6..984db8d099 100644 --- a/addons/arsenal/functions/fnc_removeBox.sqf +++ b/addons/arsenal/functions/fnc_removeBox.sqf @@ -25,7 +25,7 @@ private _id = _object getVariable QGVAR(initBoxJIP); if (_global && {isMultiplayer} && {!isNil "_id"}) then { // Remove event from JIP queue - [_id] call CBA_fnc_removeGlobalEventJIP; + _id call CBA_fnc_removeGlobalEventJIP; // Reset JIP ID _object setVariable [QGVAR(initBoxJIP), nil, true]; diff --git a/addons/arsenal/functions/fnc_removeVirtualItems.sqf b/addons/arsenal/functions/fnc_removeVirtualItems.sqf index f16cf6553f..71db2b15a1 100644 --- a/addons/arsenal/functions/fnc_removeVirtualItems.sqf +++ b/addons/arsenal/functions/fnc_removeVirtualItems.sqf @@ -100,9 +100,12 @@ if (_items isEqualType true) then { [_object, _global] call FUNC(removeBox); } else { _object setVariable [QGVAR(virtualItems), _cargo, _global]; + // If the arsenal is already open, refresh arsenal display - if (!isNil QGVAR(currentBox) && {GVAR(currentBox) isEqualTo _object}) then { - [true, true] call FUNC(refresh); + if (_global) then { + [QGVAR(refresh), _object] call CBA_fnc_globalEvent; + } else { + [QGVAR(refresh), _object] call CBA_fnc_localEvent; }; }; };