Skip to content

Commit

Permalink
Merge pull request #1262 from CBATeam/update-dropWeapon
Browse files Browse the repository at this point in the history
update CBA_fnc_dropWeapon
  • Loading branch information
commy2 committed Dec 3, 2019
2 parents 939c70e + 28498a4 commit c4daf20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
39 changes: 11 additions & 28 deletions addons/common/fnc_dropWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Function: CBA_fnc_dropWeapon
Description:
Drops a weapon.
Drops a weapon (including binocular).
Function which verifies existence of _item and _unit, returns false in case
of trouble, or when able to remove _item from _unit true in case of success
Expand All @@ -21,32 +21,23 @@ Examples:
(end)
Author:
?, commy2
commy2
---------------------------------------------------------------------------- */
SCRIPT(dropWeapon);

params [["_unit", objNull, [objNull]], ["_item", "", [""]]];

private _weaponInfo = (weaponsItems _unit select {_x select 0 == _item}) param [0, []];
private _return = [_unit, _item] call CBA_fnc_removeWeapon;

if (_return) then {
private _baseWeapon = _item call CBA_fnc_weaponComponents param [0, _item];

private _items = _weaponInfo;
_items deleteAt 0; // delete the weapon

private _magazines = [];
private _weaponInfo = [];

{
if (_x isEqualType []) then {
_magazines pushBack _x;
_items set [_forEachIndex, ""];
};
} forEach _items;
{
if (_x param [0, ""] == _item) exitWith {
_weaponInfo = _x;
};
} forEach weaponsItems _unit;

_items = _items - [""];
private _return = [_unit, _item] call CBA_fnc_removeWeapon;

if (_return) then {
_unit switchMove "ainvpknlmstpslaywrfldnon_1";

private _weaponHolder = nearestObject [_unit, "WeaponHolder"];
Expand All @@ -56,15 +47,7 @@ if (_return) then {
_weaponHolder setPosASL getPosASL _unit;
};

_weaponHolder addWeaponCargoGlobal [_baseWeapon, 1];

{
_weaponHolder addItemCargoGlobal [_x, 1];
} forEach _items;

{
_weaponHolder addMagazineAmmoCargo [_x select 0, 1, _x select 1];
} forEach _magazines;
_weaponHolder addWeaponWithAttachmentsCargoGlobal [_weaponInfo, 1];
};

_return
2 changes: 1 addition & 1 deletion addons/common/fnc_removeWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Function: CBA_fnc_removeWeapon
Description:
Remove a weapon.
Remove a weapon (including binocular).
Function which verifies existence of _item and _unit, returns false in case
of trouble, or when able to remove _item from _unit true in case of success.
Expand Down

0 comments on commit c4daf20

Please sign in to comment.