ACE3/addons/dragging/functions/fnc_carryObject.sqf

75 lines
2.1 KiB
Plaintext
Raw Normal View History

2015-03-17 14:42:25 +00:00
/*
* Author: commy2
* Carry an object.
*
2015-08-09 12:53:13 +00:00
* Arguments:
* 0: Unit that should do the carrying <OBJECT>
* 1: Object to carry <OBJECT>
2015-03-17 14:42:25 +00:00
*
2015-08-09 12:53:13 +00:00
* Return Value:
* None
*
2016-01-28 18:52:53 +00:00
* Example:
* [player, cursorTarget] call ace_dragging_fnc_carryObject;
*
2015-08-09 12:53:13 +00:00
* Public: No
2015-03-17 14:42:25 +00:00
*/
#include "script_component.hpp"
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-17 14:42:25 +00:00
2015-03-25 12:32:59 +00:00
// get attachTo offset and direction.
2015-03-18 13:14:16 +00:00
2016-01-28 18:52:53 +00:00
private _position = _target getVariable [QGVAR(carryPosition), [0, 0, 0]];
private _direction = _target getVariable [QGVAR(carryDirection), 0];
2015-03-18 13:14:16 +00:00
2015-03-25 12:32:59 +00:00
// handle objects vs persons
if (_target isKindOf "CAManBase") then {
2015-03-17 14:42:25 +00:00
2015-03-25 12:32:59 +00:00
[_unit, "AcinPercMstpSnonWnonDnon", 2, true] call EFUNC(common,doAnimation);
[_target, "AinjPfalMstpSnonWnonDf_carried_dead", 2, true] call EFUNC(common,doAnimation);
2015-03-17 14:42:25 +00:00
2015-03-25 12:32:59 +00:00
// attach person
_target attachTo [_unit, _position, "LeftShoulder"];
2015-03-17 14:42:25 +00:00
2015-03-25 12:32:59 +00:00
} else {
2015-03-17 14:42:25 +00:00
2015-03-25 12:32:59 +00:00
// add height offset of model
2016-01-28 18:52:53 +00:00
private _offset = (_target modelToWorldVisual [0, 0, 0] select 2) - (_unit modelToWorldVisual [0, 0, 0] select 2);
2015-03-17 14:42:25 +00:00
2015-03-25 12:32:59 +00:00
_position = _position vectorAdd [0, 0, _offset];
2015-03-18 12:36:22 +00:00
2015-03-25 12:32:59 +00:00
// attach object
_target attachTo [_unit, _position];
2015-03-18 12:36:22 +00:00
2015-03-25 12:32:59 +00:00
};
2015-03-25 19:45:47 +00:00
["setDir", _target, [_target, _direction]] call EFUNC(common,targetEvent);
2015-03-17 14:42:25 +00:00
_unit setVariable [QGVAR(isCarrying), true, true];
_unit setVariable [QGVAR(carriedObject), _target, true];
// 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]] call FUNC(dropObject_carry)}
] call EFUNC(common,addActionEventHandler)];
2015-03-17 14:42:25 +00:00
// show mouse hint
[localize LSTRING(Drop), "", localize LSTRING(LowerRaise)] call EFUNC(interaction,showMouseHint);
2015-03-17 14:42:25 +00:00
// check everything
[FUNC(carryObjectPFH), 0.5, [_unit, _target]] call CBA_fnc_addPerFrameHandler;
2015-03-17 14:42:25 +00:00
// reset current dragging height.
GVAR(currentHeightChange) = 0;
// prevent UAVs from firing
2016-01-28 18:52:53 +00:00
private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew);
if !(_UAVCrew isEqualTo []) then {
{_target deleteVehicleCrew _x} count _UAVCrew;
_target setVariable [QGVAR(isUAV), true, true];
};