diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 2af7d0c6011..eec6bb45e2d 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -397,45 +397,53 @@ addMissionEventHandler ["PlayerViewChanged", { ////////////////////////////////////////////////// GVAR(isReloading) = false; +GVAR(reloadMutex_lastMagazines) = []; +// When reloading, the new magazine is removed from inventory, an animation plays and then the old magazine is added +// If the animation is interrupted, the new magazine will be lost +["loadout", { + params ["_unit", "_newLoadout"]; + private _mags = magazines _unit; + // if our magazine count dropped by 1, we might be reloading + if ((count GVAR(reloadMutex_lastMagazines)) - (count _mags) == 1) then { + private _weapon = currentWeapon _unit; + private _muzzle = currentMuzzle _unit; + if (_weapon == "") exitWith {}; + private _wpnMzlConfig = configFile >> "CfgWeapons" >> _weapon; + if (_muzzle != _weapon) then { _wpnMzlConfig = _wpnMzlConfig >> _muzzle; }; + + private _compatMags = [_wpnMzlConfig] call CBA_fnc_compatibleMagazines; + private _lastCompatMagCount = {_x in _compatMags} count GVAR(reloadMutex_lastMagazines); + private _curCompatMagCount = {_x in _compatMags} count _mags; + TRACE_3("",_wpnMzlConfig,_lastCompatMagCount,_curCompatMagCount); + if (_lastCompatMagCount - _curCompatMagCount != 1) exitWith {}; // check if magazines for our specific muzzle dropped by 1 + + private _gesture = getText (_wpnMzlConfig >> "reloadAction"); + if (_gesture == "") exitWith {}; //Ignore weapons with no reload gesture (binoculars) + private _isLauncher = _weapon isKindOf ["Launcher", configFile >> "CfgWeapons"]; + private _animConfig = ["CfgGesturesMale", "CfgMovesMaleSdr"] select _isLauncher; + private _duration = getNumber (configfile >> _animConfig >> "States" >> _gesture >> "speed"); + + if (_duration != 0) then { + _duration = if (_duration < 0) then { abs _duration } else { 1 / _duration }; + } else { + _duration = 3; + }; -["keyDown", { - if ((_this select 1) in actionKeys "ReloadMagazine" && {alive ACE_player}) then { - //Ignore mounted (except ffv) - if (!(player call CBA_fnc_canUseWeapon)) exitWith {}; - private _weapon = currentWeapon ACE_player; - - if (_weapon != "") then { - private _muzzle = currentMuzzle ACE_player; - private _wpnConfig = configFile >> "CfgWeapons" >> _weapon; - private _gesture = getText ([_wpnConfig >> _muzzle, _wpnConfig] select (_weapon isEqualTo _muzzle) >> "reloadAction"); - if (_gesture == "") exitWith {}; //Ignore weapons with no reload gesture (binoculars) - private _isLauncher = _weapon isKindOf ["Launcher", configFile >> "CfgWeapons"]; - private _config = ["CfgGesturesMale", "CfgMovesMaleSdr"] select _isLauncher; - private _duration = getNumber (configfile >> _config >> "States" >> _gesture >> "speed"); - - if (_duration != 0) then { - _duration = if (_duration < 0) then { abs _duration } else { 1 / _duration }; - } else { - _duration = 3; - }; - - TRACE_2("Reloading, blocking gestures",_weapon,_duration); - GVAR(reloadingETA) = CBA_missionTime + _duration; + TRACE_2("Reloading, blocking gestures",_weapon,_duration); + GVAR(reloadingETA) = CBA_missionTime + _duration; - if (!GVAR(isReloading)) then { - GVAR(isReloading) = true; + if (!GVAR(isReloading)) then { + GVAR(isReloading) = true; - [{ - CBA_missionTime > GVAR(reloadingETA) - },{ - GVAR(isReloading) = false; - }] call CBA_fnc_waitUntilAndExecute; - }; + [{ + CBA_missionTime > GVAR(reloadingETA) + },{ + GVAR(isReloading) = false; + }] call CBA_fnc_waitUntilAndExecute; }; }; - - false -}] call CBA_fnc_addDisplayHandler; + GVAR(reloadMutex_lastMagazines) = _mags; +}, true] call CBA_fnc_addPlayerEventHandler; ////////////////////////////////////////////////// // Set up PlayerJIP eventhandler