From 04564b4e4fb8000fbc6c1a5abe71e6e5b280655e Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:08:43 +0200 Subject: [PATCH] `setPosATL` globally --- addons/dragging/XEH_postInit.sqf | 38 +++++++++++++-------- addons/dragging/functions/fnc_dropClone.sqf | 4 +-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index 1aef704226..745803bf33 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -67,9 +67,30 @@ if (isNil QGVAR(maxWeightCarryRun)) then { _clone setMimic "unconscious"; }] call CBA_fnc_addEventHandler; -[QGVAR(syncCorpse),{ - params ["_corpse"]; +[QGVAR(moveCorpse), { + params ["_corpse", "_dir", "_pos"]; + _pos params ["_xPos", "_yPos", "_zPos"]; + private _currentPos = getPosATL _corpse; + + // Check if the corpse is already close to the target + // If so, don't teleport + if !( + (_currentPos select 0 <= _xPos + 0.25) && + {_currentPos select 0 >= _xPos - 0.25} && + {_currentPos select 1 <= _yPos + 0.25} && + {_currentPos select 1 >= _yPos - 0.25} && + {_currentPos select 2 <= _zPos + 0.25} && + {_currentPos select 2 >= _zPos - 0.25} + ) then { + // Set direction before position + _corpse setDir _dir; + + // Bring corpse back to clone's position + _corpse setPosATL _pos; + }; + + // Sync the corpse with its position [{ _this awake true; @@ -79,19 +100,6 @@ if (isNil QGVAR(maxWeightCarryRun)) then { }, _corpse] call CBA_fnc_execNextFrame; }] call CBA_fnc_addEventHandler; -[QGVAR(moveCorpse), { - params ["_corpse", "_dir", "_pos"]; - - // Set direction before position - _corpse setDir _dir; - - // Bring corpse back to clone's position - _corpse setPosATL _pos; - - // Sync the corpse with its position - [QGVAR(syncCorpse), _corpse] call CBA_fnc_globalEvent; -}] call CBA_fnc_addEventHandler; - // Display event handler ["MouseZChanged", {(_this select 1) call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler; diff --git a/addons/dragging/functions/fnc_dropClone.sqf b/addons/dragging/functions/fnc_dropClone.sqf index 0ef9d9b7d2..0f00609e8c 100644 --- a/addons/dragging/functions/fnc_dropClone.sqf +++ b/addons/dragging/functions/fnc_dropClone.sqf @@ -39,8 +39,8 @@ if (!isNull _target) then { _pos set [2, 0.05]; }; - // Move the unit where it is local - [QGVAR(moveCorpse), [_target, getDir _unit + 180, _pos], _target] call CBA_fnc_targetEvent; + // Move the unit globally (important, as it doesn't work otherwise) + [QGVAR(moveCorpse), [_target, getDir _unit + 180, _pos]] call CBA_fnc_globalEvent; // Unhide unit if (!_isObjectHidden) then {