ACE3/addons/csw/functions/fnc_unloadMagazines.sqf

51 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-07-13 16:53:57 +00:00
#include "script_component.hpp"
/*
* Author: LinkIsGrim
2023-07-13 17:01:33 +00:00
* Unloads and returns magazines from a CSW
2023-07-13 16:53:57 +00:00
*
* Arguments:
2023-07-13 17:01:33 +00:00
* 0: CSW <OBJECT> (default: objNull)
* 1: Turret Path <ARRAY> (default: [0], gunner turret)
* 2: Return removed magazines <BOOL> (default: true)
2023-07-13 16:53:57 +00:00
*
* Return Value:
* None
*
2023-07-13 17:01:33 +00:00
* Example:
* [cursorTarget, [0]] call ace_csw_fnc_unloadMagazines
*
* Public: Yes
2023-07-13 16:53:57 +00:00
*/
2023-07-13 17:01:33 +00:00
params [["_vehicle", objNull, [objNull]], ["_turretPath", [0], [0]], ["_returnMags", true, [true]]];
if (isNull _vehicle) exitWith {};
2023-07-13 16:53:57 +00:00
private _magsToRemove = [];
private _containerMagazineClassnames = [];
private _containerMagazineCount = [];
{
_x params ["_xMag", "_xTurret", "_xAmmo"];
if (_xTurret isNotEqualTo _turretPath) then {continue};
private _carryMag = _xMag call FUNC(getCarryMagazine);
if (_carryMag != "") then {
_magsToRemove pushBackUnique [_xMag, _xTurret];
private _index = _containerMagazineClassnames find _carryMag;
if (_index < 0) then {
_index = _containerMagazineClassnames pushBack _carryMag;
_containerMagazineCount pushBack 0;
};
_containerMagazineCount set [_index, (_containerMagazineCount select _index) + _xAmmo];
};
} forEach (_vehicle magazinesAllTurrets _vehicle);
{
_vehicle removeMagazinesTurret _x;
} forEach _magsToRemove;
2023-07-13 17:01:33 +00:00
if (_returnMags) then {
{
[_vehicle, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo);
} forEach _containerMagazineClassnames;
};