Skip to content

Commit

Permalink
Fix bug where supply crate wouldn't have correct ammo
Browse files Browse the repository at this point in the history
  • Loading branch information
theace0296 committed Oct 24, 2021
1 parent 2aab0ef commit cf5c612
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions RandFramework/Global/common/fn_initAmmoBox.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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;

0 comments on commit cf5c612

Please sign in to comment.