From f35f872963a42b1f12a18e9c31993f46c62e0f07 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:21:50 -0400 Subject: [PATCH] Dragging - Prevent carrying crewed static weapons (#9491) Co-authored-by: PabstMirror --- addons/dragging/functions/fnc_carryObject.sqf | 12 ++++++------ .../dragging/functions/fnc_carryObjectPFH.sqf | 12 ++++++++++++ addons/dragging/functions/fnc_dragObject.sqf | 19 +++++++++---------- .../dragging/functions/fnc_dragObjectPFH.sqf | 12 ++++++++++++ addons/dragging/functions/fnc_dropObject.sqf | 9 +++++++-- .../functions/fnc_dropObject_carry.sqf | 9 +++++++-- 6 files changed, 53 insertions(+), 20 deletions(-) diff --git a/addons/dragging/functions/fnc_carryObject.sqf b/addons/dragging/functions/fnc_carryObject.sqf index d1c5294144..dfff18a3c0 100644 --- a/addons/dragging/functions/fnc_carryObject.sqf +++ b/addons/dragging/functions/fnc_carryObject.sqf @@ -55,12 +55,6 @@ _unit setVariable [QGVAR(releaseActionID), [ // Add anim changed EH [_unit, "AnimChanged", FUNC(handleAnimChanged), [_unit]] call CBA_fnc_addBISEventHandler; -// Check everything -[FUNC(carryObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; - -// Reset current dragging height -GVAR(currentHeightChange) = 0; - // Prevent UAVs from firing private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew); @@ -71,3 +65,9 @@ if (_UAVCrew isNotEqualTo []) then { _target setVariable [QGVAR(isUAV), true, true]; }; + +// Check everything +[FUNC(carryObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; + +// Reset current dragging height +GVAR(currentHeightChange) = 0; diff --git a/addons/dragging/functions/fnc_carryObjectPFH.sqf b/addons/dragging/functions/fnc_carryObjectPFH.sqf index 932e30cf71..1dbdc2de5b 100644 --- a/addons/dragging/functions/fnc_carryObjectPFH.sqf +++ b/addons/dragging/functions/fnc_carryObjectPFH.sqf @@ -53,6 +53,18 @@ if !(alive _target && {_unit distance _target <= 10} && {_unit getHitPointDamage _idPFH call CBA_fnc_removePerFrameHandler; }; +// Drop static if crew is in it (UAV crew deletion may take a few frames) +if (_target isKindOf "StaticWeapon" && {(crew _target) isNotEqualTo []} && {!(_target getVariable [QGVAR(isUAV), false])}) then { + TRACE_2("static weapon crewed",_unit,_target); + + [_unit, _target] call FUNC(dropObject_carry); + + _unit setVariable [QGVAR(hint), nil]; + call EFUNC(interaction,hideMouseHint); + + _idPFH call CBA_fnc_removePerFrameHandler; +}; + private _previousHint = _unit getVariable [QGVAR(hint), []]; // If paused, don't show mouse button hints diff --git a/addons/dragging/functions/fnc_dragObject.sqf b/addons/dragging/functions/fnc_dragObject.sqf index e6def58c34..ddad0ad7bb 100644 --- a/addons/dragging/functions/fnc_dragObject.sqf +++ b/addons/dragging/functions/fnc_dragObject.sqf @@ -68,18 +68,8 @@ if !(GVAR(dragAndFire)) then { // Add anim changed EH [_unit, "AnimChanged", FUNC(handleAnimChanged), [_unit]] call CBA_fnc_addBISEventHandler; -// Check everything -[FUNC(dragObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; - -// Reset current dragging height. -GVAR(currentHeightChange) = 0; - // Prevent UAVs from firing private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew); - -// Fixes not being able to move when in combat pace -[_unit, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); - if (_UAVCrew isNotEqualTo []) then { { _target deleteVehicleCrew _x; @@ -87,3 +77,12 @@ if (_UAVCrew isNotEqualTo []) then { _target setVariable [QGVAR(isUAV), true, true]; }; + +// Check everything +[FUNC(dragObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; + +// Reset current dragging height. +GVAR(currentHeightChange) = 0; + +// Fixes not being able to move when in combat pace +[_unit, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); diff --git a/addons/dragging/functions/fnc_dragObjectPFH.sqf b/addons/dragging/functions/fnc_dragObjectPFH.sqf index 4162f570ff..a2895f4216 100644 --- a/addons/dragging/functions/fnc_dragObjectPFH.sqf +++ b/addons/dragging/functions/fnc_dragObjectPFH.sqf @@ -45,3 +45,15 @@ if (!alive _target || {_unit distance _target > 10}) then { _idPFH call CBA_fnc_removePerFrameHandler; }; + +// Drop static if crew is in it (UAV crew deletion may take a few frames) +if (_target isKindOf "StaticWeapon" && {(crew _target) isNotEqualTo []} && {!(_target getVariable [QGVAR(isUAV), false])}) then { + TRACE_2("static weapon crewed",_unit,_target); + + [_unit, _target] call FUNC(dropObject); + + _unit setVariable [QGVAR(hint), nil]; + call EFUNC(interaction,hideMouseHint); + + _idPFH call CBA_fnc_removePerFrameHandler; +}; diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 59a3cf9eeb..debe757101 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -80,9 +80,14 @@ if (_unit getVariable ["ACE_isUnconscious", false]) then { [_unit, "unconscious", 2] call EFUNC(common,doAnimation); }; -// Recreate UAV crew +// Recreate UAV crew (add a frame delay or this may cause the vehicle to be moved to [0,0,0]) if (_target getVariable [QGVAR(isUAV), false]) then { - createVehicleCrew _target; + [{ + params ["_target"]; + if (!alive _target) exitWith {}; + TRACE_2("restoring uav crew",_target,getPosASL _target); + createVehicleCrew _target; + }, [_target]] call CBA_fnc_execNextFrame; }; // Fixes not being able to move when in combat pace diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index b6033ed2b5..f57e362375 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -77,9 +77,14 @@ if !(_target isKindOf "CAManBase") then { [QEGVAR(common,fixFloating), _target, _target] call CBA_fnc_targetEvent; }; -// Recreate UAV crew +// Recreate UAV crew (add a frame delay or this may cause the vehicle to be moved to [0,0,0]) if (_target getVariable [QGVAR(isUAV), false]) then { - createVehicleCrew _target; + [{ + params ["_target"]; + if (!alive _target) exitWith {}; + TRACE_2("restoring uav crew",_target,getPosASL _target); + createVehicleCrew _target; + }, [_target]] call CBA_fnc_execNextFrame; }; // Reset mass