ACE3/addons/dragging/functions/fnc_carryObject.sqf

81 lines
2.1 KiB
Plaintext
Raw Normal View History

2015-03-17 14:42:25 +00:00
/*
* Author: commy2
*
* Carry an object.
*
* Argument:
* 0: Unit that should do the carrying (Object)
* 1: Object to carry (Object)
*
* Return value:
* NONE.
*/
#include "script_component.hpp"
private ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
2015-03-18 13:14:16 +00:00
// check weight
private "_weight";
_weight = [_target] call FUNC(getWeight);
if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith {
[localize "STR_ACE_Dragging_UnableToDrag"] call EFUNC(common,displayTextStructured);
};
2015-03-17 14:42:25 +00:00
// select no weapon and stop sprinting
_unit action ["SwitchWeapon", _unit, _unit, 99];
[_unit, "isDragging", true] call EFUNC(common,setforceWalkStatus);
// prevent multiple players from accessing the same object
[_unit, _target, true] call EFUNC(common,claim);
// get attachTo offset and direction.
private ["_position", "_direction"];
_position = _target getVariable [QGVAR(carryPosition), [0, 0, 0]];
_direction = _target getVariable [QGVAR(carryDirection), 0];
2015-03-18 12:36:22 +00:00
// add height offset of model
private "_offset";
_offset = (_target modelToWorld [0, 0, 0] select 2) - (_unit modelToWorld [0, 0, 0] select 2);
_position = _position vectorAdd [0, 0, _offset];
2015-03-17 14:42:25 +00:00
// attach object
_target attachTo [_unit, _position];
_target setDir _direction;
_unit setVariable [QGVAR(isCarrying), true, true];
_unit setVariable [QGVAR(carriedObject), _target, true];
// add scrollwheel action to release object
private "_actionID";
_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];
if (_actionID != -1) then {
_unit removeAction _actionID;
};
_actionID = _unit addAction [
format ["<t color='#FF0000'>%1</t>", localize "STR_ACE_Dragging_Drop"],
QUOTE([ARR_2(_this select 0, (_this select 0) getVariable [ARR_2(QUOTE(QGVAR(carriedObject)),objNull)])] call FUNC(dropObject_carry)),
nil,
20,
false,
true,
"",
QUOTE(!isNull (_this getVariable [ARR_2(QUOTE(QGVAR(carriedObject)),objNull)]))
];
_unit setVariable [QGVAR(ReleaseActionID), _actionID];
// check everything
[FUNC(carryObjectPFH), 0, [_unit, _target]] call CBA_fnc_addPerFrameHandler;
// reset current dragging height.
GVAR(currentHeightChange) = 0;