Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - improve CBA_fnc_addMagazine and CBA_fnc_addMagazineCargo #1527

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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