2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-16 18:25:29 +00:00
|
|
|
/*
|
2021-04-20 11:33:58 +00:00
|
|
|
* Author: commy2, PiZZADOX, Malbryn
|
2015-03-16 18:25:29 +00:00
|
|
|
* Start the dragging process.
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2015-08-09 12:53:13 +00:00
|
|
|
* 0: Unit that should do the dragging <OBJECT>
|
|
|
|
* 1: Object to drag <OBJECT>
|
2015-03-16 18:25:29 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2015-08-09 12:53:13 +00:00
|
|
|
* None
|
2016-01-28 18:52:53 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, cursorTarget] call ace_dragging_fnc_startDrag;
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-16 18:25:29 +00:00
|
|
|
*/
|
2015-03-16 13:31:16 +00:00
|
|
|
|
2015-08-09 12:53:13 +00:00
|
|
|
params ["_unit", "_target"];
|
2016-01-28 18:52:53 +00:00
|
|
|
TRACE_2("params",_unit,_target);
|
2015-03-16 18:25:29 +00:00
|
|
|
|
2019-01-20 16:23:24 +00:00
|
|
|
// exempt from weight check if object has override variable set
|
|
|
|
if (!GETVAR(_target,GVAR(ignoreWeightDrag),false) && {
|
|
|
|
private _weight = [_target] call FUNC(getWeight);
|
|
|
|
_weight > GETMVAR(ACE_maxWeightDrag,1E11)
|
|
|
|
}) exitWith {
|
|
|
|
// exit if object weight is over global var value
|
2015-05-28 19:59:04 +00:00
|
|
|
[localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured);
|
2015-03-18 13:14:16 +00:00
|
|
|
};
|
2015-03-16 18:25:29 +00:00
|
|
|
|
2021-04-20 11:33:58 +00:00
|
|
|
// Add a primary weapon if the unit has none
|
|
|
|
if !(GVAR(dragAndFire)) then {
|
|
|
|
if (primaryWeapon _unit isEqualto "") then {
|
|
|
|
_unit addWeapon "ACE_FakePrimaryWeapon";
|
|
|
|
_unit selectWeapon primaryWeapon _unit;
|
|
|
|
} else {
|
|
|
|
_unit selectWeapon primaryWeapon _unit;
|
|
|
|
};
|
|
|
|
} 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 {
|
|
|
|
// Use primary if possible
|
|
|
|
_unit selectWeapon primaryWeapon _unit;
|
|
|
|
} else {
|
|
|
|
if (handgunWeapon _unit != "") then {
|
|
|
|
// Use pistol if unit has no primary
|
|
|
|
_unit selectWeapon handgunWeapon _unit;
|
|
|
|
} else {
|
|
|
|
// Add fake weapon if no weapons besides launcher are available
|
|
|
|
_unit addWeapon "ACE_FakePrimaryWeapon";
|
|
|
|
_unit selectWeapon primaryWeapon _unit;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2015-03-16 18:25:29 +00:00
|
|
|
};
|
|
|
|
|
2021-04-20 11:33:58 +00:00
|
|
|
// Save the weapon so we can monitor if it changes
|
|
|
|
_unit setVariable [QGVAR(currentWeapon), currentWeapon _unit];
|
2015-03-16 18:25:29 +00:00
|
|
|
|
2017-12-07 17:26:21 +00:00
|
|
|
[_unit, "blockThrow", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
|
|
|
|
|
2015-03-16 18:25:29 +00:00
|
|
|
// prevent multiple players from accessing the same object
|
|
|
|
[_unit, _target, true] call EFUNC(common,claim);
|
|
|
|
|
2015-03-18 15:55:57 +00:00
|
|
|
// can't play action that depends on weapon if it was added the same frame
|
2017-10-01 18:38:11 +00:00
|
|
|
if !(_unit call EFUNC(common,isSwimming)) then {
|
|
|
|
[{
|
2021-04-20 11:33:58 +00:00
|
|
|
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);
|
|
|
|
};
|
2017-10-01 18:38:11 +00:00
|
|
|
}, _unit] call CBA_fnc_execNextFrame;
|
|
|
|
};
|
2015-03-16 18:25:29 +00:00
|
|
|
|
2015-03-24 18:07:39 +00:00
|
|
|
// move a bit closer and adjust direction when trying to pick up a person
|
|
|
|
if (_target isKindOf "CAManBase") then {
|
|
|
|
_target setDir (getDir _unit + 180);
|
2015-05-31 16:34:48 +00:00
|
|
|
_target setPosASL (getPosASL _unit vectorAdd (vectorDir _unit vectorMultiply 1.5));
|
2015-03-25 12:32:59 +00:00
|
|
|
|
2021-08-03 18:06:12 +00:00
|
|
|
[_target, "AinjPpneMrunSnonWnonDb_grab", 2] call EFUNC(common,doAnimation);
|
2015-03-24 18:07:39 +00:00
|
|
|
};
|
|
|
|
|
2015-10-21 20:52:21 +00:00
|
|
|
// prevents draging and carrying at the same time
|
2015-03-22 16:12:14 +00:00
|
|
|
_unit setVariable [QGVAR(isDragging), true, true];
|
|
|
|
|
2016-03-02 10:01:39 +00:00
|
|
|
[FUNC(startDragPFH), 0.2, [_unit, _target, CBA_missionTime + 5]] call CBA_fnc_addPerFrameHandler;
|
2019-03-24 08:26:00 +00:00
|
|
|
|
|
|
|
// disable collisions by setting the physx mass to almost zero
|
|
|
|
private _mass = getMass _target;
|
|
|
|
|
|
|
|
if (_mass > 1) then {
|
|
|
|
_target setVariable [QGVAR(originalMass), _mass, true];
|
2021-01-20 20:49:38 +00:00
|
|
|
[QEGVAR(common,setMass), [_target, 1e-12]] call CBA_fnc_globalEvent; // force global sync
|
2019-03-24 08:26:00 +00:00
|
|
|
};
|