From dbe372cb481308c6ff8c0c423f16a094b5d8d2f6 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 24 Jul 2023 01:07:37 +0200 Subject: [PATCH] Dragging - Improve code (#9271) * Code cleanup * Moved keybinds to initKeybinds.sqf * Update addons/dragging/initKeybinds.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update addons/dragging/functions/fnc_carryObject.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update addons/dragging/functions/fnc_getWeight.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Rephrasing and adjustments for dragging --------- Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> --- addons/dragging/CfgEventHandlers.hpp | 15 ++--- addons/dragging/CfgVehicles.hpp | 23 +++---- addons/dragging/XEH_PREP.hpp | 1 - addons/dragging/XEH_postInit.sqf | 67 ++++--------------- addons/dragging/functions/fnc_canCarry.sqf | 10 +-- addons/dragging/functions/fnc_canDrag.sqf | 6 +- addons/dragging/functions/fnc_canDrop.sqf | 6 +- .../dragging/functions/fnc_canDrop_carry.sqf | 6 +- addons/dragging/functions/fnc_carryObject.sqf | 37 +++++----- .../dragging/functions/fnc_carryObjectPFH.sqf | 49 ++++++++------ addons/dragging/functions/fnc_dragObject.sqf | 37 +++++----- .../dragging/functions/fnc_dragObjectPFH.sqf | 25 ++++--- addons/dragging/functions/fnc_dropObject.sqf | 30 ++++----- .../functions/fnc_dropObject_carry.sqf | 52 +++++++------- addons/dragging/functions/fnc_getWeight.sqf | 4 +- .../functions/fnc_handleAnimChanged.sqf | 15 ++--- .../dragging/functions/fnc_handleKilled.sqf | 4 +- .../functions/fnc_handlePlayerChanged.sqf | 2 +- .../fnc_handlePlayerWeaponChanged.sqf | 15 ++--- .../functions/fnc_handleScrollWheel.sqf | 17 +++-- .../functions/fnc_handleUnconscious.sqf | 14 ++-- addons/dragging/functions/fnc_initObject.sqf | 6 +- addons/dragging/functions/fnc_initPerson.sqf | 6 +- .../functions/fnc_isObjectOnObject.sqf | 6 +- .../dragging/functions/fnc_setCarryable.sqf | 27 ++++---- .../dragging/functions/fnc_setDraggable.sqf | 23 +++---- addons/dragging/functions/fnc_startCarry.sqf | 50 +++++++------- .../dragging/functions/fnc_startCarryPFH.sqf | 36 +++++----- addons/dragging/functions/fnc_startDrag.sqf | 49 ++++++++------ .../dragging/functions/fnc_startDragPFH.sqf | 31 ++++----- addons/dragging/initKeybinds.sqf | 58 ++++++++++++++++ addons/dragging/initSettings.sqf | 5 +- 32 files changed, 380 insertions(+), 352 deletions(-) create mode 100644 addons/dragging/initKeybinds.sqf diff --git a/addons/dragging/CfgEventHandlers.hpp b/addons/dragging/CfgEventHandlers.hpp index 8903f2ded8..94ebf2cda6 100644 --- a/addons/dragging/CfgEventHandlers.hpp +++ b/addons/dragging/CfgEventHandlers.hpp @@ -1,4 +1,3 @@ - class Extended_PreStart_EventHandlers { class ADDON { init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); @@ -20,34 +19,34 @@ class Extended_PostInit_EventHandlers { class Extended_Init_EventHandlers { class CAManBase { class ADDON { - init = QUOTE(_this call DFUNC(initPerson)); + init = QUOTE(_this call FUNC(initPerson)); exclude[] = {"VirtualMan_F"}; }; }; class StaticWeapon { class ADDON { - init = QUOTE(_this call DFUNC(initObject)); + init = QUOTE(_this call FUNC(initObject)); }; }; class Thing { class ADDON { - init = QUOTE(_this call DFUNC(initObject)); + init = QUOTE(_this call FUNC(initObject)); exclude[] = {"ModuleEmpty_F", "ThingEffect", "Wreck"}; }; }; class NonStrategic { class ADDON { - init = QUOTE(_this call DFUNC(initObject)); + init = QUOTE(_this call FUNC(initObject)); }; }; class WeaponHolder { class ADDON { - init = QUOTE(_this call DFUNC(initObject)); + init = QUOTE(_this call FUNC(initObject)); }; }; class Land_Camping_Light_F { class ADDON { - init = QUOTE(_this call DFUNC(initObject)); + init = QUOTE(_this call FUNC(initObject)); }; }; }; @@ -55,7 +54,7 @@ class Extended_Init_EventHandlers { class Extended_Killed_EventHandlers { class CAManBase { class ADDON { - killed = QUOTE(_this call DFUNC(handleKilled)); + killed = QUOTE(_this call FUNC(handleKilled)); }; }; }; diff --git a/addons/dragging/CfgVehicles.hpp b/addons/dragging/CfgVehicles.hpp index c972a6514f..395133e946 100644 --- a/addons/dragging/CfgVehicles.hpp +++ b/addons/dragging/CfgVehicles.hpp @@ -72,7 +72,7 @@ class CfgVehicles { GVAR(canDrag) = 0; }; - // ammo boxes + // Ammo boxes class ThingX; class Items_base_F; class ReammoBox_F: ThingX { @@ -86,7 +86,7 @@ class CfgVehicles { GVAR(canCarry) = 0; GVAR(canDrag) = 0; }; - //remove actions from Taru Pods + // Remove actions from Taru Pods class Pod_Heli_Transport_04_base_F: Slingload_base_F { GVAR(canCarry) = 0; GVAR(canDrag) = 0; @@ -160,7 +160,7 @@ class CfgVehicles { GVAR(canDrag) = 0; }; - //Plastic and metal case + // Plastic and metal case class PlasticCase_01_base_F: Items_base_F { GVAR(canCarry) = 1; GVAR(carryDirection) = 270; @@ -226,22 +226,22 @@ class CfgVehicles { GVAR(canCarry) = 1; }; - // weapons dropped from dead body + // Weapons dropped from dead body class WeaponHolderSimulated: ThingX { GVAR(canCarry) = 1; GVAR(carryPosition[]) = {0,0.5,1.3}; GVAR(carryDirection) = 0; - // z-position floats from -1.2 to >0 - // it's OK for carrying but odd for dragging - // needs workaround to drag correctly. Disabled ATM + // z-position floats from -1.2 to > 0 + // It's OK for carrying but odd for dragging + // Needs workaround to drag correctly. Disabled ATM GVAR(canDrag) = 0; GVAR(dragPosition[]) = {0,1,0}; GVAR(dragDirection) = 0; }; class ReammoBox; - // dropped weapons/gear + // Dropped weapons/gear class WeaponHolder: ReammoBox { GVAR(canCarry) = 1; GVAR(carryPosition[]) = {0,0.5,1}; @@ -265,7 +265,7 @@ class CfgVehicles { class FloatingStructure_F; class Land_Camping_Light_F: FloatingStructure_F { GVAR(canCarry) = 1; - // if y < 0.9 player gets damage + // If y < 0.9 player gets damaged GVAR(carryPosition)[] = {0,0.9,1}; GVAR(canDrag) = 1; @@ -288,8 +288,7 @@ class CfgVehicles { GVAR(dragPosition)[] = {0,1,0}; }; - // some terrain objects - + // Some terrain objects class Land_CampingTable_F: ThingX { EGVAR(interaction,replaceTerrainObject) = 1; GVAR(canCarry) = 1; @@ -400,8 +399,8 @@ class CfgVehicles { GVAR(canDrag) = 1; }; - // static classes need XEH + // Static classes need XEH class NonStrategic; class Land_Pallets_F: NonStrategic { XEH_INHERITED; diff --git a/addons/dragging/XEH_PREP.hpp b/addons/dragging/XEH_PREP.hpp index 5e85c1abba..c359a35678 100644 --- a/addons/dragging/XEH_PREP.hpp +++ b/addons/dragging/XEH_PREP.hpp @@ -1,4 +1,3 @@ - PREP(canCarry); PREP(canDrag); PREP(canDrop); diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index 498d55d034..a07274f838 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -1,6 +1,7 @@ // by PabstMirror, commy2 #include "script_component.hpp" +// Release object on disconnection. Function is identical to killed if (isServer) then { // 'HandleDisconnect' EH triggers too late addMissionEventHandler ["PlayerDisconnected", { @@ -29,6 +30,7 @@ if (isNil "ACE_maxWeightDrag") then { if (isNil "ACE_maxWeightCarry") then { ACE_maxWeightCarry = 600; }; + if (isNil QGVAR(maxWeightCarryRun)) then { GVAR(maxWeightCarryRun) = 50; }; @@ -36,16 +38,16 @@ if (isNil QGVAR(maxWeightCarryRun)) then { ["isNotDragging", {!((_this select 0) getVariable [QGVAR(isDragging), false])}] call EFUNC(common,addCanInteractWithCondition); ["isNotCarrying", {!((_this select 0) getVariable [QGVAR(isCarrying), false])}] call EFUNC(common,addCanInteractWithCondition); -// release object on player change. This does work when returning to lobby, but not when hard disconnecting. -["unit", FUNC(handlePlayerChanged)] call CBA_fnc_addPlayerEventHandler; +// Release object on player change. This does work when returning to lobby, but not when hard disconnecting. +["unit", LINKFUNC(handlePlayerChanged)] call CBA_fnc_addPlayerEventHandler; ["vehicle", {[ACE_player, objNull] call FUNC(handlePlayerChanged)}] call CBA_fnc_addPlayerEventHandler; -["weapon", FUNC(handlePlayerWeaponChanged)] call CBA_fnc_addPlayerEventHandler; +["weapon", LINKFUNC(handlePlayerWeaponChanged)] call CBA_fnc_addPlayerEventHandler; -// handle waking up dragged unit and falling unconscious while dragging -["ace_unconscious", {_this call FUNC(handleUnconscious)}] call CBA_fnc_addEventHandler; +// Handle waking up dragged unit and falling unconscious while dragging +["ace_unconscious", LINKFUNC(handleUnconscious)] call CBA_fnc_addEventHandler; -// display event handler -["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler; +// Display event handler +["MouseZChanged", {(_this select 1) call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler; [QGVAR(carryingContainerClosed), { params ["_container", "_owner"]; @@ -57,13 +59,13 @@ if (isNil QGVAR(maxWeightCarryRun)) then { _weight = [_container] call FUNC(getWeight); }; - // drop the object if overweight + // Drop the object if overweight if (_weight > ACE_maxWeightCarry) exitWith { [_owner, _container] call FUNC(dropObject_carry); }; private _canRun = [_weight] call FUNC(canRun_carry); - // force walking based on weight + // Force walking based on weight [_owner, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set); [_owner, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set); }] call CBA_fnc_addEventHandler; @@ -78,53 +80,10 @@ if (isNil QGVAR(maxWeightCarryRun)) then { _weight = [_container] call FUNC(getWeight); }; - // drop the object if overweight + // Drop the object if overweight if (_weight > ACE_maxWeightDrag) exitWith { [_owner, _container] call FUNC(dropObject); }; }] call CBA_fnc_addEventHandler; -//Add Keybind: -["ACE3 Common", QGVAR(drag), (localize LSTRING(DragKeybind)), { - if (!alive ACE_player) exitWith {false}; - if !([ACE_player, objNull, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false}; - - // If we are drag/carrying something right now then just drop it: - if (ACE_player getVariable [QGVAR(isDragging), false]) exitWith { - [ACE_player, ACE_player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); - false - }; - if (ACE_player getVariable [QGVAR(isCarrying), false]) exitWith { - [ACE_player, ACE_player getVariable [QGVAR(carriedObject), objNull]] call FUNC(dropObject_carry); - false - }; - - private _cursor = cursorObject; - if ((isNull _cursor) || {(_cursor distance ACE_player) > 2.6}) exitWith {false}; - if (!([ACE_player, _cursor] call FUNC(canDrag))) exitWith {false}; - - [ACE_player, _cursor] call FUNC(startDrag); - false -}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND - -["ACE3 Common", QGVAR(carry), (localize LSTRING(CarryKeybind)), { - if (!alive ACE_player) exitWith {false}; - if !([ACE_player, objNull, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false}; - - // If we are drag/carrying something right now then just drop it: - if (ACE_player getVariable [QGVAR(isDragging), false]) exitWith { - [ACE_player, ACE_player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); - false - }; - if (ACE_player getVariable [QGVAR(isCarrying), false]) exitWith { - [ACE_player, ACE_player getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry); - false - }; - - private _cursor = cursorObject; - if ((isNull _cursor) || {(_cursor distance ACE_player) > 2.6}) exitWith {false}; - if (!([ACE_player, _cursor] call FUNC(canCarry))) exitWith {false}; - - [ACE_player, _cursor] call FUNC(startCarry); - false -}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND +#include "initKeybinds.sqf" diff --git a/addons/dragging/functions/fnc_canCarry.sqf b/addons/dragging/functions/fnc_canCarry.sqf index b80a39ed55..ab8cedaabb 100644 --- a/addons/dragging/functions/fnc_canCarry.sqf +++ b/addons/dragging/functions/fnc_canCarry.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2, Dystopian - * Check if unit can carry the object. Doesn't check weight. + * Checks if unit can carry the object. Doesn't check weight. * * Arguments: * 0: Unit that should do the carrying @@ -22,19 +22,19 @@ if !(alive _target && {_target getVariable [QGVAR(canCarry), false]} && {isNull if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false}; -//#2644 - Units with injured legs cannot bear the extra weight of carrying an object -//The fireman carry animation does not slow down for injured legs, so you could carry and run +// #2644 - Units with injured legs cannot bear the extra weight of carrying an object +// The fireman carry animation does not slow down for injured legs, so you could carry and run if ((_unit getHitPointDamage "HitLegs") >= 0.5) exitWith {false}; // Static weapons need to be empty for carrying (ignore UAV AI) if (_target isKindOf "StaticWeapon") exitWith { - crew _target findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1 + (crew _target) findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1 }; // Units need to be unconscious or limping; Units also need to not be in ragdoll, as that causes desync issues if (_target isKindOf "CAManBase") exitWith { !(alive _target != isAwake _target) && - {lifeState _target isEqualTo "INCAPACITATED" || + {lifeState _target == "INCAPACITATED" || {_target getHitPointDamage "HitLegs" >= 0.5}} }; diff --git a/addons/dragging/functions/fnc_canDrag.sqf b/addons/dragging/functions/fnc_canDrag.sqf index d5aac56693..aa3e182ad2 100644 --- a/addons/dragging/functions/fnc_canDrag.sqf +++ b/addons/dragging/functions/fnc_canDrag.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2, Dystopian - * Check if unit can drag the object. Doesn't check weight. + * Checks if unit can drag the object. Doesn't check weight. * * Arguments: * 0: Unit that should do the dragging @@ -24,13 +24,13 @@ if !([_unit, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)) exi // Static weapons need to be empty for dragging (ignore UAV AI) if (_target isKindOf "StaticWeapon") exitWith { - crew _target findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1 + (crew _target) findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1 }; // Units need to be unconscious or limping; Units also need to not be in ragdoll, as that causes desync issues if (_target isKindOf "CAManBase") exitWith { !(alive _target != isAwake _target) && - {lifeState _target isEqualTo "INCAPACITATED" || + {lifeState _target == "INCAPACITATED" || {_target getHitPointDamage "HitLegs" >= 0.5}} }; diff --git a/addons/dragging/functions/fnc_canDrop.sqf b/addons/dragging/functions/fnc_canDrop.sqf index 2d42ae6244..e56d34b762 100644 --- a/addons/dragging/functions/fnc_canDrop.sqf +++ b/addons/dragging/functions/fnc_canDrop.sqf @@ -1,11 +1,11 @@ #include "script_component.hpp" /* * Author: commy2 - * Check if unit can drop the object. + * Checks if unit can drop the dragged object. * * Arguments: - * 0: Unit that currently drags a object - * 1: Object that is dragged + * 0: Unit that is currently dragging an object + * 1: Object being dragged * * Return Value: * Can the unit drop the object? diff --git a/addons/dragging/functions/fnc_canDrop_carry.sqf b/addons/dragging/functions/fnc_canDrop_carry.sqf index 89be866ea6..eea752d834 100644 --- a/addons/dragging/functions/fnc_canDrop_carry.sqf +++ b/addons/dragging/functions/fnc_canDrop_carry.sqf @@ -1,11 +1,11 @@ #include "script_component.hpp" /* * Author: commy2 - * Check if unit can drop the carried object. + * Checks if unit can drop the carried object. * * Arguments: - * 0: Unit that currently carries a object - * 1: Object that is carried + * 0: Unit that is currently carrying an object + * 1: Object being carried * * Return Value: * Can the unit drop the object? diff --git a/addons/dragging/functions/fnc_carryObject.sqf b/addons/dragging/functions/fnc_carryObject.sqf index 7e783bd0c5..23e35b0f25 100644 --- a/addons/dragging/functions/fnc_carryObject.sqf +++ b/addons/dragging/functions/fnc_carryObject.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Carry an object. + * Handles attaching and setting up a carried object. Called from ace_dragging_fnc_startCarryPFH. * * Arguments: * 0: Unit that should do the carrying @@ -19,56 +19,55 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); -// get attachTo offset and direction. - +// Get attachTo offset and direction private _position = _target getVariable [QGVAR(carryPosition), [0, 0, 0]]; private _direction = _target getVariable [QGVAR(carryDirection), 0]; -// handle objects vs persons +// Handle objects vs. persons if (_target isKindOf "CAManBase") then { - [_unit, "AcinPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation); [_target, "AinjPfalMstpSnonWnonDf_carried_dead", 2] call EFUNC(common,doAnimation); - // attach person + // Attach person _target attachTo [_unit, _position, "LeftShoulder"]; - } else { - - // add height offset of model - private _offset = (_target modelToWorldVisual [0, 0, 0] select 2) - (_unit modelToWorldVisual [0, 0, 0] select 2); + // Add height offset of model + private _offset = ((_target modelToWorldVisual [0, 0, 0]) select 2) - ((_unit modelToWorldVisual [0, 0, 0]) select 2); _position = _position vectorAdd [0, 0, _offset]; - // attach object + // Attach object _target attachTo [_unit, _position]; - }; + [QEGVAR(common,setDir), [_target, _direction], _target] call CBA_fnc_targetEvent; _unit setVariable [QGVAR(isCarrying), true, true]; _unit setVariable [QGVAR(carriedObject), _target, true]; -// add drop action -_unit setVariable [QGVAR(ReleaseActionID), [ +// Add drop action +_unit setVariable [QGVAR(releaseActionID), [ _unit, "DefaultAction", {!isNull ((_this select 0) getVariable [QGVAR(carriedObject), objNull])}, {[_this select 0, (_this select 0) getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry)} ] call EFUNC(common,addActionEventHandler)]; -// add anim changed EH +// Add anim changed EH [_unit, "AnimChanged", FUNC(handleAnimChanged), [_unit]] call CBA_fnc_addBISEventHandler; -// check everything +// Check everything [FUNC(carryObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; -// reset current dragging height. +// Reset current dragging height GVAR(currentHeightChange) = 0; -// prevent UAVs from firing +// Prevent UAVs from firing private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew); if (_UAVCrew isNotEqualTo []) then { - {_target deleteVehicleCrew _x} count _UAVCrew; + { + _target deleteVehicleCrew _x; + } forEach _UAVCrew; + _target setVariable [QGVAR(isUAV), true, true]; }; diff --git a/addons/dragging/functions/fnc_carryObjectPFH.sqf b/addons/dragging/functions/fnc_carryObjectPFH.sqf index 3cba029f24..2a392a20a6 100644 --- a/addons/dragging/functions/fnc_carryObjectPFH.sqf +++ b/addons/dragging/functions/fnc_carryObjectPFH.sqf @@ -1,20 +1,20 @@ #include "script_component.hpp" /* * Author: commy2 - * PFH for Carry Object + * PFH for carrying an object. * * Arguments: - * 0: ARGS - * 0: Unit - * 1: Target - * 2: Start time + * 0: Arguments + * 0.0: Unit + * 0.1: Target + * 0.2: Start time * 1: PFEH Id * * Return Value: * None * * Example: - * [[player, target], 20] call ace_dragging_fnc_carryObjectPFH; + * [[player, cursorTarget, CBA_missionTime], _idPFH] call ace_dragging_fnc_carryObjectPFH; * * Public: No */ @@ -28,33 +28,40 @@ _args params ["_unit", "_target", "_startTime"]; if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith { TRACE_2("carry false",_unit,_target); + _unit setVariable [QGVAR(hint), nil]; - [] call EFUNC(interaction,hideMouseHint); - [_idPFH] call CBA_fnc_removePerFrameHandler; + call EFUNC(interaction,hideMouseHint); + + _idPFH call CBA_fnc_removePerFrameHandler; }; -// drop if the crate is destroyed OR target moved away from carrier (weapon disassembled) OR carrier starts limping +// Drop if the crate is destroyed OR target moved away from carrier (weapon disassembled) OR carrier starts limping if !(alive _target && {_unit distance _target <= 10} && {_unit getHitPointDamage "HitLegs" < 0.5}) exitWith { TRACE_2("dead/distance",_unit,_target); + if ((_unit distance _target > 10) && {(CBA_missionTime - _startTime) < 1}) exitWith { - //attachTo seems to have some kind of network delay and target can return an odd position during the first few frames, - //so wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos) + // attachTo seems to have some kind of network delay and target can return an odd position during the first few frames, + // So wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos) TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,CBA_missionTime); }; + [_unit, _target] call FUNC(dropObject_carry); + _unit setVariable [QGVAR(hint), nil]; - [] call EFUNC(interaction,hideMouseHint); - [_idPFH] call CBA_fnc_removePerFrameHandler; + call EFUNC(interaction,hideMouseHint); + + _idPFH call CBA_fnc_removePerFrameHandler; }; // Mouse hint -private _hintLMB = localize LSTRING(Drop); +private _hintLMB = LLSTRING(Drop); getCursorObjectParams params ["_cursorObject", "", "_distance"]; + if ( - !isNull _cursorObject - && {_distance < MAX_LOAD_DISTANCE} - && {([_unit, _cursorObject, ["isNotCarrying"]] call EFUNC(common,canInteractWith))} - && { + !isNull _cursorObject && + {_distance < MAX_LOAD_DISTANCE} && + {[_unit, _cursorObject, ["isNotCarrying"]] call EFUNC(common,canInteractWith)} && + { if (_target isKindOf "CAManBase") then { [_cursorObject, 0, true] call EFUNC(common,nearestVehiclesFreeSeat) isNotEqualTo [] } else { @@ -63,15 +70,17 @@ if ( } } ) then { - _hintLMB = localize ELSTRING(common,loadObject); + _hintLMB = LELSTRING(common,loadObject); }; -private _hintMMB = localize LSTRING(RaiseLowerRotate); +private _hintMMB = LLSTRING(RaiseLowerRotate); + if (_target isKindOf "CAManBase") then { _hintMMB = ""; }; private _hint = [_hintLMB, "", _hintMMB]; + if (_hint isNotEqualTo (_unit getVariable [QGVAR(hint), []])) then { _unit setVariable [QGVAR(hint), _hint]; _hint call EFUNC(interaction,showMouseHint); diff --git a/addons/dragging/functions/fnc_dragObject.sqf b/addons/dragging/functions/fnc_dragObject.sqf index 99380659ce..4fc93971ab 100644 --- a/addons/dragging/functions/fnc_dragObject.sqf +++ b/addons/dragging/functions/fnc_dragObject.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2, Malbryn - * Drag an object. Called from ace_dragging_fnc_startDrag + * Handles attaching and setting up a dragged object. Called from ace_dragging_fnc_startDragPFH. * * Arguments: * 0: Unit that should do the dragging @@ -19,20 +19,24 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); -// get attachTo offset and direction. +// Get attachTo offset and direction. private _position = _target getVariable [QGVAR(dragPosition), [0, 0, 0]]; private _direction = _target getVariable [QGVAR(dragDirection), 0]; -// add height offset of model -private _offset = (_target modelToWorldVisual [0, 0, 0] select 2) - (_unit modelToWorldVisual [0, 0, 0] select 2); +// Add height offset of model +private _offset = ((_target modelToWorldVisual [0, 0, 0]) select 2) - ((_unit modelToWorldVisual [0, 0, 0]) select 2); + if (_target isKindOf "CAManBase") then { _offset = 0; }; + _position = _position vectorAdd [0, 0, _offset]; -// attach object +// Attach object TRACE_3("attaching",_position,_offset,_direction); + _target attachTo [_unit, _position]; + [QEGVAR(common,setDir), [_target, _direction], _target] call CBA_fnc_targetEvent; if (_target isKindOf "CAManBase") then { @@ -42,17 +46,17 @@ if (_target isKindOf "CAManBase") then { _unit setVariable [QGVAR(isDragging), true, true]; _unit setVariable [QGVAR(draggedObject), _target, true]; -// add drop action +// Add drop action GVAR(unit) = _unit; GVAR(releaseActionID) = [0xF1, [false, false, false], { [GVAR(unit), GVAR(unit) getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); }, "keydown", "", false, 0] call CBA_fnc_addKeyHandler; -// show mouse hint -["", localize LSTRING(Drop)] call EFUNC(interaction,showMouseHint); +// Show mouse hint +["", LLSTRING(Drop)] call EFUNC(interaction,showMouseHint); -// block firing +// Block firing if !(GVAR(dragAndFire)) then { _unit setVariable [QGVAR(blockFire), [ _unit, "DefaultAction", @@ -61,22 +65,25 @@ if !(GVAR(dragAndFire)) then { ] call EFUNC(common,addActionEventHandler)]; }; -// add anim changed EH +// Add anim changed EH [_unit, "AnimChanged", FUNC(handleAnimChanged), [_unit]] call CBA_fnc_addBISEventHandler; -// check everything +// Check everything [FUNC(dragObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; -// reset current dragging height. +// Reset current dragging height. GVAR(currentHeightChange) = 0; -// prevent UAVs from firing +// Prevent UAVs from firing private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew); -// fixes not being able to move when in combat pace +// 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} count _UAVCrew; + { + _target deleteVehicleCrew _x; + } forEach _UAVCrew; + _target setVariable [QGVAR(isUAV), true, true]; }; diff --git a/addons/dragging/functions/fnc_dragObjectPFH.sqf b/addons/dragging/functions/fnc_dragObjectPFH.sqf index a45a26ae89..c5346bcd0e 100644 --- a/addons/dragging/functions/fnc_dragObjectPFH.sqf +++ b/addons/dragging/functions/fnc_dragObjectPFH.sqf @@ -1,20 +1,20 @@ #include "script_component.hpp" /* * Author: commy2 - * PFH for Drag Object + * PFH for dragging an object. * * Arguments: - * 0: ARGS - * 0: Unit - * 1: Target - * 2: Start time + * 0: Arguments + * 0.0: Unit + * 0.1: Target + * 0.2: Start time * 1: PFEH Id * * Return Value: * None * * Example: - * [[player, target], 20] call ace_dragging_fnc_dragObjectPFH; + * [[player, cursorTarget, CBA_missionTime], _idPFH] call ace_dragging_fnc_dragObjectPFH; * * Public: No */ @@ -28,17 +28,20 @@ _args params ["_unit", "_target", "_startTime"]; if !(_unit getVariable [QGVAR(isDragging), false]) exitWith { TRACE_2("drag false",_unit,_target); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; }; -// drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled)) +// Drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled)) if (!alive _target || {_unit distance _target > 10}) then { TRACE_2("dead/distance",_unit,_target); + if ((_unit distance _target > 10) && {(CBA_missionTime - _startTime) < 1}) exitWith { - //attachTo seems to have some kind of network delay and target can return an odd position during the first few frames, - //so wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos) + // attachTo seems to have some kind of network delay and target can return an odd position during the first few frames, + // So wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos) TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,CBA_missionTime); }; + [_unit, _target] call FUNC(dropObject); - [_idPFH] call CBA_fnc_removePerFrameHandler; + + _idPFH call CBA_fnc_removePerFrameHandler; }; diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 84b7adfb21..df9027ab31 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2, Malbryn - * Drop a dragged object. + * Drops a dragged object. * * Arguments: * 0: Unit that drags the other object @@ -19,26 +19,26 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); -// remove drop action +// Remove drop action [GVAR(releaseActionID), "keydown"] call CBA_fnc_removeKeyHandler; -// stop blocking +// Stop blocking if !(GVAR(dragAndFire)) then { [_unit, "DefaultAction", _unit getVariable [QGVAR(blockFire), -1]] call EFUNC(common,removeActionEventHandler); }; -private _inBuilding = [_unit] call FUNC(isObjectOnObject); +private _inBuilding = _unit call FUNC(isObjectOnObject); +// Play release animation if !(_unit getVariable ["ACE_isUnconscious", false]) then { - // play release animation [_unit, "released"] call EFUNC(common,doGesture); }; -// prevent collision damage +// Prevent collision damage [QEGVAR(common,fixCollision), _unit] call CBA_fnc_localEvent; [QEGVAR(common,fixCollision), _target, _target] call CBA_fnc_targetEvent; -// release object +// Release object detach _target; if (_target isKindOf "CAManBase") then { @@ -53,19 +53,19 @@ _unit removeWeapon "ACE_FakePrimaryWeapon"; [_unit, "blockThrow", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); -// prevent object from flipping inside buildings +// Prevent object from flipping inside buildings if (_inBuilding) then { _target setPosASL (getPosASL _target vectorAdd [0, 0, 0.05]); TRACE_2("setPos",getPosASL _unit,getPosASL _target); }; -// hide mouse hint -[] call EFUNC(interaction,hideMouseHint); +// Hide mouse hint +call EFUNC(interaction,hideMouseHint); _unit setVariable [QGVAR(isDragging), false, true]; _unit setVariable [QGVAR(draggedObject), objNull, true]; -// make object accessible for other units +// Make object accessible for other units [objNull, _target, true] call EFUNC(common,claim); if !(_target isKindOf "CAManBase") then { @@ -77,17 +77,17 @@ if (_unit getVariable ["ACE_isUnconscious", false]) then { [_unit, "unconscious", 2] call EFUNC(common,doAnimation); }; -// recreate UAV crew +// Recreate UAV crew if (_target getVariable [QGVAR(isUAV), false]) then { createVehicleCrew _target; }; -// fixes not being able to move when in combat pace +// Fixes not being able to move when in combat pace [_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); -// reset mass +// Reset mass private _mass = _target getVariable [QGVAR(originalMass), 0]; if (_mass != 0) then { - [QEGVAR(common,setMass), [_target, _mass]] call CBA_fnc_globalEvent; // force global sync + [QEGVAR(common,setMass), [_target, _mass]] call CBA_fnc_globalEvent; // Force global sync }; diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index 1b475e7b36..54c88ef1e3 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -1,11 +1,12 @@ #include "script_component.hpp" /* * Author: commy2 - * Drop a carried object. + * Drops a carried object. * * Arguments: * 0: Unit that carries the other object * 1: Carried object to drop + * 2: Try loading object into vehicle (default: false) * * Return Value: * None @@ -19,19 +20,19 @@ params ["_unit", "_target", ["_tryLoad", false]]; TRACE_1("params",_this); -// remove drop action -[_unit, "DefaultAction", _unit getVariable [QGVAR(ReleaseActionID), -1]] call EFUNC(common,removeActionEventHandler); +// Remove drop action +[_unit, "DefaultAction", _unit getVariable [QGVAR(releaseActionID), -1]] call EFUNC(common,removeActionEventHandler); -private _inBuilding = [_unit] call FUNC(isObjectOnObject); +private _inBuilding = _unit call FUNC(isObjectOnObject); -// prevent collision damage +// Prevent collision damage [QEGVAR(common,fixCollision), _unit] call CBA_fnc_localEvent; [QEGVAR(common,fixCollision), _target, _target] call CBA_fnc_targetEvent; -// release object +// Release object detach _target; -// fix anim when aborting carrying persons +// Fix anim when aborting carrying persons if (_target isKindOf "CAManBase" || {animationState _unit in CARRY_ANIMATIONS}) then { if (vehicle _unit == _unit && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { [_unit, "", 2] call EFUNC(common,doAnimation); @@ -44,10 +45,10 @@ if (_target isKindOf "CAManBase" || {animationState _unit in CARRY_ANIMATIONS}) }; }; -// properly remove fake weapon +// Properly remove fake weapon _unit removeWeapon "ACE_FakePrimaryWeapon"; -// reselect weapon and re-enable sprint +// Reselect weapon and re-enable sprint private _previousWeaponIndex = _unit getVariable [QGVAR(previousWeapon), -1]; _unit setVariable [QGVAR(previousWeapon), nil, true]; @@ -59,7 +60,7 @@ if (_previousWeaponIndex != -1) then { [_unit, "blockSprint", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); [_unit, "blockThrow", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); -// prevent object from flipping inside buildings +// Prevent object from flipping inside buildings if (_inBuilding) then { _target setPosASL (getPosASL _target vectorAdd [0, 0, 0.05]); }; @@ -67,7 +68,7 @@ if (_inBuilding) then { _unit setVariable [QGVAR(isCarrying), false, true]; _unit setVariable [QGVAR(carriedObject), objNull, true]; -// make object accesable for other units +// Make object accessible for other units [objNull, _target, true] call EFUNC(common,claim); if !(_target isKindOf "CAManBase") then { @@ -75,38 +76,41 @@ if !(_target isKindOf "CAManBase") then { [QEGVAR(common,fixFloating), _target, _target] call CBA_fnc_targetEvent; }; -// recreate UAV crew +// Recreate UAV crew if (_target getVariable [QGVAR(isUAV), false]) then { createVehicleCrew _target; }; -// reset mass +// Reset mass private _mass = _target getVariable [QGVAR(originalMass), 0]; if (_mass != 0) then { - [QEGVAR(common,setMass), [_target, _mass]] call CBA_fnc_globalEvent; // force global sync + [QEGVAR(common,setMass), [_target, _mass]] call CBA_fnc_globalEvent; // Force global sync }; -// reset temp direction +// Reset temp direction _target setVariable [QGVAR(carryDirection_temp), nil]; -// try loading into vehicle -if (_tryLoad && {!isNull cursorObject} && {([ACE_player, cursorObject, ["isNotCarrying"]] call EFUNC(common,canInteractWith))}) then { +private _cursorObject = cursorObject; + +// Try loading into vehicle +if (_tryLoad && {!isNull _cursorObject} && {[_unit, _cursorObject, ["isNotCarrying"]] call EFUNC(common,canInteractWith)}) then { if (_target isKindOf "CAManBase") then { - private _vehicles = [cursorObject, 0, true] call EFUNC(common,nearestVehiclesFreeSeat); - if ([cursorObject] isEqualTo _vehicles) then { - if (["ACE_Medical"] call EFUNC(common,isModLoaded)) then { - [_unit, _target, cursorObject] call EFUNC(medical_treatment,loadUnit); + private _vehicles = [_cursorObject, 0, true] call EFUNC(common,nearestVehiclesFreeSeat); + + if ([_cursorObject] isEqualTo _vehicles) then { + if (["ace_medical"] call EFUNC(common,isModLoaded)) then { + [_unit, _target, _cursorObject] call EFUNC(medical_treatment,loadUnit); } else { - [_unit, _target, cursorObject] call EFUNC(common,loadPerson); + [_unit, _target, _cursorObject] call EFUNC(common,loadPerson); }; }; } else { if ( ["ace_cargo"] call EFUNC(common,isModLoaded) && - {[_target, cursorObject] call EFUNC(cargo,canLoadItemIn)} + {[_target, _cursorObject] call EFUNC(cargo,canLoadItemIn)} ) then { - [player, _target, cursorObject] call EFUNC(cargo,startLoadIn); + [_unit, _target, _cursorObject] call EFUNC(cargo,startLoadIn); }; }; }; diff --git a/addons/dragging/functions/fnc_getWeight.sqf b/addons/dragging/functions/fnc_getWeight.sqf index 2603584151..e397386be1 100644 --- a/addons/dragging/functions/fnc_getWeight.sqf +++ b/addons/dragging/functions/fnc_getWeight.sqf @@ -11,7 +11,7 @@ * Weight * * Example: - * [_object] call ace_dragging_fnc_getWeight + * [cursorTarget] call ace_dragging_fnc_getWeight * * Public: No */ @@ -36,4 +36,4 @@ if !(GVAR(skipContainerWeight)) then { // Mass in Arma isn't an exact amount but rather a volume/weight value // This attempts to work around that by making it a usable value (sort of) -_weight * 0.5; +_weight * 0.5 // return diff --git a/addons/dragging/functions/fnc_handleAnimChanged.sqf b/addons/dragging/functions/fnc_handleAnimChanged.sqf index 7fa242ae16..4820a467ff 100644 --- a/addons/dragging/functions/fnc_handleAnimChanged.sqf +++ b/addons/dragging/functions/fnc_handleAnimChanged.sqf @@ -1,23 +1,21 @@ #include "script_component.hpp" /* * Author: commy2 - * Handle the animaion for a Unit for Dragging Module + * Handle the animation for a unit for the dragging module. * * Arguments: * 0: Unit - * 1: animaion + * 1: Animaion * * Return Value: * None * * Example: - * [_unit, "amovpercmstpsnonwnondnon"] call ace_dragging_fnc_handleAnimChanged; + * [player, "amovpercmstpsnonwnondnon"] call ace_dragging_fnc_handleAnimChanged; * * Public: No */ -//IGNORE_PRIVATE_WARNING ["_thisArgs", "_thisID"]; // From CBA_fnc_addBISEventHandler; - params ["_unit", "_anim"]; _thisArgs params ["_realUnit"]; TRACE_4("params",_unit,_anim,_realUnit,_thisID); @@ -28,8 +26,7 @@ if (_unit != _realUnit) exitWith { }; if (_unit getVariable [QGVAR(isDragging), false]) then { - - // drop dragged object when not in valid animation + // Drop dragged object when not in valid animation if (!(_anim in DRAG_ANIMATIONS) && {!(_unit call EFUNC(common,isSwimming))}) then { private _draggedObject = _unit getVariable [QGVAR(draggedObject), objNull]; @@ -39,10 +36,8 @@ if (_unit getVariable [QGVAR(isDragging), false]) then { }; }; } else { - if (_unit getVariable [QGVAR(isCarrying), false]) then { - - // drop carried object when not standing; also some exceptions when picking up crate + // Drop carried object when not standing; also some exceptions when picking up crate if (stance _unit != "STAND" && {_anim != "amovpercmstpsnonwnondnon"}) then { private _carriedObject = _unit getVariable [QGVAR(carriedObject), objNull]; diff --git a/addons/dragging/functions/fnc_handleKilled.sqf b/addons/dragging/functions/fnc_handleKilled.sqf index 672869d3c9..858a319f70 100644 --- a/addons/dragging/functions/fnc_handleKilled.sqf +++ b/addons/dragging/functions/fnc_handleKilled.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Handle death of the dragger + * Handle death of the dragger/carrier. * * Arguments: * 0: Unit @@ -10,7 +10,7 @@ * None * * Example: - * [_unit] call ace_dragging_fnc_handleKilled; + * [player] call ace_dragging_fnc_handleKilled; * * Public: No */ diff --git a/addons/dragging/functions/fnc_handlePlayerChanged.sqf b/addons/dragging/functions/fnc_handlePlayerChanged.sqf index a404660106..593208b1d9 100644 --- a/addons/dragging/functions/fnc_handlePlayerChanged.sqf +++ b/addons/dragging/functions/fnc_handlePlayerChanged.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Handle player changes. + * Handles player changes. * * Arguments: * 0: New Player Unit diff --git a/addons/dragging/functions/fnc_handlePlayerWeaponChanged.sqf b/addons/dragging/functions/fnc_handlePlayerWeaponChanged.sqf index beaed397e7..57c5545e67 100644 --- a/addons/dragging/functions/fnc_handlePlayerWeaponChanged.sqf +++ b/addons/dragging/functions/fnc_handlePlayerWeaponChanged.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Handle the Weapon Changed Event + * Handles the weapon changed event. * * Arguments: * 0: Unit @@ -11,7 +11,7 @@ * None * * Example: - * [_unit, "gun"] call ace_dragging_fnc_handlePlayerWeaponChanged; + * [player, primaryWeapon player] call ace_dragging_fnc_handlePlayerWeaponChanged; * * Public: No */ @@ -20,32 +20,25 @@ params ["_unit", "_weapon"]; TRACE_2("params",_unit,_weapon); if (_unit getVariable [QGVAR(isDragging), false]) then { - - // drop dragged object when changing weapon + // Drop dragged object when changing weapon if (_weapon != _unit getVariable [QGVAR(currentWeapon), ""]) then { private _draggedObject = _unit getVariable [QGVAR(draggedObject), objNull]; [_unit, _draggedObject] call FUNC(dropObject); }; - }; if (_unit getVariable [QGVAR(isCarrying), false]) then { - private _carriedObject = _unit getVariable [QGVAR(carriedObject), objNull]; if (_carriedObject isKindOf "CAManBase") then { - if (_weapon != primaryWeapon _unit) then { [_unit, _carriedObject] call FUNC(dropObject_carry); }; - } else { - - // drop carried object when selecting any weapon + // Drop carried object when selecting any weapon if (_weapon != "") then { [_unit, _carriedObject] call FUNC(dropObject_carry); }; - }; }; diff --git a/addons/dragging/functions/fnc_handleScrollWheel.sqf b/addons/dragging/functions/fnc_handleScrollWheel.sqf index 04c2542b2f..663b9086b6 100644 --- a/addons/dragging/functions/fnc_handleScrollWheel.sqf +++ b/addons/dragging/functions/fnc_handleScrollWheel.sqf @@ -24,13 +24,12 @@ if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {false}; private _carriedItem = _unit getVariable [QGVAR(carriedObject), objNull]; -//disabled for persons +// Disabled for persons if (_carriedItem isKindOf "CAManBase") exitWith {false}; -if !(cba_events_control) then { - // raise/lower - - // move carried item 15 cm per scroll interval +if !(CBA_events_control) then { + // Raise/lower + // Move carried item 15 cm per scroll interval _scrollAmount = _scrollAmount * 0.15; private _position = getPosASL _carriedItem; @@ -38,7 +37,7 @@ if !(cba_events_control) then { _position set [2, ((_position select 2) + _scrollAmount min (_maxHeight + 1.5)) max _maxHeight]; - // move up/down object and reattach at current position + // Move up/down object and reattach at current position detach _carriedItem; // Uses this method of selecting position because setPosATL did not have immediate effect @@ -47,15 +46,15 @@ if !(cba_events_control) then { _selectionPosition = _selectionPosition vectorAdd _positionChange; _carriedItem attachTo [_unit, _selectionPosition]; - //reset the carry direction + // Reset the carry direction private _direction = _carriedItem getVariable [QGVAR(carryDirection_temp), _carriedItem getVariable [QGVAR(carryDirection), 0]]; [QEGVAR(common,setDir), [_carriedItem, _direction], _carriedItem] call CBA_fnc_targetEvent; } else { - // rotate - + // Rotate private _direction = _carriedItem getVariable [QGVAR(carryDirection_temp), _carriedItem getVariable [QGVAR(carryDirection), 0]]; _scrollAmount = _scrollAmount * 10; _direction = _direction + _scrollAmount; + [QEGVAR(common,setDir), [_carriedItem, _direction], _carriedItem] call CBA_fnc_targetEvent; _carriedItem setVariable [QGVAR(carryDirection_temp), _direction]; }; diff --git a/addons/dragging/functions/fnc_handleUnconscious.sqf b/addons/dragging/functions/fnc_handleUnconscious.sqf index fd3f95f95d..98bd883174 100644 --- a/addons/dragging/functions/fnc_handleUnconscious.sqf +++ b/addons/dragging/functions/fnc_handleUnconscious.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Handle the Unconscious of a Unit while Dragging + * Handles consciousness change of a unit while dragging / carrying. * * Arguments: * 0: Unit @@ -10,7 +10,7 @@ * None * * Example: - * [_unit] call ace_dragging_fnc_handleUnconscious; + * [player] call ace_dragging_fnc_handleUnconscious; * * Public: No */ @@ -20,30 +20,28 @@ params ["_unit"]; private _player = ACE_player; if (_player getVariable [QGVAR(isDragging), false]) then { - private _draggedObject = _player getVariable [QGVAR(draggedObject), objNull]; - // handle falling unconscious + // Handle falling unconscious if (_unit == _player) then { [_unit, _draggedObject] call FUNC(dropObject); }; - // handle waking up dragged unit + // Handle waking up dragged unit if (_unit == _draggedObject) then { [_player, _draggedObject] call FUNC(dropObject); }; }; if (_player getVariable [QGVAR(isCarrying), false]) then { - private _carriedObject = _player getVariable [QGVAR(carriedObject), objNull]; - // handle falling unconscious + // Handle falling unconscious if (_unit == _player) then { [_unit, _carriedObject] call FUNC(dropObject_carry); }; - // handle waking up dragged unit + // Handle waking up dragged unit if (_unit == _carriedObject) then { [_player, _carriedObject] call FUNC(dropObject_carry); }; diff --git a/addons/dragging/functions/fnc_initObject.sqf b/addons/dragging/functions/fnc_initObject.sqf index 054f016a67..7a06d1d1bf 100644 --- a/addons/dragging/functions/fnc_initObject.sqf +++ b/addons/dragging/functions/fnc_initObject.sqf @@ -1,16 +1,16 @@ #include "script_component.hpp" /* * Author: commy2 - * Initialize variables for drag or carryable objects. Called from init EH. + * Initializes variables for draggable / carryable objects. Called from init EH. * * Arguments: - * 0: Any object + * 0: Object * * Return Value: * None * * Example: - * [box] call ace_dragging_fnc_initObject; + * [cursorTarget] call ace_dragging_fnc_initObject; * * Public: No */ diff --git a/addons/dragging/functions/fnc_initPerson.sqf b/addons/dragging/functions/fnc_initPerson.sqf index c9365710dd..5e3b24c5ef 100644 --- a/addons/dragging/functions/fnc_initPerson.sqf +++ b/addons/dragging/functions/fnc_initPerson.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Initialize variables for drag or carryable persons. Called from init EH. + * Initialize variables for draggable / carryable persons. Called from init EH. * * Arguments: * 0: Unit @@ -17,5 +17,5 @@ params ["_unit"]; -[_unit, true, [0,1.1,0.092], 180] call FUNC(setDraggable); -[_unit, true, [0.4,-0.1,-1.25], 195] call FUNC(setCarryable); // hard-coded selection: "LeftShoulder" +[_unit, true, [0, 1.1, 0.092], 180] call FUNC(setDraggable); +[_unit, true, [0.4, -0.1, -1.25], 195] call FUNC(setCarryable); // Hard-coded selection: "LeftShoulder" diff --git a/addons/dragging/functions/fnc_isObjectOnObject.sqf b/addons/dragging/functions/fnc_isObjectOnObject.sqf index 00c2823e4a..16f169b8fe 100644 --- a/addons/dragging/functions/fnc_isObjectOnObject.sqf +++ b/addons/dragging/functions/fnc_isObjectOnObject.sqf @@ -1,15 +1,15 @@ /* * Author: commy2 - * Check if Object is Overlapping + * Checks if an object is overlapping another object. * * Arguments: * 0: Object * * Return Value: - * Boolean + * If object is overlapping another * * Example: - * [player] call ace_dragging_fnc_isObjectOnObject + * [player] call ace_dragging_fnc_isObjectOnObject; * * Public: No */ diff --git a/addons/dragging/functions/fnc_setCarryable.sqf b/addons/dragging/functions/fnc_setCarryable.sqf index ab909e58b4..84b4073be2 100644 --- a/addons/dragging/functions/fnc_setCarryable.sqf +++ b/addons/dragging/functions/fnc_setCarryable.sqf @@ -1,46 +1,45 @@ #include "script_component.hpp" /* * Author: commy2, PiZZADOX - * Enable the object to be carried. + * Enables the object to be carried. * * Arguments: - * 0: Any object - * 1: true to enable carrying, false to disable - * 2: Position offset for attachTo command (default: [0,1,1]) - * 3: Direction in degree to rotate the object after attachTo (default: 0) - * 4: Override weight limit (optional; default: false) + * 0: Object + * 1: True to enable carrying, false to disable + * 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) * * Return Value: * None * * Example: - * [object, 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 */ -//IGNORE_PRIVATE_WARNING ["_player", "_target"]; params ["_object", "_enableCarry", "_position", "_direction", ["_ignoreWeightCarry", false, [false]]]; if (isNil "_position") then { - _position = _object getVariable [QGVAR(carryPosition), [0,1,1]]; + _position = _object getVariable [QGVAR(carryPosition), [0, 1, 1]]; }; if (isNil "_direction") then { _direction = _object getVariable [QGVAR(carryDirection), 0]; }; -// update variables +// Update variables _object setVariable [QGVAR(canCarry), _enableCarry]; _object setVariable [QGVAR(carryPosition), _position]; _object setVariable [QGVAR(carryDirection), _direction]; _object setVariable [QGVAR(ignoreWeightCarry), _ignoreWeightCarry]; -// add action to class if it is not already present +// Add action to class if it is not already present private _type = typeOf _object; private _initializedClasses = GETGVAR(initializedClasses_carry,[]); -// do nothing if the class is already initialized +// Do nothing if the class is already initialized if (_type in _initializedClasses) exitWith {}; _initializedClasses pushBack _type; @@ -57,8 +56,8 @@ GVAR(initializedClasses_carry) = _initializedClasses; private _icon = [QUOTE(PATHTOF(UI\icons\box_carry.paa)), QUOTE(PATHTOF(UI\icons\person_carry.paa))] select (_object isKindOf "Man"); -private _carryAction = [QGVAR(carry), localize LSTRING(Carry), _icon, {[_player, _target] call FUNC(startCarry)}, {[_player, _target] call FUNC(canCarry)}] call EFUNC(interact_menu,createAction); -private _dropAction = [QGVAR(drop_carry), localize LSTRING(Drop), "", {[_player, _target] call FUNC(dropObject_carry)}, {[_player, _target] call FUNC(canDrop_carry)}] call EFUNC(interact_menu,createAction); +private _carryAction = [QGVAR(carry), LLSTRING(Carry), _icon, {[_player, _target] call FUNC(startCarry)}, {[_player, _target] call FUNC(canCarry)}] call EFUNC(interact_menu,createAction); +private _dropAction = [QGVAR(drop_carry), LLSTRING(Drop), "", {[_player, _target] call FUNC(dropObject_carry)}, {[_player, _target] call FUNC(canDrop_carry)}] call EFUNC(interact_menu,createAction); [_type, 0, ["ACE_MainActions"], _carryAction] call EFUNC(interact_menu,addActionToClass); [_type, 0, [], _dropAction] call EFUNC(interact_menu,addActionToClass); diff --git a/addons/dragging/functions/fnc_setDraggable.sqf b/addons/dragging/functions/fnc_setDraggable.sqf index 84e966562a..f5ba0929ca 100644 --- a/addons/dragging/functions/fnc_setDraggable.sqf +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -1,25 +1,24 @@ #include "script_component.hpp" /* * Author: commy2, PiZZADOX - * Enable the object to be dragged. + * Enables the object to be dragged. * * Arguments: - * 0: Any object - * 1: true to enable dragging, false to disable + * 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 degree to rotate the object after attachTo (optional; default: 0) - * 4: Override weight limit (optional; default: false) + * 3: Direction in degrees to rotate the object after attachTo (optional; default: 0) + * 4: Override weight limit (default: false) * * Return Value: * None * * Example: - * [object, 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 */ -//IGNORE_PRIVATE_WARNING ["_player", "_target"]; params ["_object", "_enableDrag", "_position", "_direction", ["_ignoreWeightDrag", false, [false]]]; if (isNil "_position") then { @@ -30,17 +29,17 @@ if (isNil "_direction") then { _direction = _object getVariable [QGVAR(dragDirection), 0]; }; -// update variables +// Update variables _object setVariable [QGVAR(canDrag), _enableDrag]; _object setVariable [QGVAR(dragPosition), _position]; _object setVariable [QGVAR(dragDirection), _direction]; _object setVariable [QGVAR(ignoreWeightDrag), _ignoreWeightDrag]; -// add action to class if it is not already present +// Add action to class if it is not already present private _type = typeOf _object; private _initializedClasses = GETGVAR(initializedClasses,[]); -// do nothing if the class is already initialized +// Do nothing if the class is already initialized if (_type in _initializedClasses) exitWith {}; _initializedClasses pushBack _type; @@ -58,8 +57,8 @@ GVAR(initializedClasses) = _initializedClasses; private _icon = [QUOTE(PATHTOF(UI\icons\box_drag.paa)), QUOTE(PATHTOF(UI\icons\person_drag.paa))] select (_object isKindOf "Man"); -private _dragAction = [QGVAR(drag), localize LSTRING(Drag), _icon, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}] call EFUNC(interact_menu,createAction); -private _dropAction = [QGVAR(drop), localize LSTRING(Drop), "", {[_player, _target] call FUNC(dropObject)}, {[_player, _target] call FUNC(canDrop)}] call EFUNC(interact_menu,createAction); +private _dragAction = [QGVAR(drag), LLSTRING(Drag), _icon, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}] call EFUNC(interact_menu,createAction); +private _dropAction = [QGVAR(drop), LLSTRING(Drop), "", {[_player, _target] call FUNC(dropObject)}, {[_player, _target] call FUNC(canDrop)}] call EFUNC(interact_menu,createAction); [_type, 0, ["ACE_MainActions"], _dragAction] call EFUNC(interact_menu,addActionToClass); [_type, 0, [], _dropAction] call EFUNC(interact_menu,addActionToClass); diff --git a/addons/dragging/functions/fnc_startCarry.sqf b/addons/dragging/functions/fnc_startCarry.sqf index 747cb16d00..6580659402 100644 --- a/addons/dragging/functions/fnc_startCarry.sqf +++ b/addons/dragging/functions/fnc_startCarry.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2, PiZZADOX - * Start the carrying process. + * Starts the carrying process. * * Arguments: * 0: Unit that should do the carrying @@ -19,72 +19,74 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); -private _weight = [_target] call FUNC(getWeight); - -// exempt from weight check if object has override variable set +// Exempt from weight check if object has override variable set private _weight = 0; + if !(_target getVariable [QGVAR(ignoreWeightCarry), false]) then { - _weight = [_target] call FUNC(getWeight); + _weight = _target call FUNC(getWeight); }; -// exit if object weight is over global var value +// Exit if object weight is over global var value if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith { - [localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); + [LLSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); }; private _timer = CBA_missionTime + 5; -// handle objects vs persons +// Handle objects vs. persons if (_target isKindOf "CAManBase") then { + private _primaryWeapon = primaryWeapon _unit; - // add a primary weapon if the unit has none. - if (primaryWeapon _unit isEqualto "") then { + // Add a primary weapon if the unit has none + if (_primaryWeapon == "") then { _unit addWeapon "ACE_FakePrimaryWeapon"; + _primaryWeapon = "ACE_FakePrimaryWeapon"; }; - // select primary, otherwise the drag animation actions don't work. - _unit selectWeapon primaryWeapon _unit; + // Select primary, otherwise the drag animation actions don't work + _unit selectWeapon _primaryWeapon; - // move a bit closer and adjust direction when trying to pick up a person - _target setDir (getDir _unit + 180); + // Move a bit closer and adjust direction when trying to pick up a person + [QEGVAR(common,setDir), [_target, getDir _unit + 180], _target] call CBA_fnc_targetEvent; _target setPosASL (getPosASL _unit vectorAdd (vectorDir _unit)); [_unit, "AcinPknlMstpSnonWnonDnon_AcinPercMrunSnonWnonDnon", 2] call EFUNC(common,doAnimation); [_target, "AinjPfalMstpSnonWrflDnon_carried_Up", 2] call EFUNC(common,doAnimation); _timer = CBA_missionTime + 10; - } else { - // select no weapon and stop sprinting + // Select no weapon and stop sprinting private _previousWeaponIndex = [_unit] call EFUNC(common,getFiremodeIndex); _unit setVariable [QGVAR(previousWeapon), _previousWeaponIndex, true]; + _unit action ["SwitchWeapon", _unit, _unit, 299]; + [_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation); - private _canRun = [_weight] call FUNC(canRun_carry); - // only force walking if we're overweight + private _canRun = _weight call FUNC(canRun_carry); + + // Only force walking if we're overweight [_unit, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set); [_unit, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set); - }; [_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); -// prevent multiple players from accessing the same object +// Prevent multiple players from accessing the same object [_unit, _target, true] call EFUNC(common,claim); -// prevents draging and carrying at the same time +// Prevents dragging and carrying at the same time _unit setVariable [QGVAR(isCarrying), true, true]; -// required for aborting animation +// Required for aborting animation _unit setVariable [QGVAR(carriedObject), _target, true]; [FUNC(startCarryPFH), 0.2, [_unit, _target, _timer]] call CBA_fnc_addPerFrameHandler; -// disable collisions by setting the physx mass to almost zero +// Disable collisions by setting the PhysX mass to almost zero private _mass = getMass _target; if (_mass > 1) then { _target setVariable [QGVAR(originalMass), _mass, true]; - [QEGVAR(common,setMass), [_target, 1e-12]] call CBA_fnc_globalEvent; // force global sync + [QEGVAR(common,setMass), [_target, 1e-12]] call CBA_fnc_globalEvent; // Force global sync }; diff --git a/addons/dragging/functions/fnc_startCarryPFH.sqf b/addons/dragging/functions/fnc_startCarryPFH.sqf index f2c5cfb5d2..8271b005e1 100644 --- a/addons/dragging/functions/fnc_startCarryPFH.sqf +++ b/addons/dragging/functions/fnc_startCarryPFH.sqf @@ -1,20 +1,20 @@ #include "script_component.hpp" /* * Author: commy2 - * Carry PFH + * Checks for carrying conditions. If these are met, the unit will start carrying. Called from ace_dragging_fnc_startCarry. * * Arguments: - * 0: ARGS - * 0: Unit - * 1: Target - * 2: Timeout + * 0: Arguments + * 0.0: Unit + * 0.1: Target + * 0.2: Timeout * 1: PFEH Id * * Return Value: * None * * Example: - * [[player, target, 100], 20] call ace_dragging_fnc_startCarryPFH; + * [[player, cursorTarget, 10], _idPFH] call ace_dragging_fnc_startCarryPFH; * * Public: No */ @@ -26,42 +26,44 @@ params ["_args", "_idPFH"]; _args params ["_unit", "_target", "_timeOut"]; -// handle aborting carry +// Handle aborting carry if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith { TRACE_4("carry false",_unit,_target,_timeOut,CBA_missionTime); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; }; -// same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled)) +// Same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled)) if (!alive _target || {_unit distance _target > 10}) then { TRACE_4("dead/distance",_unit,_target,_timeOut,CBA_missionTime); [_unit, _target] call FUNC(dropObject_carry); - [_idPFH] call CBA_fnc_removePerFrameHandler; + + _idPFH call CBA_fnc_removePerFrameHandler; }; -// handle persons vs objects +// Handle persons vs. objects if (_target isKindOf "CAManBase") then { + // Drop if in timeout if (CBA_missionTime > _timeOut) exitWith { TRACE_4("Start carry person",_unit,_target,_timeOut,CBA_missionTime); [_unit, _target] call FUNC(carryObject); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; }; } else { + // Drop if in timeout if (CBA_missionTime > _timeOut) exitWith { TRACE_4("timeout",_unit,_target,_timeOut,CBA_missionTime); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; - // drop if in timeout private _draggedObject = _unit getVariable [QGVAR(draggedObject), objNull]; [_unit, _draggedObject] call FUNC(dropObject_carry); }; - // wait for the unit to stand up - if (stance _unit isEqualto "STAND") exitWith { + // Wait for the unit to stand up + if (stance _unit == "STAND") exitWith { TRACE_4("Start carry object",_unit,_target,_timeOut,CBA_missionTime); [_unit, _target] call FUNC(carryObject); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; }; }; diff --git a/addons/dragging/functions/fnc_startDrag.sqf b/addons/dragging/functions/fnc_startDrag.sqf index d8db0258fc..0efdc8ae62 100644 --- a/addons/dragging/functions/fnc_startDrag.sqf +++ b/addons/dragging/functions/fnc_startDrag.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2, PiZZADOX, Malbryn - * Start the dragging process. + * Starts the dragging process. * * Arguments: * 0: Unit that should do the dragging @@ -19,38 +19,43 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); -// exempt from weight check if object has override variable set +// Exempt from weight check if object has override variable set private _weight = 0; + if !(_target getVariable [QGVAR(ignoreWeightDrag), false]) then { - _weight = [_target] call FUNC(getWeight); + _weight = _target call FUNC(getWeight); }; -// exit if object weight is over global var value +// Exit if object weight is over global var value if (_weight > GETMVAR(ACE_maxWeightDrag,1E11)) exitWith { - [localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); + [LLSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); }; +private _primaryWeapon = primaryWeapon _unit; + // Add a primary weapon if the unit has none if !(GVAR(dragAndFire)) then { - if (primaryWeapon _unit isEqualto "") then { + if (_primaryWeapon == "") then { _unit addWeapon "ACE_FakePrimaryWeapon"; - _unit selectWeapon primaryWeapon _unit; - } else { - _unit selectWeapon primaryWeapon _unit; + _primaryWeapon = "ACE_FakePrimaryWeapon"; }; + + _unit selectWeapon _primaryWeapon; } else { // Making sure the unit is holding a primary weapon or handgun - if !(currentWeapon _unit in [primaryWeapon _unit, handgunWeapon _unit]) then { - if (primaryWeapon _unit != "") then { + private _handgunWeapon = handgunWeapon _unit; + + if !(currentWeapon _unit in [_primaryWeapon, _handgunWeapon]) then { + if (_primaryWeapon != "") then { // Use primary if possible - _unit selectWeapon primaryWeapon _unit; + _unit selectWeapon _primaryWeapon; } else { - if (handgunWeapon _unit != "") then { + if (_handgunWeapon != "") then { // Use pistol if unit has no primary - _unit selectWeapon handgunWeapon _unit; + _unit selectWeapon _handgunWeapon; } else { // Add fake weapon if no weapons besides launcher are available _unit addWeapon "ACE_FakePrimaryWeapon"; - _unit selectWeapon primaryWeapon _unit; + _unit selectWeapon "ACE_FakePrimaryWeapon"; }; }; }; @@ -61,10 +66,10 @@ _unit setVariable [QGVAR(currentWeapon), currentWeapon _unit]; [_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); -// prevent multiple players from accessing the same object +// Prevent multiple players from accessing the same object [_unit, _target, true] call EFUNC(common,claim); -// can't play action that depends on weapon if it was added the same frame +// Can't play action that depends on weapon if it was added the same frame if !(_unit call EFUNC(common,isSwimming)) then { [{ private _unitWeapon = _this getVariable [QGVAR(currentWeapon), ""]; @@ -77,23 +82,23 @@ if !(_unit call EFUNC(common,isSwimming)) then { }, _unit] call CBA_fnc_execNextFrame; }; -// move a bit closer and adjust direction when trying to pick up a person +// Move a bit closer and adjust direction when trying to pick up a person if (_target isKindOf "CAManBase") then { - _target setDir (getDir _unit + 180); + [QEGVAR(common,setDir), [_target, getDir _unit + 180], _target] call CBA_fnc_targetEvent; _target setPosASL (getPosASL _unit vectorAdd (vectorDir _unit vectorMultiply 1.5)); [_target, "AinjPpneMrunSnonWnonDb_grab", 2] call EFUNC(common,doAnimation); }; -// prevents draging and carrying at the same time +// Prevents dragging and carrying at the same time _unit setVariable [QGVAR(isDragging), true, true]; [FUNC(startDragPFH), 0.2, [_unit, _target, CBA_missionTime + 5]] call CBA_fnc_addPerFrameHandler; -// disable collisions by setting the physx mass to almost zero +// Disable collisions by setting the physx mass to almost zero private _mass = getMass _target; if (_mass > 1) then { _target setVariable [QGVAR(originalMass), _mass, true]; - [QEGVAR(common,setMass), [_target, 1e-12]] call CBA_fnc_globalEvent; // force global sync + [QEGVAR(common,setMass), [_target, 1e-12]] call CBA_fnc_globalEvent; // Force global sync }; diff --git a/addons/dragging/functions/fnc_startDragPFH.sqf b/addons/dragging/functions/fnc_startDragPFH.sqf index 614b6a8741..ef5883e0e9 100644 --- a/addons/dragging/functions/fnc_startDragPFH.sqf +++ b/addons/dragging/functions/fnc_startDragPFH.sqf @@ -1,20 +1,20 @@ #include "script_component.hpp" /* * Author: commy2 - * Drag PFH + * Checks for dragging conditions. If these are met, the unit will start dragging. Called from ace_dragging_fnc_startDrag. * * Arguments: - * 0: ARGS - * 0: Unit - * 1: Target - * 2: Timeout + * 0: Arguments + * 0.0: Unit + * 0.1: Target + * 0.2: Timeout * 1: PFEH Id * * Return Value: * None * * Example: - * [[player, target, 100], 20] call ace_dragging_fnc_startDragPFH; + * [[player, cursorTarget, 10], _idPFH] call ace_dragging_fnc_startDragPFH; * * Public: No */ @@ -26,33 +26,34 @@ params ["_args", "_idPFH"]; _args params ["_unit", "_target", "_timeOut"]; -// handle aborting drag +// Handle aborting drag if !(_unit getVariable [QGVAR(isDragging), false]) exitWith { TRACE_4("drag false",_unit,_target,_timeOut,CBA_missionTime); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; }; -// same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled)) +// Same as dragObjectPFH, checks if object is deleted, dead or target moved away from carrier (e.g. weapon disassembled) if (!alive _target || {_unit distance _target > 10}) then { TRACE_4("dead/distance",_unit,_target,_timeOut,CBA_missionTime); [_unit, _target] call FUNC(dropObject); - [_idPFH] call CBA_fnc_removePerFrameHandler; + + _idPFH call CBA_fnc_removePerFrameHandler; }; -// timeout. Do nothing. Quit. CBA_missionTime, because anim length is linked to ingame time. +// Timeout: Do nothing, quit. CBA_missionTime, because anim length is linked to ingame time if (CBA_missionTime > _timeOut) exitWith { TRACE_4("timeout",_unit,_target,_timeOut,CBA_missionTime); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; - // drop if in timeout + // Drop if in timeout private _draggedObject = _unit getVariable [QGVAR(draggedObject), objNull]; [_unit, _draggedObject] call FUNC(dropObject); }; -// unit is ready to start dragging +// Unit is ready to start dragging if (animationState _unit in DRAG_ANIMATIONS || {_unit call EFUNC(common,isSwimming)}) exitWith { TRACE_4("Start Dragging",_unit,_target,_timeOut,CBA_missionTime); [_unit, _target] call FUNC(dragObject); - [_idPFH] call CBA_fnc_removePerFrameHandler; + _idPFH call CBA_fnc_removePerFrameHandler; }; diff --git a/addons/dragging/initKeybinds.sqf b/addons/dragging/initKeybinds.sqf new file mode 100644 index 0000000000..8ee36d0283 --- /dev/null +++ b/addons/dragging/initKeybinds.sqf @@ -0,0 +1,58 @@ +// Add Keybinds +["ACE3 Common", QGVAR(drag), LLSTRING(DragKeybind), { + private _player = ACE_player; + + if (!alive _player) exitWith {false}; + if !([_player, objNull, ["isNotDragging", "isNotCarrying", "isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false}; + + // If we are drag/carrying something right now then just drop it: + if (_player getVariable [QGVAR(isDragging), false]) exitWith { + [_player, _player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); + + false + }; + + if (_player getVariable [QGVAR(isCarrying), false]) exitWith { + [_player, _player getVariable [QGVAR(carriedObject), objNull]] call FUNC(dropObject_carry); + + false + }; + + private _cursorObject = cursorObject; + + if (isNull _cursorObject || {(_cursorObject distance _player) > 2.6}) exitWith {false}; + if !([_player, _cursorObject] call FUNC(canDrag)) exitWith {false}; + + [_player, _cursorObject] call FUNC(startDrag); + + false +}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND + +["ACE3 Common", QGVAR(carry), LLSTRING(CarryKeybind), { + private _player = ACE_player; + + if (!alive _player) exitWith {false}; + if !([_player, objNull, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false}; + + // If we are drag/carrying something right now then just drop it: + if (_player getVariable [QGVAR(isDragging), false]) exitWith { + [_player, _player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); + + false + }; + + if (_player getVariable [QGVAR(isCarrying), false]) exitWith { + [_player, _player getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry); + + false + }; + + private _cursorObject = cursorObject; + + if (isNull _cursorObject || {(_cursorObject distance _player) > 2.6}) exitWith {false}; + if !([_player, _cursorObject] call FUNC(canCarry)) exitWith {false}; + + [_player, _cursorObject] call FUNC(startCarry); + + false +}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND diff --git a/addons/dragging/initSettings.sqf b/addons/dragging/initSettings.sqf index ef537d8bce..a3e444e29c 100644 --- a/addons/dragging/initSettings.sqf +++ b/addons/dragging/initSettings.sqf @@ -2,9 +2,8 @@ QGVAR(dragAndFire), "CHECKBOX", [LSTRING(DragAndFire_DisplayName), LSTRING(DragAndFire_Description)], - localize LSTRING(SettingsName), - true, - false + LLSTRING(SettingsName), + true ] call CBA_fnc_addSetting; [