ACE3/addons/dragging/functions/fnc_startDrag.sqf
jonpas 711e1fc026 Fix Underwater interactions (magrepack, loading, refuel, medical legs, dragging) (#5521)
* Fix Magazine Repack underwater - fix #5513
Also prevent common goKneeling function underwater

* Fix loading patients underwater - fix #5515

* Fix load object underwater

* Fix take nozzle on jerry can underwater

* Fix refuel underwater conditions further

* Use isTouchingGround, Make refuel semi-compatible
 reports false if head is out of the water, we want true even if we are not diving

* Less interact exceptions duplication

* Use animationState to determine if unit is swimming, create common function and use it instead of isTouchingGround

* Fix condition

* Support dragging underwater
No carrying due to animation timing issues and other misc things

* Allow Medical Legs SelfActions underwater

* Fix fixPosition function underwater (use getPosATL instead of getPos)

* Fix fixPosition's slope adjustment for non-gravity objects, Do the same for objects without simulation as well
2017-10-01 13:38:11 -05:00

60 lines
1.7 KiB
Plaintext

/*
* Author: commy2
* Start the dragging process.
*
* Arguments:
* 0: Unit that should do the dragging <OBJECT>
* 1: Object to drag <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player, cursorTarget] call ace_dragging_fnc_startDrag;
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_target"];
TRACE_2("params",_unit,_target);
// check weight
private _weight = [_target] call FUNC(getWeight);
if (_weight > missionNamespace getVariable ["ACE_maxWeightDrag", 1E11]) exitWith {
[localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured);
};
// add a primary weapon if the unit has none.
// @todo prevent opening inventory when equipped with a fake weapon
if (primaryWeapon _unit == "") then {
_unit addWeapon "ACE_FakePrimaryWeapon";
};
// select primary, otherwise the drag animation actions don't work.
_unit selectWeapon primaryWeapon _unit;
// 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 {
[{
[_this, "grabDrag"] 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 {
_target setDir (getDir _unit + 180);
_target setPosASL (getPosASL _unit vectorAdd (vectorDir _unit vectorMultiply 1.5));
[_target, "AinjPpneMrunSnonWnonDb_grab", 2, true] call EFUNC(common,doAnimation);
};
// prevents draging 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;