From cf5c61206b3ada7c40f784226077b4c020791989 Mon Sep 17 00:00:00 2001 From: Chase <29675446+theace0296@users.noreply.github.com> Date: Sun, 24 Oct 2021 19:13:23 -0400 Subject: [PATCH] Fix bug where supply crate wouldn't have correct ammo --- .../Global/common/fn_initAmmoBox.sqf | 90 +++++++++++-------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/RandFramework/Global/common/fn_initAmmoBox.sqf b/RandFramework/Global/common/fn_initAmmoBox.sqf index 25eeb2a1..4c7da69d 100644 --- a/RandFramework/Global/common/fn_initAmmoBox.sqf +++ b/RandFramework/Global/common/fn_initAmmoBox.sqf @@ -15,11 +15,23 @@ * [box1, units group player] call TRGM_GLOBAL_fnc_initAmmoBox */ -params [["_box", objNull, [objNull]], ["_units", []]]; +params [["_box", objNull, [objNull]], ["_units", [], [objNull, []]]]; +if (isNil "_box" || {isNull _box}) exitWith {}; +private _allPlayers = ((allPlayers - (entities "HeadlessClient_F")); -if (isNil "_box") exitWith {}; +if (typeName _units isEqualTo "OBJECT") then { + _units = units group _units; +}; + +if (_units isEqualTo []) then { + _units = _allPlayers select {(_x distance2D _box) < 1500}); +}; + +if (_units isEqualTo []) then { + _units = _allPlayers; +}; private _initBoxItems = [TRGM_VAR_InitialBoxItems, TRGM_VAR_InitialBoxItemsWithAce] select (call TRGM_GLOBAL_fnc_isAceLoaded); _initBoxItems params [ @@ -50,48 +62,48 @@ _classes = _list select 0; _values = _list select 1; {_box addbackpackcargoglobal [_x,_values select _foreachindex];} foreach _classes; -if (count _units > 0) then { +if (_units isEqualTo []) exitWith { true; }; + +{ + TRGM_LOCAL_fnc_isWeaponValid = { + (isClass(configFile >> "CfgWeapons" >> _this) && {getNumber(configFile >> "CfgWeapons" >> _this >> "scope") isEqualTo 2}); + }; + TRGM_LOCAL_fnc_isMagazineValid = { + (isClass(configFile >> "CfgMagazines" >> _this) && {getNumber(configFile >> "CfgMagazines" >> _this >> "scope") isEqualTo 2}); + }; + private _weapons = [[primaryWeapon _x, primaryWeaponMagazine _x], [secondaryWeapon _x, secondaryWeaponMagazine _x], [handgunWeapon _x, handgunMagazine _x], ["", magazines _x]]; { - TRGM_LOCAL_fnc_isWeaponValid = { - (isClass(configFile >> "CfgWeapons" >> _this) && {getNumber(configFile >> "CfgWeapons" >> _this >> "scope") isEqualTo 2}); + _x params ["_weapon", "_mags"]; + if (_weapon != "" && {_weapon call TRGM_LOCAL_fnc_isWeaponValid}) then { + _box addWeaponCargoGlobal [_weapon, 1]; + format["Weapon: %2 added to %1", str _box, _weapon] call TRGM_GLOBAL_fnc_log; + if ({_x call TRGM_LOCAL_fnc_isMagazineValid} count _mags isEqualTo 0) then { + _mags = getArray(configfile >> "CfgWeapons" >> _weapon >> "magazines"); + }; + { + _box addMagazineCargoGlobal [_x, 2]; + format["Mags: %2 added to %1", str _box, _x] call TRGM_GLOBAL_fnc_log; + } forEach (_mags select {_x call TRGM_LOCAL_fnc_isMagazineValid}); }; - TRGM_LOCAL_fnc_isMagazineValid = { - (isClass(configFile >> "CfgMagazines" >> _this) && {getNumber(configFile >> "CfgMagazines" >> _this >> "scope") isEqualTo 2}); + if (_weapon isEqualTo "" && {{_x call TRGM_LOCAL_fnc_isMagazineValid} count _mags > 0}) then { + { + _box addMagazineCargoGlobal [_x, 2]; + format["Mags: %2 added to %1", str _box, _x] call TRGM_GLOBAL_fnc_log; + } forEach (_mags select {_x call TRGM_LOCAL_fnc_isMagazineValid}); }; - private _weapons = [[primaryWeapon _x, primaryWeaponMagazine _x], [secondaryWeapon _x, secondaryWeaponMagazine _x], [handgunWeapon _x, handgunMagazine _x], ["", magazines _x]]; - { - _x params ["_weapon", "_mags"]; - if (_weapon != "" && {_weapon call TRGM_LOCAL_fnc_isWeaponValid}) then { - _box addWeaponCargoGlobal [_weapon, 1]; - format["Weapon: %2 added to %1", str _box, _weapon] call TRGM_GLOBAL_fnc_log; - if ({_x call TRGM_LOCAL_fnc_isMagazineValid} count _mags isEqualTo 0) then { - _mags = getArray(configfile >> "CfgWeapons" >> _weapon >> "magazines"); - }; - { - _box addMagazineCargoGlobal [_x, 2]; - format["Mags: %2 added to %1", str _box, _x] call TRGM_GLOBAL_fnc_log; - } forEach (_mags select {_x call TRGM_LOCAL_fnc_isMagazineValid}); - }; - if (_weapon isEqualTo "" && {{_x call TRGM_LOCAL_fnc_isMagazineValid} count _mags > 0}) then { - { - _box addMagazineCargoGlobal [_x, 2]; - format["Mags: %2 added to %1", str _box, _x] call TRGM_GLOBAL_fnc_log; - } forEach (_mags select {_x call TRGM_LOCAL_fnc_isMagazineValid}); - }; - } forEach _weapons; + } forEach _weapons; - { - _box addItemCargoGlobal [_x, 1]; - format["Item: %2 added to %1", str _box, _x] call TRGM_GLOBAL_fnc_log; - } forEach items _x; + { + _box addItemCargoGlobal [_x, 1]; + format["Item: %2 added to %1", str _box, _x] call TRGM_GLOBAL_fnc_log; + } forEach items _x; - // Scope isEqualTo 2 excludes protected backpacks that act strange when in an inventory (can't remove, infinite items, etc...) - if (typeof(unitBackpack _x) != "" && isClass(configfile >> "CfgVehicles" >> typeof(unitBackpack _x)) && getNumber(configfile >> "CfgVehicles" >> typeof(unitBackpack _x) >> "scope") isEqualTo 2) then { - _box addBackpackCargoGlobal [typeof(unitBackpack _x), 1]; - format["Backpack: %2 added to %1", str _box, typeof(unitBackpack _x)] call TRGM_GLOBAL_fnc_log; - }; + // Scope isEqualTo 2 excludes protected backpacks that act strange when in an inventory (can't remove, infinite items, etc...) + if (typeof(unitBackpack _x) != "" && isClass(configfile >> "CfgVehicles" >> typeof(unitBackpack _x)) && getNumber(configfile >> "CfgVehicles" >> typeof(unitBackpack _x) >> "scope") isEqualTo 2) then { + _box addBackpackCargoGlobal [typeof(unitBackpack _x), 1]; + format["Backpack: %2 added to %1", str _box, typeof(unitBackpack _x)] call TRGM_GLOBAL_fnc_log; + }; - } forEach _units; -}; +} forEach _units; true; \ No newline at end of file