From b438e43d4aa64c799ac5886935ac8a7b7e869c46 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Fri, 10 Dec 2021 23:30:11 -0800 Subject: [PATCH 1/7] add keybind and function to unload unit's weapon/muzzle - add keybind and function to unload unit's weapon/muzzle - requires https://github.com/CBATeam/CBA_A3/pull/1527 --- addons/common/XEH_PREP.hpp | 1 + addons/common/XEH_postInit.sqf | 17 ++++ .../common/functions/fnc_unloadWeaponMan.sqf | 87 +++++++++++++++++++ addons/common/stringtable.xml | 3 + 4 files changed, 108 insertions(+) create mode 100644 addons/common/functions/fnc_unloadWeaponMan.sqf diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 4b547655394..c252c55701c 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -187,6 +187,7 @@ PREP(uniqueElements); PREP(uniqueItems); PREP(unloadPerson); PREP(unloadPersonLocal); +PREP(unloadWeaponMan); PREP(unmuteUnit); PREP(useItem); PREP(useMagazine); diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 78a50913691..2f725c6e7d4 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -527,4 +527,21 @@ GVAR(deviceKeyCurrentIndex) = -1; {false}, [0xC7, [true, false, false]], false] call CBA_fnc_addKeybind; //SHIFT + Home Key + +["ACE3 Weapons", QGVAR(unloadWeapon), localize LSTRING(unloadWeapon), { + // Conditions: + if !([ACE_player, objNull, ["isNotInside"]] call FUNC(canInteractWith)) exitWith {false}; + + private _currentWeapon = currentWeapon ACE_player; + if !(_currentWeapon != primaryWeapon _unit && {_currentWeapon != handgunWeapon _unit} && {_currentWeapon != secondaryWeapon _unit}) exitWith {false}; + + private _currentMuzzle = currentMuzzle ACE_player; + private _currentAmmoCount = ACE_player ammo _currentMuzzle; + if (_currentAmmoCount < 1) exitWith {false}; + + // Statement: + [ACE_player, _currentWeapon, _currentMuzzle, _currentAmmoCount, false] call FUNC(unloadWeaponMan); + true +}, {false}, [19, [false, false, true]], false] call CBA_fnc_addKeybind; //ALT + R Key + GVAR(commonPostInited) = true; diff --git a/addons/common/functions/fnc_unloadWeaponMan.sqf b/addons/common/functions/fnc_unloadWeaponMan.sqf new file mode 100644 index 00000000000..1da0b43d42f --- /dev/null +++ b/addons/common/functions/fnc_unloadWeaponMan.sqf @@ -0,0 +1,87 @@ +#include "script_component.hpp" +/* + * Author: drofseh & Commy2 + * Unload the magazine from the unit's weapon and attempt to put it in a sensible place. + * + * Arguments: + * 0: Player + * 1: Weapon + * 2: Muzzle (optional, default: Weapon) + * 3: Ammo count (optional, default: ammo currentMuzzle Player) + * 4: Skip animation? (optional, default: false) + * + * Return Value: + * None + * + * Example: + * [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player, 23, false] call ace_common_fnc_unloadWeaponMan + * + * Public: No + */ + +params ["_unit", "_weapon", ["_muzzle", _weapon], ["_ammoCount", ammo _muzzle _unit], ["_skipAnim", false]]; +TRACE_5("params",_unit,_weapon,_muzzle,_ammoCount,_skipAnim); + +// audiovisual effects +private _delay = 0; +if !(_skipAnim) then { + _delay = 1.5; + private _config = configFile >> "CfgWeapons" >> _weapon; + if (_weapon != _muzzle) then { + _config = _config >> _muzzle; + }; + + // get and play animation + private _unloadAction = getText (_config >> "ACE_unloadAction"); + + if (_unloadAction == "") then { + _unloadAction = getText (_config >> "reloadAction"); + }; + + [_unit, _unloadAction, 1] call FUNC(doGesture); + + // get and play sound + private _unloadSound = getText (_config >> "ACE_unloadSound"); + + if (_unloadSound == "") then { + _unloadSound = "A3\Sounds_F\arsenal\weapons\Rifles\Katiba\reload_Katiba.wss"; + private _unloadSoundArray = getArray (_config >> "reloadMagazineSound"); + + // file extention is required for playSound3D + if (_unloadSoundArray isNotEqualTo []) then { + private _wssTest = format ["%1.wss", _unloadSoundArray select 0]; + if (fileExists _wssTest) then { + _unloadSound = _wssTest; + } else { + private _wavTest = format ["%1.wav", _unloadSoundArray select 0]; + if (fileExists _wavTest) then { + _unloadSound = _wavTest; + }; + }; + }; + }; + + playSound3D [_unloadSound, _unit]; +}; + +// remove magazine from weapon and add it to inventory +[{ + params ["_unit", "_weapon", "_ammoCount"]; + + // remove weapon item + private _magazineClass = currentMagazine _unit; + + switch true do { + case (_weapon == primaryWeapon _unit): { + _unit removePrimaryWeaponItem _magazineClass; + }; + case (_weapon == handgunWeapon _unit): { + _unit removeHandgunItem _magazineClass; + }; + case (_weapon == secondaryWeapon _unit): { + _unit removeSecondaryWeaponItem _magazineClass; + }; + }; + + [_unit, _magazineClass, _ammoCount, true] call CBA_fnc_addMagazine; +}, [_unit, _weapon, _ammoCount], _delay] call CBA_fnc_waitAndExecute; diff --git a/addons/common/stringtable.xml b/addons/common/stringtable.xml index 5f361645483..a3a16229d54 100644 --- a/addons/common/stringtable.xml +++ b/addons/common/stringtable.xml @@ -1590,5 +1590,8 @@ 受所在位置影響提升醫療能力 Konumlar Tedaviyi Hızlandırır + + Unload Weapon + From 2b07d66392ff4a4d1883cc4565e304e3c8429ce7 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Sun, 12 Dec 2021 12:12:17 -0800 Subject: [PATCH 2/7] change function name --- addons/common/XEH_PREP.hpp | 2 +- addons/common/XEH_postInit.sqf | 2 +- addons/common/functions/fnc_unloadWeaponMan.sqf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index c252c55701c..366d8dd22ae 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -187,7 +187,7 @@ PREP(uniqueElements); PREP(uniqueItems); PREP(unloadPerson); PREP(unloadPersonLocal); -PREP(unloadWeaponMan); +PREP(unloadUnitWeapon); PREP(unmuteUnit); PREP(useItem); PREP(useMagazine); diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 2f725c6e7d4..145e3c8c1f1 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -540,7 +540,7 @@ GVAR(deviceKeyCurrentIndex) = -1; if (_currentAmmoCount < 1) exitWith {false}; // Statement: - [ACE_player, _currentWeapon, _currentMuzzle, _currentAmmoCount, false] call FUNC(unloadWeaponMan); + [ACE_player, _currentWeapon, _currentMuzzle, _currentAmmoCount, false] call FUNC(unloadUnitWeapon); true }, {false}, [19, [false, false, true]], false] call CBA_fnc_addKeybind; //ALT + R Key diff --git a/addons/common/functions/fnc_unloadWeaponMan.sqf b/addons/common/functions/fnc_unloadWeaponMan.sqf index 1da0b43d42f..85ae49d482f 100644 --- a/addons/common/functions/fnc_unloadWeaponMan.sqf +++ b/addons/common/functions/fnc_unloadWeaponMan.sqf @@ -14,7 +14,7 @@ * None * * Example: - * [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player, 23, false] call ace_common_fnc_unloadWeaponMan +* [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player, 23, false] call ace_common_fnc_unloadUnitWeapon * * Public: No */ From 8d63baa61a5af25ad7547bcb6f667b33bedcce05 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Sun, 12 Dec 2021 13:07:38 -0800 Subject: [PATCH 3/7] rename the file too --- .../{fnc_unloadWeaponMan.sqf => fnc_unloadUnitWeapon.sqf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename addons/common/functions/{fnc_unloadWeaponMan.sqf => fnc_unloadUnitWeapon.sqf} (100%) diff --git a/addons/common/functions/fnc_unloadWeaponMan.sqf b/addons/common/functions/fnc_unloadUnitWeapon.sqf similarity index 100% rename from addons/common/functions/fnc_unloadWeaponMan.sqf rename to addons/common/functions/fnc_unloadUnitWeapon.sqf From f538ce6d1da3dd4f0fa5d0e255d6679db8e07be9 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Sat, 18 Dec 2021 15:46:30 -0800 Subject: [PATCH 4/7] Create common-framework.md --- docs/wiki/framework/common-framework.md | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docs/wiki/framework/common-framework.md diff --git a/docs/wiki/framework/common-framework.md b/docs/wiki/framework/common-framework.md new file mode 100644 index 00000000000..594ca6b1e44 --- /dev/null +++ b/docs/wiki/framework/common-framework.md @@ -0,0 +1,26 @@ +--- +layout: wiki +title: Common Framework +description: Notes on ACE3 Common. +group: framework +order: 5 +parent: wiki +mod: ace +version: + major: 3 + minor: 15 + patch: 0 +--- + +## 1. Config Values + +### 1.1 `CfgWeapons` + +```cpp +class CfgWeapons { + class yourWeaponClass { + ACE_unloadAction = "GestureUnloadMyWeaponClass"; // Animation to play when weapon is unloaded with ace_common_fnc_unloadUnitWeapon + ACE_unloadSound = "A3\Sounds_F\arsenal\weapons\Rifles\Katiba\reload_Katiba.wss"; // Sound to play when weapon is unloaded with ace_common_fnc_unloadUnitWeapon + }; +}; +``` From 55eefc6b43e41f6919fdc333f1d7de7fab4f180d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 17 May 2022 18:11:08 -0500 Subject: [PATCH 5/7] Set REQUIRED_CBA_VERSION to 3.15.7 --- addons/main/script_mod.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index 8e598ffeef4..8f1fcd1993c 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -11,7 +11,7 @@ // MINIMAL required version for the Mod. Components can specify others.. #define REQUIRED_VERSION 2.06 -#define REQUIRED_CBA_VERSION {3,15,6} +#define REQUIRED_CBA_VERSION {3,15,7} #ifdef COMPONENT_BEAUTIFIED #define COMPONENT_NAME QUOTE(ACE3 - COMPONENT_BEAUTIFIED) From eee17ba841cb044cf1162d96d1bf36e99dfb5c15 Mon Sep 17 00:00:00 2001 From: Drofseh Date: Tue, 17 May 2022 18:17:15 -0700 Subject: [PATCH 6/7] Update required CBA version Co-authored-by: PabstMirror --- addons/common/functions/fnc_unloadUnitWeapon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_unloadUnitWeapon.sqf b/addons/common/functions/fnc_unloadUnitWeapon.sqf index 85ae49d482f..6998370e363 100644 --- a/addons/common/functions/fnc_unloadUnitWeapon.sqf +++ b/addons/common/functions/fnc_unloadUnitWeapon.sqf @@ -19,7 +19,7 @@ * Public: No */ -params ["_unit", "_weapon", ["_muzzle", _weapon], ["_ammoCount", ammo _muzzle _unit], ["_skipAnim", false]]; +params ["_unit", "_weapon", ["_muzzle", _weapon], ["_ammoCount", _unit ammo _muzzle ], ["_skipAnim", false]]; TRACE_5("params",_unit,_weapon,_muzzle,_ammoCount,_skipAnim); // audiovisual effects From 9ea4e0e6bfd09911c6e16fca576db5c18dcff958 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 18 May 2022 12:56:44 -0500 Subject: [PATCH 7/7] Apply suggestions from code review --- docs/wiki/framework/common-framework.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/wiki/framework/common-framework.md b/docs/wiki/framework/common-framework.md index 594ca6b1e44..464593eb05d 100644 --- a/docs/wiki/framework/common-framework.md +++ b/docs/wiki/framework/common-framework.md @@ -8,8 +8,8 @@ parent: wiki mod: ace version: major: 3 - minor: 15 - patch: 0 + minor: 14 + patch: 2 --- ## 1. Config Values