From 655f23b53cfbf99017f4593c5855e1c83693f506 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 24 Mar 2015 21:37:27 +0100 Subject: [PATCH] start carrying phase --- addons/dragging/XEH_preInit.sqf | 2 + addons/dragging/functions/fnc_dropObject.sqf | 10 ++-- .../functions/fnc_dropObject_carry.sqf | 18 +++++- addons/dragging/functions/fnc_startCarry.sqf | 57 +++++++++++++++++++ .../dragging/functions/fnc_startCarryPFH.sqf | 23 ++++++++ 5 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 addons/dragging/functions/fnc_startCarry.sqf create mode 100644 addons/dragging/functions/fnc_startCarryPFH.sqf diff --git a/addons/dragging/XEH_preInit.sqf b/addons/dragging/XEH_preInit.sqf index dba69eb22a..f596a89493 100644 --- a/addons/dragging/XEH_preInit.sqf +++ b/addons/dragging/XEH_preInit.sqf @@ -24,6 +24,8 @@ PREP(initPerson); PREP(isObjectOnObject); PREP(setCarryable); PREP(setDraggable); +PREP(startCarry); +PREP(startCarryPFH); PREP(startDrag); PREP(startDragPFH); diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 9ebbfae61f..489457bfbc 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -27,7 +27,7 @@ _inBuilding = [_unit] call FUNC(isObjectOnObject); _unit playAction "released"; // prevent collision damage -["fixCollision", _unit, _unit] call EFUNC(common,targetEvent); +["fixCollision", _unit] call EFUNC(common,localEvent); ["fixCollision", _target, _target] call EFUNC(common,targetEvent); // release object @@ -37,7 +37,7 @@ if (_target isKindOf "CAManBase") then { if (_target getVariable ["ACE_isUnconscious", false]) then { [_target, "unconscious", 2, true] call EFUNC(common,doAnimation); } else { - [_target, "", 2, true] call EFUNC(common,doAnimation); //@todo "AinjPpneMrunSnonWnonDb_release" seems to fall back to unconsciousness anim. retest after config fix + [_target, "", 2, true] call EFUNC(common,doAnimation); //@todo "AinjPpneMrunSnonWnonDb_release" seems to fall back to unconsciousness anim. }; }; @@ -54,5 +54,7 @@ _unit setVariable [QGVAR(draggedObject), objNull, true]; // make object accesable for other units [objNull, _target, true] call EFUNC(common,claim); -["fixPosition", _target, _target] call EFUNC(common,targetEvent); -["fixFloating", _target, _target] call EFUNC(common,targetEvent); +if !(_target isKindOf "CAManBase") then { + ["fixPosition", _target, _target] call EFUNC(common,targetEvent); + ["fixFloating", _target, _target] call EFUNC(common,targetEvent); +}; diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index 497b96b95c..83c93827d1 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -24,12 +24,22 @@ private "_inBuilding"; _inBuilding = [_unit] call FUNC(isObjectOnObject); // prevent collision damage -["fixCollision", _unit, _unit] call EFUNC(common,targetEvent); +["fixCollision", _unit] call EFUNC(common,localEvent); ["fixCollision", _target, _target] call EFUNC(common,targetEvent); // release object detach _target; +if (_target isKindOf "CAManBase") then { + [_unit, "", 2, true] call EFUNC(common,doAnimation); + + if (_target getVariable ["ACE_isUnconscious", false]) then { + [_target, "unconscious", 2, true] call EFUNC(common,doAnimation); + } else { + [_target, "", 2, true] call EFUNC(common,doAnimation); //@todo + }; +}; + // reselect weapon and re-enable sprint _unit selectWeapon primaryWeapon _unit; @@ -46,5 +56,7 @@ _unit setVariable [QGVAR(carriedObject), objNull, true]; // make object accesable for other units [objNull, _target, true] call EFUNC(common,claim); -["fixPosition", _target, _target] call EFUNC(common,targetEvent); -["fixFloating", _target, _target] call EFUNC(common,targetEvent); +if !(_target isKindOf "CAManBase") then { + ["fixPosition", _target, _target] call EFUNC(common,targetEvent); + ["fixFloating", _target, _target] call EFUNC(common,targetEvent); +}; diff --git a/addons/dragging/functions/fnc_startCarry.sqf b/addons/dragging/functions/fnc_startCarry.sqf new file mode 100644 index 0000000000..ca73805b61 --- /dev/null +++ b/addons/dragging/functions/fnc_startCarry.sqf @@ -0,0 +1,57 @@ +/* + * Author: commy2 + * + * Start the carrying process. + * + * 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; + +// 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); +}; + +// 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); + +private "_timer"; +_timer = 2; + +// can't play action that depends on weapon if it was added the same frame +/*[{_this playActionNow "grabDrag";}, _unit] call EFUNC(common,execNextFrame);*/ //@todo + +// move a bit closer and adjust direction when trying to pick up a person +if (_target isKindOf "CAManBase") then { + /*[_target, "AinjPpneMrunSnonWnonDb_grab", 2, true] call EFUNC(common,doAnimation); + _target setDir (getDir _unit + 180); + _target setPos (getPos _unit vectorAdd (vectorDir _unit vectorMultiply 1.5));*/ + + _timer = 15; + + +//@todo +}; + +// prevents draging and carrying at the same time +_unit setVariable [QGVAR(isCarrying), true, true]; + +[FUNC(startCarryPFH), 0.2, [_unit, _target], _timer] call CBA_fnc_addPerFrameHandler; diff --git a/addons/dragging/functions/fnc_startCarryPFH.sqf b/addons/dragging/functions/fnc_startCarryPFH.sqf new file mode 100644 index 0000000000..b9cfd06d0c --- /dev/null +++ b/addons/dragging/functions/fnc_startCarryPFH.sqf @@ -0,0 +1,23 @@ +// by commy2 +#include "script_component.hpp" + +private ["_unit", "_target", "_timeOut"]; + +_unit = _this select 0 select 0; +_target = _this select 0 select 1; +_timeOut = _this select 0 select 2; + +// timeout. Done with lifting object. Start carrying process. +if (time > _timeOut) exitWith { + [_this select 1] call CBA_fnc_removePerFrameHandler; + + // drop if in timeout + private "_carriedObject"; + _carriedObject = _unit getVariable [QGVAR(carriedObject), objNull]; + + if (!isNull _carriedObject) exitWith { + [_unit, _carriedObject] call FUNC(dropObject); + }; + + [_unit, _target] call FUNC(carryObject); +};