From 67ebb15e076d8686c556eb21367bb62de2513cc7 Mon Sep 17 00:00:00 2001 From: mharis001 <34453221+mharis001@users.noreply.github.com> Date: Mon, 13 Feb 2023 23:01:51 -0500 Subject: [PATCH] Dragging - Improve weapon reselect behaviour (#9052) * Dragging - Improve weapon reselect behaviour * Add and use func to getFiremodeIndex --------- Co-authored-by: PabstMirror --- addons/common/XEH_PREP.hpp | 1 + .../common/functions/fnc_getFiremodeIndex.sqf | 31 +++++++++++++++++++ .../functions/fnc_dropObject_carry.sqf | 7 ++++- addons/dragging/functions/fnc_startCarry.sqf | 4 +-- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 addons/common/functions/fnc_getFiremodeIndex.sqf diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 02eca6d441..2706ca45e2 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -64,6 +64,7 @@ PREP(getDefaultAnim); PREP(getDefinedVariable); PREP(getDefinedVariableDefault); PREP(getDefinedVariableInfo); +PREP(getFiremodeIndex); PREP(getFirstObjectIntersection); PREP(getFirstTerrainIntersection); PREP(getGunner); diff --git a/addons/common/functions/fnc_getFiremodeIndex.sqf b/addons/common/functions/fnc_getFiremodeIndex.sqf new file mode 100644 index 0000000000..20c04bc69f --- /dev/null +++ b/addons/common/functions/fnc_getFiremodeIndex.sqf @@ -0,0 +1,31 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror + * Get the firemode index of the weapon for use with "SwitchWeapon" + * + * Arguments: + * 0: Unit + * 1: Muzzle (Optional) + * 2: Firemode (Optional) + * + * Return Value: + * Weapon/Mode index + * + * Example: + * [player] call ace_common_fnc_getFiremodeIndex + * + * Public: Yes + */ + +params ["_unit"]; +(weaponState _unit) params ["", "_currentMuzzle", "_currentFiremode"]; +params ["", ["_muzzle", _currentMuzzle], ["_firemode", _currentFireMode]]; + +private _weapons = _unit weaponsInfo [_muzzle, false]; +private _index = -1; +{ + _x params ["_xIndex", "", "", "", "_xFiremode"]; + if (_xFiremode == _firemode) exitWith { _index = _xIndex; }; +} forEach _weapons; + +_index diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index e0f4f4308b..7f681d4658 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -48,7 +48,12 @@ if (_target isKindOf "CAManBase" || {animationState _unit in CARRY_ANIMATIONS}) _unit removeWeapon "ACE_FakePrimaryWeapon"; // reselect weapon and re-enable sprint -_unit selectWeapon primaryWeapon _unit; +private _previousWeaponIndex = _unit getVariable [QGVAR(previousWeapon), -1]; +_unit setVariable [QGVAR(previousWeapon), nil, true]; + +if (_previousWeaponIndex != -1) then { + _unit action ["SwitchWeapon", _unit, _unit, _previousWeaponIndex]; +}; [_unit, "forceWalk", "ACE_dragging", false] call EFUNC(common,statusEffect_set); [_unit, "blockThrow", "ACE_dragging", false] call EFUNC(common,statusEffect_set); diff --git a/addons/dragging/functions/fnc_startCarry.sqf b/addons/dragging/functions/fnc_startCarry.sqf index 335e421bb2..9b1dfaa068 100644 --- a/addons/dragging/functions/fnc_startCarry.sqf +++ b/addons/dragging/functions/fnc_startCarry.sqf @@ -51,13 +51,13 @@ if (_target isKindOf "CAManBase") then { _timer = CBA_missionTime + 10; } else { - // select no weapon and stop sprinting + private _previousWeaponIndex = [_unit] call EFUNC(common,getFiremodeIndex); + _unit setVariable [QGVAR(previousWeapon), _previousWeaponIndex, true]; _unit action ["SwitchWeapon", _unit, _unit, 299]; [_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation); [_unit, "forceWalk", "ACE_dragging", true] call EFUNC(common,statusEffect_set); - }; [_unit, "blockThrow", "ACE_dragging", true] call EFUNC(common,statusEffect_set);