diff --git a/addons/common/functions/fnc_claimSafeServer.sqf b/addons/common/functions/fnc_claimSafeServer.sqf index e24a421549..6ebee7cb4f 100644 --- a/addons/common/functions/fnc_claimSafeServer.sqf +++ b/addons/common/functions/fnc_claimSafeServer.sqf @@ -1,7 +1,7 @@ #include "..\script_component.hpp" /* * Author: commy2, PabstMirror - * Unit claims the ownership over an object. This is used to prevent multiple players from draging the same ammo box or using up the same wheel when repairing etc. + * Unit claims the ownership over an object. This is used to prevent multiple players from dragging the same ammo box or using up the same wheel when repairing etc. * This function only runs on the server and handles the "ace_common_claimSafe" event. It provides a network safe way claiming objects as all claims are run on server. * Return event is passed [_unit, _target, _success] for new claims, no event on claim release * diff --git a/addons/dragging/XEH_PREP.hpp b/addons/dragging/XEH_PREP.hpp index 37b9722e8e..0861c9533d 100644 --- a/addons/dragging/XEH_PREP.hpp +++ b/addons/dragging/XEH_PREP.hpp @@ -26,6 +26,8 @@ PREP(resumeDrag); PREP(setCarryable); PREP(setDraggable); PREP(startCarry); +PREP(startCarryLocal); PREP(startCarryPFH); PREP(startDrag); +PREP(startDragLocal); PREP(startDragPFH); diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index 84bcffb544..ae277bf4d2 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -67,6 +67,9 @@ if (isNil QGVAR(maxWeightCarryRun)) then { }; }] call CBA_fnc_addEventHandler; +[QGVAR(startCarry), LINKFUNC(startCarryLocal)] call CBA_fnc_addEventHandler; +[QGVAR(startDrag), LINKFUNC(startDragLocal)] call CBA_fnc_addEventHandler; + [QGVAR(carryingContainerClosed), { params ["_container", "_owner"]; TRACE_2("carryingContainerClosed EH",_container,_owner); diff --git a/addons/dragging/functions/fnc_pauseCarry.sqf b/addons/dragging/functions/fnc_pauseCarry.sqf index bfe27420f6..49c91e166f 100644 --- a/addons/dragging/functions/fnc_pauseCarry.sqf +++ b/addons/dragging/functions/fnc_pauseCarry.sqf @@ -1,7 +1,7 @@ #include "..\script_component.hpp" /* * Author: johnb43 - * Removes user input affecting dragging. + * Removes user input affecting carrying. * * Arguments: * 0: Unit diff --git a/addons/dragging/functions/fnc_setCarryable.sqf b/addons/dragging/functions/fnc_setCarryable.sqf index 174bdbf972..60b9854f41 100644 --- a/addons/dragging/functions/fnc_setCarryable.sqf +++ b/addons/dragging/functions/fnc_setCarryable.sqf @@ -56,8 +56,25 @@ GVAR(initializedClasses_carry) = _initializedClasses; private _icon = [QPATHTOF(UI\icons\box_carry.paa), QPATHTOF(UI\icons\person_carry.paa)] select (_object isKindOf "CAManBase"); -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); +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 a00e3005e9..e024ec5be2 100644 --- a/addons/dragging/functions/fnc_setDraggable.sqf +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -56,8 +56,25 @@ GVAR(initializedClasses) = _initializedClasses; private _icon = [QPATHTOF(UI\icons\box_drag.paa), QPATHTOF(UI\icons\person_drag.paa)] select (_object isKindOf "CAManBase"); -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); +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 040b701f71..3e2cc17efd 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 - * Starts the carrying process. + * Author: johnb43 + * Starts the carrying process safely. * * Arguments: * 0: Unit that should do the carrying @@ -11,82 +11,11 @@ * None * * Example: - * [player, cursorTarget] call ace_dragging_fnc_startCarry; + * [player, cursorTarget] call ace_dragging_fnc_startCarry * * Public: No */ - params ["_unit", "_target"]; -TRACE_2("params",_unit,_target); -// 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); -}; - -// Exit if object weight is over global var value -if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith { - [LLSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); -}; - -private _timer = CBA_missionTime + 5; - -// Handle objects vs. persons -if (_target isKindOf "CAManBase") then { - private _primaryWeapon = primaryWeapon _unit; - - // 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; - - // 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 - 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 - [_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 -[_unit, _target, true] call EFUNC(common,claim); - -// Prevents dragging and carrying at the same time -_unit setVariable [QGVAR(isCarrying), true, true]; - -// 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 -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 -}; +// Try to claim the object +[QEGVAR(common,claimSafe), [_unit, _target, true, QGVAR(startCarry)]] call CBA_fnc_serverEvent; diff --git a/addons/dragging/functions/fnc_startCarryLocal.sqf b/addons/dragging/functions/fnc_startCarryLocal.sqf new file mode 100644 index 0000000000..5cc524081b --- /dev/null +++ b/addons/dragging/functions/fnc_startCarryLocal.sqf @@ -0,0 +1,92 @@ +#include "..\script_component.hpp" +/* + * Author: commy2, PiZZADOX + * Starts the carrying process. + * + * Arguments: + * 0: Unit that should do the carrying + * 1: Object to carry + * 2: If object was successfully claimed + * + * Return Value: + * None + * + * Example: + * [player, cursorTarget, true] call ace_dragging_fnc_startCarryLocal + * + * Public: No + */ + +params ["_unit", "_target", "_claimed"]; +TRACE_3("params",_unit,_target,_claimed); + +if (!_claimed) exitWith {}; + +// 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); +}; + +// Exit if object weight is over global var value +if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith { + [LLSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); +}; + +private _timer = CBA_missionTime + 5; + +// Handle objects vs. persons +if (_target isKindOf "CAManBase") then { + private _primaryWeapon = primaryWeapon _unit; + + // 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; + + // 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 + 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 + [_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); + +// Prevents dragging and carrying at the same time +_unit setVariable [QGVAR(isCarrying), true, true]; + +// 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 +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 +}; diff --git a/addons/dragging/functions/fnc_startDrag.sqf b/addons/dragging/functions/fnc_startDrag.sqf index cd298804e6..8dd6db6dee 100644 --- a/addons/dragging/functions/fnc_startDrag.sqf +++ b/addons/dragging/functions/fnc_startDrag.sqf @@ -1,104 +1,21 @@ #include "..\script_component.hpp" /* - * Author: commy2, PiZZADOX, Malbryn - * Starts the dragging process. + * Author: johnb43 + * Starts the dragging process safely. * * Arguments: - * 0: Unit that should do the dragging + * 0: Unit that should do the carrying * 1: Object to drag * * Return Value: * None * * Example: - * [player, cursorTarget] call ace_dragging_fnc_startDrag; + * [player, cursorTarget] call ace_dragging_fnc_startDrag * * Public: No */ - params ["_unit", "_target"]; -TRACE_2("params",_unit,_target); -// 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); -}; - -// Exit if object weight is over global var value -if (_weight > GETMVAR(ACE_maxWeightDrag,1E11)) exitWith { - [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 == "") then { - _unit addWeapon "ACE_FakePrimaryWeapon"; - _primaryWeapon = "ACE_FakePrimaryWeapon"; - }; - - _unit selectWeapon _primaryWeapon; -} else { // Making sure the unit is holding a primary weapon or handgun - private _handgunWeapon = handgunWeapon _unit; - - if !(currentWeapon _unit in [_primaryWeapon, _handgunWeapon]) then { - if (_primaryWeapon != "") then { - // Use primary if possible - _unit selectWeapon _primaryWeapon; - } else { - if (_handgunWeapon != "") then { - // Use pistol if unit has no primary - _unit selectWeapon _handgunWeapon; - } else { - // Add fake weapon if no weapons besides launcher are available - _unit addWeapon "ACE_FakePrimaryWeapon"; - _unit selectWeapon "ACE_FakePrimaryWeapon"; - }; - }; - }; -}; - -// Save the weapon so we can monitor if it changes -_unit setVariable [QGVAR(currentWeapon), currentWeapon _unit]; - -[_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); - -// 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 -if !(_unit call EFUNC(common,isSwimming)) then { - [{ - private _unitWeapon = _this getVariable [QGVAR(currentWeapon), ""]; - - if (_unitWeapon isKindOf ["Pistol", configFile >> "CfgWeapons"]) then { - [_this, "ACE_dragWithPistol"] call EFUNC(common,doGesture); - } else { - [_this, "ACE_dragWithRifle"] call EFUNC(common,doGesture); - }; - }, _unit] call CBA_fnc_execNextFrame; -}; - -// Move a bit closer and adjust direction when trying to pick up a person -if (_target isKindOf "CAManBase") then { - [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 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 -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 -}; +// Try to claim the object +[QEGVAR(common,claimSafe), [_unit, _target, true, QGVAR(startDrag)]] call CBA_fnc_serverEvent; diff --git a/addons/dragging/functions/fnc_startDragLocal.sqf b/addons/dragging/functions/fnc_startDragLocal.sqf new file mode 100644 index 0000000000..819ec55252 --- /dev/null +++ b/addons/dragging/functions/fnc_startDragLocal.sqf @@ -0,0 +1,104 @@ +#include "..\script_component.hpp" +/* + * Author: commy2, PiZZADOX, Malbryn + * Starts the dragging process. + * + * Arguments: + * 0: Unit that should do the dragging + * 1: Object to drag + * 2: If object was successfully claimed + * + * Return Value: + * None + * + * Example: + * [player, cursorTarget, true] call ace_dragging_fnc_startDragLocal + * + * Public: No + */ + +params ["_unit", "_target", "_claimed"]; +TRACE_3("params",_unit,_target,_claimed); + +if (!_claimed) exitWith {}; + +// 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); +}; + +// Exit if object weight is over global var value +if (_weight > GETMVAR(ACE_maxWeightDrag,1E11)) exitWith { + [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 == "") then { + _unit addWeapon "ACE_FakePrimaryWeapon"; + _primaryWeapon = "ACE_FakePrimaryWeapon"; + }; + + _unit selectWeapon _primaryWeapon; +} else { // Making sure the unit is holding a primary weapon or handgun + private _handgunWeapon = handgunWeapon _unit; + + if !(currentWeapon _unit in [_primaryWeapon, _handgunWeapon]) then { + if (_primaryWeapon != "") then { + // Use primary if possible + _unit selectWeapon _primaryWeapon; + } else { + if (_handgunWeapon != "") then { + // Use pistol if unit has no primary + _unit selectWeapon _handgunWeapon; + } else { + // Add fake weapon if no weapons besides launcher are available + _unit addWeapon "ACE_FakePrimaryWeapon"; + _unit selectWeapon "ACE_FakePrimaryWeapon"; + }; + }; + }; +}; + +// Save the weapon so we can monitor if it changes +_unit setVariable [QGVAR(currentWeapon), currentWeapon _unit]; + +[_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); + +// 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), ""]; + + if (_unitWeapon isKindOf ["Pistol", configFile >> "CfgWeapons"]) then { + [_this, "ACE_dragWithPistol"] call EFUNC(common,doGesture); + } else { + [_this, "ACE_dragWithRifle"] call EFUNC(common,doGesture); + }; + }, _unit] call CBA_fnc_execNextFrame; +}; + +// Move a bit closer and adjust direction when trying to pick up a person +if (_target isKindOf "CAManBase") then { + [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 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 +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 +}; diff --git a/addons/dragging/initKeybinds.inc.sqf b/addons/dragging/initKeybinds.inc.sqf index 8ee36d0283..a8792f3576 100644 --- a/addons/dragging/initKeybinds.inc.sqf +++ b/addons/dragging/initKeybinds.inc.sqf @@ -5,7 +5,7 @@ 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 we are dragging/carrying something right now then just drop it if (_player getVariable [QGVAR(isDragging), false]) exitWith { [_player, _player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); @@ -34,7 +34,7 @@ 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 we are dragging/carrying something right now then just drop it if (_player getVariable [QGVAR(isDragging), false]) exitWith { [_player, _player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject); diff --git a/addons/medical_gui/functions/fnc_collectActions.sqf b/addons/medical_gui/functions/fnc_collectActions.sqf index 818decb017..f9392897f3 100644 --- a/addons/medical_gui/functions/fnc_collectActions.sqf +++ b/addons/medical_gui/functions/fnc_collectActions.sqf @@ -32,7 +32,7 @@ GVAR(actions) = []; if ("ace_dragging" call EFUNC(common,isModLoaded)) then { GVAR(actions) pushBack [ - localize ELSTRING(dragging,Drag), "drag", + LELSTRING(dragging,Drag), "drag", {ACE_player != GVAR(target) && {[ACE_player, GVAR(target)] call EFUNC(dragging,canDrag)}}, { GVAR(pendingReopen) = false; @@ -41,7 +41,7 @@ if ("ace_dragging" call EFUNC(common,isModLoaded)) then { ]; GVAR(actions) pushBack [ - localize ELSTRING(dragging,Carry), "drag", + LELSTRING(dragging,Carry), "drag", {ACE_player != GVAR(target) && {[ACE_player, GVAR(target)] call EFUNC(dragging,canCarry)}}, { GVAR(pendingReopen) = false;