ACE3/addons/csw/functions/fnc_unloadMagazines.sqf

46 lines
1.3 KiB
Plaintext
Raw Normal View History

2023-12-18 16:47:01 +00:00
#include "..\script_component.hpp"
2023-07-13 16:53:57 +00:00
/*
* Author: LinkIsGrim
2023-12-18 16:47:01 +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)
2023-07-14 15:43:19 +00:00
* 1: Turret Path or True to unload all turrets <ARRAY|BOOL> (default: [0])
2023-07-13 17:01:33 +00:00
* 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-12-18 16:47:01 +00:00
2023-07-13 21:12:18 +00:00
params [["_vehicle", objNull, [objNull]], ["_turretPath", [0], [[0], true]], ["_returnMags", true, [true]]];
2023-07-13 17:01:33 +00:00
if (!alive _vehicle) exitWith {};
2023-07-13 16:53:57 +00:00
private _magsToRemove = [];
private _carryMagazines = createHashMap;
2023-07-13 16:53:57 +00:00
{
_x params ["_xMag", "_xTurret", "_xAmmo"];
2023-07-13 21:12:18 +00:00
if (_xTurret isNotEqualTo _turretPath && {_turretPath isNotEqualTo true}) then {continue};
2023-07-13 16:53:57 +00:00
private _carryMag = _xMag call FUNC(getCarryMagazine);
if (_carryMag != "") then {
_magsToRemove pushBackUnique [_xMag, _xTurret];
_carryMagazines set [_carryMag, (_carryMagazines getOrDefault [_carryMag, 0]) + _xAmmo];
2023-07-13 16:53:57 +00:00
};
2023-07-13 21:12:18 +00:00
} forEach (magazinesAllTurrets _vehicle);
2023-07-13 16:53:57 +00:00
{
[QEGVAR(common,removeMagazinesTurret), [_vehicle, _x select 0, _x select 1], _vehicle, _x select 1] call CBA_fnc_turretEvent;
2023-07-13 16:53:57 +00:00
} forEach _magsToRemove;
2023-07-13 17:01:33 +00:00
if (_returnMags) then {
{
[_vehicle, _x, _y] call FUNC(reload_handleReturnAmmo);
} forEach _carryMagazines;
2023-07-13 17:01:33 +00:00
};