Dragging - Improve weapon reselect behaviour (#9052)

* Dragging - Improve weapon reselect behaviour

* Add and use func to getFiremodeIndex

---------

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
mharis001 2023-02-13 23:01:51 -05:00 committed by GitHub
parent 86d79b2fc1
commit 67ebb15e07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 3 deletions

View File

@ -64,6 +64,7 @@ PREP(getDefaultAnim);
PREP(getDefinedVariable);
PREP(getDefinedVariableDefault);
PREP(getDefinedVariableInfo);
PREP(getFiremodeIndex);
PREP(getFirstObjectIntersection);
PREP(getFirstTerrainIntersection);
PREP(getGunner);

View File

@ -0,0 +1,31 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Get the firemode index of the weapon for use with "SwitchWeapon"
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Muzzle <STRING> (Optional)
* 2: Firemode <STRING> (Optional)
*
* Return Value:
* Weapon/Mode index <NUMBER>
*
* 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

View File

@ -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);

View File

@ -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);