Skip to content

Commit

Permalink
Common - Improve CBA_fnc_addItem, Fix CBA_fnc_addMagazine return (#1562)
Browse files Browse the repository at this point in the history
* Attempt to add item to vehicle if unit in vehicle

Attempt to add the item to the unit's vehicle instead of always chucking it out the window onto the ground.

* fix return for addMagazine and addItem
  • Loading branch information
Drofseh committed Jun 24, 2023
1 parent 9fd18c2 commit 4ee49d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions addons/common/fnc_addItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Description:
Parameters:
_unit - the unit <OBJECT>
_item - name of the weapon to add <STRING>
_verify - if true, then put item on the ground if it can't be added <BOOLEAN>
_verify - if true, then put item in vehicle or on the ground if it can't be added <BOOLEAN>
Returns:
true on success, false otherwise <BOOLEAN>
Expand Down Expand Up @@ -52,16 +52,21 @@ if (_verify) then {
_unit addItem _item;
_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_addItemCargo;
[_weaponHolder, _item, 1, _verify] call CBA_fnc_addItemCargo;
} else {
[_vehicle, _item, 1, _verify] call CBA_fnc_addItemCargo;
};
};
} else {
_unit addItem _item;
Expand Down
6 changes: 3 additions & 3 deletions addons/common/fnc_addMagazine.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Parameters:
_unit - the unit or vehicle <OBJECT>
_item - name of the magazine to add <STRING>
_ammo - ammo count <NUMBER>
_verify - if true, then put item on the ground if it can't be added <BOOLEAN>
_verify - if true, then put item in vehicle or on the ground if it can't be added <BOOLEAN>
Returns:
true on success, false otherwise <BOOLEAN>
Expand Down Expand Up @@ -69,9 +69,9 @@ if (_verify) then {
_weaponHolder setPosASL getPosASL _unit;
};

_return = [_weaponHolder, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo;
[_weaponHolder, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo;
} else {
_return = [_vehicle, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo;
[_vehicle, _item, 1, _verify, _ammo] call CBA_fnc_addMagazineCargo;
};
};
} else {
Expand Down

0 comments on commit 4ee49d4

Please sign in to comment.