2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2022-05-18 18:07:47 +00:00
|
|
|
/*
|
2023-08-26 16:04:31 +00:00
|
|
|
* Author: drofseh, commy2, johnb43
|
2022-05-18 18:07:47 +00:00
|
|
|
* Unload the magazine from the unit's weapon and attempt to put it in a sensible place.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2023-08-26 16:04:31 +00:00
|
|
|
* 0: Unit <OBJECT>
|
2022-05-18 18:07:47 +00:00
|
|
|
* 1: Weapon <STRING>
|
2023-08-26 16:04:31 +00:00
|
|
|
* 2: Muzzle (default: Weapon) <STRING>
|
|
|
|
* 3: Magazine (default: magazine in Weapon) <STRING>
|
|
|
|
* 4: Ammo count (default: Unit ammo Muzzle) <NUMBER>
|
|
|
|
* 5: Skip animation? (default: false) <BOOL>
|
2022-05-18 18:07:47 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2023-08-26 16:04:31 +00:00
|
|
|
* [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player, currentMagazine ACE_player, 23, false] call ace_common_fnc_unloadUnitWeapon
|
2022-05-18 18:07:47 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
params ["_unit", "_weapon", "_muzzle", "_magazine", "_ammoCount", ["_skipAnim", false]];
|
|
|
|
TRACE_6("params",_unit,_weapon,_muzzle,_magazine,_ammoCount,_skipAnim);
|
2022-05-18 18:07:47 +00:00
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
if (_unit getVariable [QGVAR(isUnloadingWeapon), false]) exitWith {};
|
|
|
|
|
|
|
|
// Only allow 1 weapon to be unloaded at a time (because of animation length)
|
|
|
|
_unit setVariable [QGVAR(isUnloadingWeapon), true];
|
|
|
|
|
|
|
|
if (isNil "_muzzle") then {
|
|
|
|
_muzzle = _weapon;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (isNil "_magazine") then {
|
|
|
|
private _weaponState = _unit weaponState _muzzle;
|
|
|
|
|
|
|
|
_magazine = _weaponState select 3;
|
|
|
|
_ammoCount = _weaponState select 4;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (isNil "_ammoCount") then {
|
|
|
|
_ammoCount = _unit ammo _muzzle;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Audiovisual effects
|
2022-05-18 18:07:47 +00:00
|
|
|
private _delay = 0;
|
2023-08-26 16:04:31 +00:00
|
|
|
|
|
|
|
if (!_skipAnim) then {
|
2022-05-18 18:07:47 +00:00
|
|
|
_delay = 1.5;
|
2023-08-26 16:04:31 +00:00
|
|
|
|
2022-05-18 18:07:47 +00:00
|
|
|
private _config = configFile >> "CfgWeapons" >> _weapon;
|
2023-08-26 16:04:31 +00:00
|
|
|
|
2022-05-18 18:07:47 +00:00
|
|
|
if (_weapon != _muzzle) then {
|
|
|
|
_config = _config >> _muzzle;
|
|
|
|
};
|
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
// Get and play animation
|
2022-05-18 18:07:47 +00:00
|
|
|
private _unloadAction = getText (_config >> "ACE_unloadAction");
|
|
|
|
|
|
|
|
if (_unloadAction == "") then {
|
|
|
|
_unloadAction = getText (_config >> "reloadAction");
|
|
|
|
};
|
|
|
|
|
|
|
|
[_unit, _unloadAction, 1] call FUNC(doGesture);
|
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
// Get and play sound
|
2022-05-18 18:07:47 +00:00
|
|
|
private _unloadSound = getText (_config >> "ACE_unloadSound");
|
|
|
|
|
|
|
|
if (_unloadSound == "") then {
|
|
|
|
_unloadSound = "A3\Sounds_F\arsenal\weapons\Rifles\Katiba\reload_Katiba.wss";
|
2023-08-26 16:04:31 +00:00
|
|
|
|
2022-05-18 18:07:47 +00:00
|
|
|
private _unloadSoundArray = getArray (_config >> "reloadMagazineSound");
|
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
// File extention is required for playSound3D
|
2022-05-18 18:07:47 +00:00
|
|
|
if (_unloadSoundArray isNotEqualTo []) then {
|
|
|
|
private _wssTest = format ["%1.wss", _unloadSoundArray select 0];
|
2023-08-26 16:04:31 +00:00
|
|
|
|
2022-05-18 18:07:47 +00:00
|
|
|
if (fileExists _wssTest) then {
|
|
|
|
_unloadSound = _wssTest;
|
|
|
|
} else {
|
|
|
|
private _wavTest = format ["%1.wav", _unloadSoundArray select 0];
|
2023-08-26 16:04:31 +00:00
|
|
|
|
2022-05-18 18:07:47 +00:00
|
|
|
if (fileExists _wavTest) then {
|
|
|
|
_unloadSound = _wavTest;
|
2023-08-26 16:04:31 +00:00
|
|
|
} else {
|
|
|
|
private _oggTest = format ["%1.ogg", _unloadSoundArray select 0];
|
|
|
|
|
|
|
|
if (fileExists _oggTest) then {
|
|
|
|
_unloadSound = _oggTest;
|
|
|
|
};
|
2022-05-18 18:07:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
playSound3D [_unloadSound, _unit];
|
|
|
|
};
|
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
// Remove magazine from weapon and add it to inventory
|
2022-05-18 18:07:47 +00:00
|
|
|
[{
|
2023-08-26 16:04:31 +00:00
|
|
|
params ["_unit", "_weapon", "_muzzle", "_magazine", "_ammoCount"];
|
|
|
|
|
|
|
|
_unit setVariable [QGVAR(isUnloadingWeapon), nil];
|
2022-05-18 18:07:47 +00:00
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
private _returnMagazine = true;
|
2022-05-18 18:07:47 +00:00
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
// Check if it's possible to remove given item from weapon; If possible, remove weapon item
|
|
|
|
switch (true) do {
|
|
|
|
case (_weapon == primaryWeapon _unit && {_weapon canAdd [_magazine, _muzzle]}): {
|
|
|
|
_unit removePrimaryWeaponItem _magazine;
|
2022-05-18 18:07:47 +00:00
|
|
|
};
|
2023-08-26 16:04:31 +00:00
|
|
|
case (_weapon == handgunWeapon _unit && {_weapon canAdd [_magazine, _muzzle]}): {
|
|
|
|
_unit removeHandgunItem _magazine;
|
2022-05-18 18:07:47 +00:00
|
|
|
};
|
2023-08-26 16:04:31 +00:00
|
|
|
case (_weapon == secondaryWeapon _unit && {_weapon canAdd [_magazine, _muzzle]}): {
|
|
|
|
_unit removeSecondaryWeaponItem _magazine;
|
|
|
|
};
|
|
|
|
default {
|
|
|
|
_returnMagazine = false;
|
2022-05-18 18:07:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-26 16:04:31 +00:00
|
|
|
// Avoid duplicating magazines (e.g. by switching weapons mid unload)
|
|
|
|
if (!_returnMagazine) exitWith {};
|
|
|
|
|
|
|
|
[_unit, _magazine, _ammoCount, true] call CBA_fnc_addMagazine;
|
|
|
|
}, [_unit, _weapon, _muzzle, _magazine, _ammoCount], _delay] call CBA_fnc_waitAndExecute;
|