From 3925adf1db4bd64443782d5d8c45d037f3478b55 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:21:18 +0200 Subject: [PATCH 1/3] Check params --- .../dragging/functions/fnc_setCarryable.sqf | 24 ++++++++++++++--- .../dragging/functions/fnc_setDraggable.sqf | 26 ++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/addons/dragging/functions/fnc_setCarryable.sqf b/addons/dragging/functions/fnc_setCarryable.sqf index 60b9854f419..f20197769e5 100644 --- a/addons/dragging/functions/fnc_setCarryable.sqf +++ b/addons/dragging/functions/fnc_setCarryable.sqf @@ -5,7 +5,7 @@ * * Arguments: * 0: Object - * 1: True to enable carrying, false to disable + * 1: True to enable carrying, false to disable (default: false) * 2: Position offset for attachTo command (default: [0, 1, 1]) * 3: Direction in degrees to rotate the object after attachTo (default: 0) * 4: Override weight limit (default: false) @@ -14,12 +14,28 @@ * None * * Example: - * [cursorTarget, true, [0, 1, 1], 0, false] call ace_dragging_fnc_setCarryable; + * [cursorTarget, true, [0, 1, 1], 0, false] call ace_dragging_fnc_setCarryable * * Public: Yes */ -params ["_object", "_enableCarry", "_position", "_direction", ["_ignoreWeightCarry", false, [false]]]; +params [ + ["_object", objNull, [objNull]], + ["_enableCarry", false, [false]], + "_position", + "_direction", + ["_ignoreWeightCarry", false, [false]] +]; + +if (isNull _object) exitWith {}; + +if (!isNil "_position" && {!(_position isEqualType []) || {!(_position isEqualTypeArray [0, 0, 0])}}) exitWith { + ERROR_2("setCarryable: Bad position parameter [%1] for [%2], should be a 3D position or nil",_position,_object); +}; + +if (!isNil "_direction" && {!(_direction isEqualType 0)}) exitWith { + ERROR_2("setCarryable: Bad direction parameter [%1] for [%2], should be a number or nil",_direction,_object); +}; if (isNil "_position") then { _position = _object getVariable [QGVAR(carryPosition), [0, 1, 1]]; @@ -78,3 +94,5 @@ private _dropAction = [ [_type, 0, ["ACE_MainActions"], _carryAction] call EFUNC(interact_menu,addActionToClass); [_type, 0, [], _dropAction] call EFUNC(interact_menu,addActionToClass); + +nil // return diff --git a/addons/dragging/functions/fnc_setDraggable.sqf b/addons/dragging/functions/fnc_setDraggable.sqf index e024ec5be29..48a0c2c6199 100644 --- a/addons/dragging/functions/fnc_setDraggable.sqf +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -6,20 +6,36 @@ * Arguments: * 0: Object * 1: True to enable dragging, false to disable - * 2: Position offset for attachTo command (optional; default: [0, 1.5, 0]) - * 3: Direction in degrees to rotate the object after attachTo (optional; default: 0) + * 2: Position offset for attachTo command (default: [0, 1.5, 0]) + * 3: Direction in degrees to rotate the object after attachTo (default: 0) * 4: Override weight limit (default: false) * * Return Value: * None * * Example: - * [cursorTarget, true, [0, 0, 0], 0, false] call ace_dragging_fnc_setDraggable; + * [cursorTarget, true, [0, 0, 0], 0, false] call ace_dragging_fnc_setDraggable * * Public: Yes */ -params ["_object", "_enableDrag", "_position", "_direction", ["_ignoreWeightDrag", false, [false]]]; +params [ + ["_object", objNull, [objNull]], + ["_enableDrag", false, [false]], + "_position", + "_direction", + ["_ignoreWeightDrag", false, [false]] +]; + +if (isNull _object) exitWith {}; + +if (!isNil "_position" && {!(_position isEqualType []) || {!(_position isEqualTypeArray [0, 0, 0])}}) exitWith { + ERROR_2("setDraggable: Bad position parameter [%1] for [%2], should be a 3D position or nil",_position,_object); +}; + +if (!isNil "_direction" && {!(_direction isEqualType 0)}) exitWith { + ERROR_2("setDraggable: Bad direction parameter [%1] for [%2], should be a number or nil",_direction,_object); +}; if (isNil "_position") then { _position = _object getVariable [QGVAR(dragPosition), [0, 1.5, 0]]; @@ -78,3 +94,5 @@ private _dropAction = [ [_type, 0, ["ACE_MainActions"], _dragAction] call EFUNC(interact_menu,addActionToClass); [_type, 0, [], _dropAction] call EFUNC(interact_menu,addActionToClass); + +nil // return From 726b18b9ca3fb8d409d7ba10135da3d4f6c29389 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:39:00 +0200 Subject: [PATCH 2/3] Add global parameter to setDraggable & setCarryable --- addons/dragging/XEH_postInit.sqf | 3 +++ addons/dragging/functions/fnc_setCarryable.sqf | 17 ++++++++++++++++- addons/dragging/functions/fnc_setDraggable.sqf | 17 ++++++++++++++++- .../dev/initReplaceTerrainCursorObject.sqf | 12 ++++++------ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index ae277bf4d24..5c66fe692c8 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -70,6 +70,9 @@ if (isNil QGVAR(maxWeightCarryRun)) then { [QGVAR(startCarry), LINKFUNC(startCarryLocal)] call CBA_fnc_addEventHandler; [QGVAR(startDrag), LINKFUNC(startDragLocal)] call CBA_fnc_addEventHandler; +[QGVAR(setCarryable), LINKFUNC(setCarryable)] call CBA_fnc_addEventHandler; +[QGVAR(setDraggable), LINKFUNC(setDraggable)] call CBA_fnc_addEventHandler; + [QGVAR(carryingContainerClosed), { params ["_container", "_owner"]; TRACE_2("carryingContainerClosed EH",_container,_owner); diff --git a/addons/dragging/functions/fnc_setCarryable.sqf b/addons/dragging/functions/fnc_setCarryable.sqf index f20197769e5..c9850d6f579 100644 --- a/addons/dragging/functions/fnc_setCarryable.sqf +++ b/addons/dragging/functions/fnc_setCarryable.sqf @@ -9,6 +9,7 @@ * 2: Position offset for attachTo command (default: [0, 1, 1]) * 3: Direction in degrees to rotate the object after attachTo (default: 0) * 4: Override weight limit (default: false) + * 5: Apply globally (default: false) * * Return Value: * None @@ -24,7 +25,8 @@ params [ ["_enableCarry", false, [false]], "_position", "_direction", - ["_ignoreWeightCarry", false, [false]] + ["_ignoreWeightCarry", false, [false]], + ["_global", false, [false]] ]; if (isNull _object) exitWith {}; @@ -37,6 +39,19 @@ if (!isNil "_direction" && {!(_direction isEqualType 0)}) exitWith { ERROR_2("setCarryable: Bad direction parameter [%1] for [%2], should be a number or nil",_direction,_object); }; +// Handle global here +if (_global) exitWith { + private _jipID = format [QGVAR(carrying_%1), hashValue _object]; + [QGVAR(setCarryable), [_object, _enableCarry, _position, _direction, _ignoreWeightCarry], _jipID] call CBA_fnc_globalEventJIP; + + // Remove from JIP queue if object is deleted + if !(_object getVariable [QGVAR(setCarryableRemoveJip), false]) then { + [_jipID, _object] call CBA_fnc_removeGlobalEventJIP; + + _object setVariable [QGVAR(setCarryableRemoveJip), true, true]; + }; +}; + if (isNil "_position") then { _position = _object getVariable [QGVAR(carryPosition), [0, 1, 1]]; }; diff --git a/addons/dragging/functions/fnc_setDraggable.sqf b/addons/dragging/functions/fnc_setDraggable.sqf index 48a0c2c6199..1a73b954d70 100644 --- a/addons/dragging/functions/fnc_setDraggable.sqf +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -9,6 +9,7 @@ * 2: Position offset for attachTo command (default: [0, 1.5, 0]) * 3: Direction in degrees to rotate the object after attachTo (default: 0) * 4: Override weight limit (default: false) + * 5: Apply globally (default: false) * * Return Value: * None @@ -24,7 +25,8 @@ params [ ["_enableDrag", false, [false]], "_position", "_direction", - ["_ignoreWeightDrag", false, [false]] + ["_ignoreWeightDrag", false, [false]], + ["_global", false, [false]] ]; if (isNull _object) exitWith {}; @@ -37,6 +39,19 @@ if (!isNil "_direction" && {!(_direction isEqualType 0)}) exitWith { ERROR_2("setDraggable: Bad direction parameter [%1] for [%2], should be a number or nil",_direction,_object); }; +// Handle global here +if (_global) exitWith { + private _jipID = format [QGVAR(dragging_%1), hashValue _object]; + [QGVAR(setDraggable), [_object, _enableDrag, _position, _direction, _ignoreWeightDrag], _jipID] call CBA_fnc_globalEventJIP; + + // Remove from JIP queue if object is deleted + if !(_object getVariable [QGVAR(setDraggableRemoveJip), false]) then { + [_jipID, _object] call CBA_fnc_removeGlobalEventJIP; + + _object setVariable [QGVAR(setDraggableRemoveJip), true, true]; + }; +}; + if (isNil "_position") then { _position = _object getVariable [QGVAR(dragPosition), [0, 1.5, 0]]; }; diff --git a/addons/interaction/dev/initReplaceTerrainCursorObject.sqf b/addons/interaction/dev/initReplaceTerrainCursorObject.sqf index a1708be423d..3f71954acb5 100644 --- a/addons/interaction/dev/initReplaceTerrainCursorObject.sqf +++ b/addons/interaction/dev/initReplaceTerrainCursorObject.sqf @@ -47,12 +47,12 @@ DFUNC(replaceTerrainModelsAdd) = { ) then { // wait while server replaces object, then init dragging on all clients [{ - if (typeOf cursorObject == "") exitwith {}; - [cursorObject, { - if !hasInterface exitWith {}; - [_this, true] call EFUNC(dragging,setDraggable); - [_this, true] call EFUNC(dragging,setCarryable); - }] remoteExec ["call", 0]; + private _object = cursorObject; + + if (isNull _object) exitwith {}; + + [_object, true, nil, nil, nil, true] call EFUNC(dragging,setCarryable); + [_object, true, nil, nil, nil, true] call EFUNC(dragging,setDraggable); }, [], 1] call CBA_fnc_waitAndExecute; }; true From a762b7c563b63d0eb4fb5b6af0409a453ddf421e Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:53:59 +0200 Subject: [PATCH 3/3] Updated docs --- docs/wiki/framework/dragging-framework.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/wiki/framework/dragging-framework.md b/docs/wiki/framework/dragging-framework.md index 43a7c98ba44..da0be50da9d 100644 --- a/docs/wiki/framework/dragging-framework.md +++ b/docs/wiki/framework/dragging-framework.md @@ -53,6 +53,7 @@ You will **not** be able to carry / drag objects that are too heavy, the mass is | 2 | Position to offset the object from player | Array | Optional (default: `[0, 1.5, 0]`) | | 3 | Direction in degree to rotate the object | Number | Optional (default: `0`) | | 4 | Ignore weight limitation for dragging | Boolean | Optional (default: `false`) | +| 5 | Apply changes globally | Boolean | Optional (default: `false`) | | **R** | None | None | Return value | #### 2.1.1 Example 1 @@ -63,7 +64,7 @@ You will **not** be able to carry / drag objects that are too heavy, the mass is |----| --------- | ----------- | | 0 | `foo` | My object | | 1 | `true` | Dragging is enabled | -| 2 | `[0,2,0]` | 0 meters sideways, 2 meters forward, 0 |meters upwards +| 2 | `[0,2,0]` | 0 meters sideways, 2 meters forward, 0 meters upwards | | 3 | `45` | Rotated by 45° | #### 2.1.2 Example 2 @@ -89,6 +90,7 @@ You will **not** be able to carry / drag objects that are too heavy, the mass is | 2 | Position to offset the object from player | Array | Optional (default: `[0, 1, 1]`) | | 3 | Direction in degree to rotate the object | Number | Optional (default: `0`) | | 4 | Ignore weight limitation for carrying | Boolean | Optional (default: `false`) | +| 5 | Apply changes globally | Boolean | Optional (default: `false`) | | **R** | None | None | Return value | #### 2.2.1 Example