switch to 2.18 commands

This commit is contained in:
LinkIsGrim 2024-05-23 17:44:10 -03:00
parent c3853b22fc
commit 16e63df107
4 changed files with 120 additions and 65 deletions

View File

@ -10,6 +10,7 @@ PREP(readSettingsFromParamsArray);
PREP(actionKeysNamesConverted);
PREP(addCanInteractWithCondition);
PREP(addLineToDebugDraw);
PREP(addReloadMutex);
PREP(addSwayFactor);
PREP(addToInventory);
PREP(addWeapon);

View File

@ -441,74 +441,23 @@ addMissionEventHandler ["PlayerViewChanged", {
//////////////////////////////////////////////////
GVAR(isReloading) = false;
GVAR(reloadMutex_lastAction) = "";
["CAManBase", "GestureChanged", {
params ["_unit", "_gesture"];
if !(
_unit isEqualTo ACE_Player &&
{!GVAR(isReloading)} &&
{_gesture isNotEqualTo ""}
) exitWith {};
["unit", {
params ["_newPlayer","_oldPlayer"];
(weaponState ACE_player) params ["_weapon", "_muzzle"];
if (_weapon isEqualTo "") exitWith {};
GVAR(isReloading) = ((weaponState _newPlayer) select 6) == 0; // Catch the new unit reloading
if (GVAR(isReloading)) then {
private _unitMovesInfo = getUnitMovesInfo _newPlayer; // 6 - gesture elapsed time, 7 - gesture duration
[{
if (_this isEqualTo ACE_player) exitWith { // player might switch units again before reload finished
GVAR(isReloading) = false
};
}, _newPlayer, (_unitMovesInfo select 7) - (_unitMovesInfo select 6)] call CBA_fnc_waitAndExecute;
};
private _reloadAction = [_weapon, _muzzle] call FUNC(getReloadAction);
// gesture is always lowercase, skip empty reload actions (binoculars)
if (_gesture isNotEqualTo _reloadAction || {_reloadAction isEqualTo ""}) exitWith {};
TRACE_2("Reloading, blocking gestures",weaponState ACE_Player,_gesture);
GVAR(isReloading) = true;
GVAR(reloadMutex_lastAction) = _gesture;
}] call CBA_fnc_addClassEventHandler;
["CAManBase", "GestureDone", {
params ["_unit", "_gesture"];
if !(
GVAR(isReloading) &&
{_unit isEqualTo ACE_Player} &&
{_gesture isEqualTo GVAR(reloadMutex_lastAction)}
) exitWith {};
GVAR(isReloading) = false;
GVAR(reloadMutex_lastAction) = "";
}] call CBA_fnc_addClassEventHandler;
// Some secondary weapons (mainly heavy launchers) have reloads as anims instead of gestures
["CAManBase", "AnimChanged", {
params ["_unit", "_anim"];
if !(
_unit isEqualTo ACE_Player &&
{!GVAR(isReloading)} &&
{currentWeapon ACE_Player isEqualTo secondaryWeapon ACE_Player}
) exitWith {};
(weaponState ACE_Player) params ["_weapon", "_muzzle"];
if (_weapon isEqualTo "") exitWith {};
private _reloadAction = [_weapon, _muzzle] call FUNC(getReloadAction);
// anim is always lowercase, skip empty reload actions (binoculars)
if (_anim isNotEqualTo _reloadAction || {_reloadAction isEqualTo ""}) exitWith {};
TRACE_2("Reloading with animation, blocking gestures",weaponState ACE_Player,_anim);
GVAR(isReloading) = true;
GVAR(reloadMutex_lastAction) = _anim;
}] call CBA_fnc_addClassEventHandler;
["CAManBase", "AnimDone", {
params ["_unit", "_anim"];
if !(
GVAR(isReloading) &&
{_unit isEqualTo ACE_Player} &&
{_anim isEqualTo GVAR(reloadMutex_lastAction)}
) exitWith {};
GVAR(isReloading) = false;
GVAR(reloadMutex_lastAction) = "";
}] call CBA_fnc_addClassEventHandler;
_oldPlayer call FUNC(removeReloadMutex);
_newPlayer call FUNC(addReloadMutex);
}, true] call CBA_fnc_addPlayerEventHandler;
//////////////////////////////////////////////////
// Start the sway loop

View File

@ -0,0 +1,71 @@
#include "..\script_component.hpp"
/*
* Author: LinkIsGrim
* Adds reload mutex to a player unit, sets variable to prevent gestures from being played during a reload animation
*
* Arguments:
* 0: Player unit <OBJECT>
*
* Return Value:
* None.
*
* Example:
* ACE_player call ace_common_fnc_addReloadMutex
*
* Public: No
*/
params ["_unit"];
_unit setVariable [
QGVAR(reloadMutex_gestureEH),
_unit addEventHandler ["GestureChanged", {
params ["_unit", "_gesture"];
if (GVAR(isReloading) || _gesture == "") exitWith {}; // skip empty gesture (include empty reload actions for binoculars)
(weaponState ACE_player) params ["_weapon", "_muzzle"];
if (_weapon isEqualTo "") exitWith {};
private _reloadAction = [_weapon, _muzzle] call FUNC(getReloadAction);
// gesture is always lowercase
if (_gesture isNotEqualTo _reloadAction) exitWith {};
TRACE_2("Reloading, blocking gestures",weaponState ACE_Player,_gesture);
GVAR(isReloading) = true;
private _unitMovesInfo = getUnitMovesInfo _unit; // 6 - gesture elapsed time, 7 - gesture duration
[{
if (_this isEqualTo ACE_player) exitWith { // player might switch units again before reload finished
GVAR(isReloading) = false
};
}, _unit, (_unitMovesInfo select 7) - (_unitMovesInfo select 6)] call CBA_fnc_waitAndExecute;
}]
];
// Some secondary weapons (mainly heavy launchers) have reloads as anims instead of gestures
_unit setVariable [
QGVAR(reloadMutex_animEH),
_unit addEventHandler ["AnimChanged", {
params ["_unit", "_anim"];
if ((currentWeapon _unit isNotEqualTo secondaryWeapon _unit) || {GVAR(isReloading) || _anim == ""}) exitWith {};
(weaponState ACE_Player) params ["_weapon", "_muzzle"];
if (_weapon isEqualTo "") exitWith {};
private _reloadAction = [_weapon, _muzzle] call FUNC(getReloadAction);
// anim is always lowercase
if (_anim isNotEqualTo _reloadAction) exitWith {};
TRACE_2("Reloading with animation, blocking gestures",weaponState ACE_Player,_anim);
GVAR(isReloading) = true;
private _unitMovesInfo = getUnitMovesInfo _unit; // 1 - anim elapsed time, 2 - anim duration
[{
if (_this isEqualTo ACE_player) exitWith { // player might switch units again before reload finished
GVAR(isReloading) = false
};
}, _unit, (_unitMovesInfo select 2) - (_unitMovesInfo select 1)] call CBA_fnc_waitAndExecute;
}]
];

View File

@ -0,0 +1,34 @@
#include "..\script_component.hpp"
/*
* Author: LinkIsGrim
* Removes reload mutex from a player unit
*
* Arguments:
* 0: Player unit <OBJECT>
*
* Return Value:
* None.
*
* Example:
* ACE_player call ace_common_fnc_removeReloadMutex
*
* Public: No
*/
params ["_unit"];
if (_unit isNil QGVAR(reloadMutex_gestureEH)) exitWith {
WARNING_1("removing reload mutex from unit %1 without eventhandlers - race condition?",_unit);
};
_unit removeEventHandler [
"GestureChanged",
_unit getVariable QGVAR(reloadMutex_gestureEH)
]
_unit setVariable [QGVAR(reloadMutex_gestureEH), nil].
_unit removeEventHandler [
"AnimChanged",
_unit getVariable QGVAR(reloadMutex_animEH)
]
_unit setVariable [QGVAR(reloadMutex_animEH), nil].