|
| 1 | +#include "script_component.hpp" |
| 2 | +/* |
| 3 | + * Author: DiGii |
| 4 | + * Drop current weapon magazine on the ground and reload from inventory |
| 5 | + * |
| 6 | + * Arguments: |
| 7 | + * 0: Player <OBJECT> |
| 8 | + * 1: Weapon <STRING> |
| 9 | + * 2: Muzzle (optional, default: Weapon)<STRING> |
| 10 | + * 3: Ammo count (optional, default: ammo currentMuzzle Player) <NUMBER> |
| 11 | + * |
| 12 | + * Return Value: |
| 13 | + * None |
| 14 | + * |
| 15 | + * Example: |
| 16 | +* [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player, 23] call digii_main_fnc_fastReload; |
| 17 | + * |
| 18 | + * Public: No |
| 19 | + */ |
| 20 | + |
| 21 | + |
| 22 | +params ["_unit", "_weapon", ["_muzzle", _weapon], ["_ammoCount", _unit ammo _muzzle ]]; |
| 23 | + |
| 24 | +private _delay = 2; |
| 25 | +[_unit, "ReloadMagazine", 1] call ACEFUNC(common,doGesture); |
| 26 | + |
| 27 | +[{ |
| 28 | + params ["_unit", "_weapon", "_ammoCount", "_muzzle"]; |
| 29 | + |
| 30 | + // remove weapon item |
| 31 | + private _magazineClass = currentMagazine _unit; |
| 32 | + |
| 33 | + switch true do { |
| 34 | + case (_weapon == primaryWeapon _unit): { |
| 35 | + _unit removePrimaryWeaponItem _magazineClass; |
| 36 | + }; |
| 37 | + case (_weapon == handgunWeapon _unit): { |
| 38 | + _unit removeHandgunItem _magazineClass; |
| 39 | + }; |
| 40 | + case (_weapon == secondaryWeapon _unit): { |
| 41 | + _unit removeSecondaryWeaponItem _magazineClass; |
| 42 | + }; |
| 43 | + }; |
| 44 | + |
| 45 | + private _weaponHolder = createVehicle ["Weapon_Empty", getPosATL _unit, [], 0, "CAN_COLLIDE"]; |
| 46 | + _weaponHolder addMagazineAmmoCargo [_magazineClass, 1, _ammoCount]; |
| 47 | + |
| 48 | + |
| 49 | + private _currentMagazines = magazinesAmmo _unit; |
| 50 | + private _compatibleMagazines = compatibleMagazines _weapon; |
| 51 | + |
| 52 | + // Load new magazine from inventory |
| 53 | + { |
| 54 | + if ((_x select 0) in _compatibleMagazines) exitWith |
| 55 | + { |
| 56 | + _unit addWeaponItem [_weapon, [_x select 0, _x select 1, _muzzle], true]; |
| 57 | + _unit removeMagazineGlobal (_x select 0); |
| 58 | + } |
| 59 | + } forEach _currentMagazines |
| 60 | + |
| 61 | +}, [_unit, _weapon, _ammoCount, _muzzle], _delay] call CBA_fnc_waitAndExecute; |
| 62 | + |
0 commit comments