From 6817bb2aff65c5f3d4995907a5bdafe3bff796be Mon Sep 17 00:00:00 2001 From: Drofseh Date: Sat, 27 Nov 2021 00:47:45 -0800 Subject: [PATCH 1/3] improve CBA_fnc_addMagazine and CBA_fnc_addMagazineCargo - improve CBA_fnc_addMagazineCargo by allowing the number of rounds to be specified. - improve CBA_fnc_addMagazine by trying to add the magazine to vehicle _unit before throwing it out the window onto the ground, and also pass ammo count to CBA_fnc_addMagazineCargo, so that a partial mag doesn't magically become full --- addons/common/fnc_addMagazine.sqf | 21 +++++++++++++-------- addons/common/fnc_addMagazineCargo.sqf | 11 ++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/addons/common/fnc_addMagazine.sqf b/addons/common/fnc_addMagazine.sqf index e1ab8e1fc0..014d19ca13 100644 --- a/addons/common/fnc_addMagazine.sqf +++ b/addons/common/fnc_addMagazine.sqf @@ -49,7 +49,7 @@ if (!isClass _config || {getNumber (_config >> "scope") < 2}) exitWith { }; if (_verify) then { - if (_unit canAdd _item) then { + if (_unit canAdd _item || {[_unit, _item, 1, true, true, true] call CBA_fnc_canAddItem}) then { // canAdd works for vehicles and units, CBA_fnc_canAddItem is more precise for units, but only try if canAdd fails for them if (_ammo < 0) then { _unit addMagazine [_item, 1E6]; // addMagazine STRING is not synched when used on remote units. addMagazine ARRAY is. } else { @@ -58,16 +58,21 @@ if (_verify) then { _return = true; } else { - _unit switchMove "ainvpknlmstpslaywrfldnon_1"; + private _vehicleUnit = vehicle _unit; + if (_vehicleUnit isEqualTo _unit) then { + _unit switchMove "ainvpknlmstpslaywrfldnon_1"; - private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; + private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; - if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then { - _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; - _weaponHolder setPosASL getPosASL _unit; - }; + if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then { + _weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; + _weaponHolder setPosASL getPosASL _unit; + }; - [_weaponHolder, _item] call CBA_fnc_addMagazineCargo; + _return = [_weaponHolder, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo; + } else { + _return = [_vehicleUnit, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo; + }; }; } else { if (_ammo < 0) then { diff --git a/addons/common/fnc_addMagazineCargo.sqf b/addons/common/fnc_addMagazineCargo.sqf index f57fab7b42..56d3979fe6 100644 --- a/addons/common/fnc_addMagazineCargo.sqf +++ b/addons/common/fnc_addMagazineCargo.sqf @@ -13,6 +13,7 @@ Parameters: _item - name of magazine to _count - number of magazines to add (Default: 1) _verify - if true, then put item on the ground if it can't be added + _ammo - ammo count (Default: 1E6) Returns: true on success, false otherwise @@ -31,7 +32,7 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(addMagazineCargo); -params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]], ["_verify", false, [false]]]; +params [["_container", objNull, [objNull]], ["_item", "", [""]], ["_count", 1, [0]], ["_verify", false, [false]], ["_ammo", 1E6, [0]]]; private _return = false; @@ -54,11 +55,11 @@ if (isNull _config || {getNumber (_config >> "scope") < 2}) exitWith { if (_verify) then { if (_container canAdd [_item, _count]) then { - _container addMagazineCargoGlobal [_item, _count]; + _container addMagazineAmmoCargo [_item, _count, _ammo]; _return = true; } else { while {_container canAdd _item && {_count > 0}} do { - _container addMagazineCargoGlobal [_item, 1]; + _container addMagazineAmmoCargo [_item, 1, _ammo]; _count = _count - 1; }; @@ -69,10 +70,10 @@ if (_verify) then { _weaponHolder setPosATL (getPosATL _container vectorAdd [random 2 - 1, random 2 - 1, 0]); }; - _weaponHolder addMagazineCargoGlobal [_item, _count]; + _weaponHolder addMagazineAmmoCargo [_item, _count, _ammo]; }; } else { - _container addMagazineCargoGlobal [_item, _count]; + _container addMagazineAmmoCargo [_item, _count, _ammo]; _return = true; }; From 673d2cd0841c1fce71900897fbea54c6eb936042 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Sat, 27 Nov 2021 09:51:36 -0800 Subject: [PATCH 2/3] changes from suggestion --- addons/common/fnc_addMagazine.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/common/fnc_addMagazine.sqf b/addons/common/fnc_addMagazine.sqf index 014d19ca13..db16b0b49b 100644 --- a/addons/common/fnc_addMagazine.sqf +++ b/addons/common/fnc_addMagazine.sqf @@ -58,8 +58,8 @@ if (_verify) then { _return = true; } else { - private _vehicleUnit = vehicle _unit; - if (_vehicleUnit isEqualTo _unit) then { + private _vehicle = vehicle _unit; + if (_vehicle isEqualTo _unit) then { _unit switchMove "ainvpknlmstpslaywrfldnon_1"; private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; @@ -71,7 +71,7 @@ if (_verify) then { _return = [_weaponHolder, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo; } else { - _return = [_vehicleUnit, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo; + _return = [_vehicle, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo; }; }; } else { From b51c8e3161530b87276cb799b4cc23ddb0ba2980 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Sat, 27 Nov 2021 18:17:44 -0800 Subject: [PATCH 3/3] use CBA_fnc_canAddItem only - use CBA_fnc_canAddItem only, requires #1528 --- addons/common/fnc_addMagazine.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/fnc_addMagazine.sqf b/addons/common/fnc_addMagazine.sqf index db16b0b49b..e5771669eb 100644 --- a/addons/common/fnc_addMagazine.sqf +++ b/addons/common/fnc_addMagazine.sqf @@ -49,7 +49,7 @@ if (!isClass _config || {getNumber (_config >> "scope") < 2}) exitWith { }; if (_verify) then { - if (_unit canAdd _item || {[_unit, _item, 1, true, true, true] call CBA_fnc_canAddItem}) then { // canAdd works for vehicles and units, CBA_fnc_canAddItem is more precise for units, but only try if canAdd fails for them + if ([_unit, _item, 1, true, true, true] call CBA_fnc_canAddItem) then { if (_ammo < 0) then { _unit addMagazine [_item, 1E6]; // addMagazine STRING is not synched when used on remote units. addMagazine ARRAY is. } else {