Fix global behavior in add / remove virtual items funcs (#5887)

This commit is contained in:
Josuan Albin 2017-12-10 18:53:51 +01:00 committed by PabstMirror
parent 845f3656d4
commit 5fa0179d06
3 changed files with 254 additions and 238 deletions

View File

@ -5,6 +5,9 @@ GVAR(EH_ID) = 0;
GVAR(lastSearchTextLeft) = ""; GVAR(lastSearchTextLeft) = "";
GVAR(lastSearchTextRight) = ""; GVAR(lastSearchTextRight) = "";
[QGVAR(addVirtualItems), {_this call FUNC(addVirtualItems)}] call CBA_fnc_addEventHandler;
[QGVAR(removeVirtualItems), {_this call FUNC(removeVirtualItems)}] call CBA_fnc_addEventHandler;
[QGVAR(initBox), {_this call FUNC(initBox)}] call CBA_fnc_addEventHandler; [QGVAR(initBox), {_this call FUNC(initBox)}] call CBA_fnc_addEventHandler;
[QGVAR(removeBox), {_this call FUNC(removeBox)}] call CBA_fnc_addEventHandler; [QGVAR(removeBox), {_this call FUNC(removeBox)}] call CBA_fnc_addEventHandler;

View File

@ -24,6 +24,10 @@ params [["_object", objNull, [objNull]], ["_items", [], [true, []]], ["_global",
if (_object == objNull) exitWith {}; if (_object == objNull) exitWith {};
if (_items isEqualType [] && {count _items == 0}) exitWith {}; if (_items isEqualType [] && {count _items == 0}) exitWith {};
if (_global && {isMultiplayer}) then {
[QGVAR(addVirtualItems), [_object, _items, false]] call CBA_fnc_globalEvent;
} else {
private _cargo = _object getVariable [QGVAR(virtualItems), [ private _cargo = _object getVariable [QGVAR(virtualItems), [
[[], [], []], // Weapons 0, primary, secondary, handgun [[], [], []], // Weapons 0, primary, secondary, handgun
[[], [], [], []], // WeaponAccessories 1, optic,side,muzzle,bipod [[], [], [], []], // WeaponAccessories 1, optic,side,muzzle,bipod
@ -47,7 +51,8 @@ private _cargo = _object getVariable [QGVAR(virtualItems), [
private _configCfgWeapons = configFile >> "CfgWeapons"; //Save this lookup in variable for perf improvement private _configCfgWeapons = configFile >> "CfgWeapons"; //Save this lookup in variable for perf improvement
if (_items isEqualType true && {_items}) then { if (_items isEqualType true) then {
if (_items) then {
private _configItems = uiNamespace getVariable QGVAR(configItems); private _configItems = uiNamespace getVariable QGVAR(configItems);
{ {
@ -67,7 +72,7 @@ if (_items isEqualType true && {_items}) then {
(_cargo select _index) append (_configItems select _index); (_cargo select _index) append (_configItems select _index);
_cargo set [_index, (_cargo select _index) arrayIntersect (_cargo select _index)]; _cargo set [_index, (_cargo select _index) arrayIntersect (_cargo select _index)];
}; };
};
} else { } else {
{ {
if (_x isEqualType "") then { if (_x isEqualType "") then {
@ -220,4 +225,5 @@ if (_items isEqualType true && {_items}) then {
} foreach _items; } foreach _items;
}; };
_object setVariable [QGVAR(virtualItems), _cargo, _global]; _object setVariable [QGVAR(virtualItems), _cargo];
};

View File

@ -23,6 +23,10 @@ params [ ["_object", objNull, [objNull]], ["_items", [], [true, [""]]], ["_globa
if (_object == objNull) exitWith {}; if (_object == objNull) exitWith {};
if (_items isEqualType [] && {count _items == 0}) exitWith {}; if (_items isEqualType [] && {count _items == 0}) exitWith {};
if (_global && {isMultiplayer}) then {
[QGVAR(removeVirtualItems), [_object, _items, false]] call CBA_fnc_globalEvent;
} else {
private _cargo = _object getVariable [QGVAR(virtualItems), [ private _cargo = _object getVariable [QGVAR(virtualItems), [
[[], [], []], // Weapons 0, primary, handgun, secondary [[], [], []], // Weapons 0, primary, handgun, secondary
[[], [], [], []], // WeaponAccessories 1, optic,side,muzzle,bipod [[], [], [], []], // WeaponAccessories 1, optic,side,muzzle,bipod
@ -44,9 +48,11 @@ private _cargo = _object getVariable [QGVAR(virtualItems), [
[ ] // InventoryItems 17 [ ] // InventoryItems 17
]]; ]];
if (_items isEqualType true && {_items}) then { if (_items isEqualType true) then {
if (_items) then {
[_object, _global] call FUNC(removeBox); [_object, _global] call FUNC(removeBox);
_object setVariable [QGVAR(virtualItems), nil, _global]; _object setVariable [QGVAR(virtualItems), nil, _global];
};
} else { } else {
// Make sure all items are in string form // Make sure all items are in string form
@ -72,9 +78,10 @@ if (_items isEqualType true && {_items}) then {
}; };
} count _cargo; } count _cargo;
_object setVariable [QGVAR(virtualItems), _cargo];
if (_itemCount == 0) then { if (_itemCount == 0) then {
[_object, _global] call FUNC(removeBox); [_object, false] call FUNC(removeBox);
} else { };
_object setVariable [QGVAR(virtualItems), _cargo, _global];
}; };
}; };