Skip to content

Commit

Permalink
Merge pull request #1527 from Drofseh/improve-fnc_addMagazineCargo-an…
Browse files Browse the repository at this point in the history
…d-fnc_addMagazine

Common - improve CBA_fnc_addMagazine and CBA_fnc_addMagazineCargo
  • Loading branch information
PabstMirror authored Mar 19, 2022
2 parents 3199775 + b51c8e3 commit 2580475
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
21 changes: 13 additions & 8 deletions addons/common/fnc_addMagazine.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (!isClass _config || {getNumber (_config >> "scope") < 2}) exitWith {
};

if (_verify) then {
if (_unit canAdd _item) then {
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 {
Expand All @@ -58,16 +58,21 @@ if (_verify) then {

_return = true;
} else {
_unit switchMove "ainvpknlmstpslaywrfldnon_1";
private _vehicle = vehicle _unit;
if (_vehicle 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 = [_vehicle, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo;
};
};
} else {
if (_ammo < 0) then {
Expand Down
11 changes: 6 additions & 5 deletions addons/common/fnc_addMagazineCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Parameters:
_item - name of magazine to <STRING>
_count - number of magazines to add <NUMBER> (Default: 1)
_verify - if true, then put item on the ground if it can't be added <BOOLEAN>
_ammo - ammo count <NUMBER> (Default: 1E6)
Returns:
true on success, false otherwise <BOOLEAN>
Expand All @@ -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;

Expand All @@ -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;
};

Expand All @@ -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;
};

Expand Down

0 comments on commit 2580475

Please sign in to comment.