function to drop object, fix position event

This commit is contained in:
commy2 2015-03-16 19:25:29 +01:00
parent ad181de578
commit 27404fed1b
15 changed files with 231 additions and 16 deletions

View File

@ -20,6 +20,8 @@ if (hasInterface) then {
};
}] call FUNC(addEventhandler);
["fixPosition", FUNC(fixPosition)] call FUNC(addEventhandler);
// hack to get PFH to work in briefing
[QGVAR(onBriefingPFH), "onEachFrame", {
if (time > 0) exitWith {

View File

@ -56,6 +56,7 @@ PREP(execRemoteFnc);
PREP(executePersistent);
PREP(filter);
PREP(fixLoweredRifleAnimation);
PREP(fixPosition);
PREP(getAllDefinedSetVariables);
PREP(getAllGear);
PREP(getCaptivityStatus);

View File

@ -0,0 +1,29 @@
/*
* Author: commy2
*
* Fixes position of an object. E.g. moves object above ground and adjusts to terrain slope. Requires local object.
*
* Argument:
* Object (Object)
*
* Return value:
* NONE
*/
#include "script_component.hpp"
// setVectorUp requires local object
if (!local _this) exitWith {};
private "_position";
_position = getPos _this;
// don't place the object below the ground
if (_position select 2 < 0) then {
_position set [2, 0];
_this setPos _position;
};
// adjust position to sloped terrain, if placed on ground
if (getPosATL _this select 2 == _position select 2) then {
_this setVectorUp surfaceNormal _position;
};

View File

@ -7,7 +7,7 @@ class Extended_PreInit_EventHandlers {
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
clientInit = QUOTE(call COMPILE_FILE(XEH_clientInit));
};
};

View File

@ -4,7 +4,7 @@ class CfgVehicles {
class ReammoBox_F: ThingX {
XEH_ENABLED;
GVAR(canDrag) = 0;
GVAR(dragPosition[]) = {0,1,1};
GVAR(dragPosition[]) = {0,1.2,0};
GVAR(dragDirection) = 0;
};

View File

@ -0,0 +1,13 @@
// by PabstMirror, commy2
#include "script_component.hpp"
GVAR(currentHeightChange) = 0;
//[{_this call DFUNC(handleScrollWheel)}] call FUNC(common,addScrollWheelEventHandler);
if (isNil QGVAR(maxWeight)) then {
GVAR(maxWeight) = 800;
};
["isNotDragging", {!((_this select 0) getVariable [QGVAR(isDragging), false])}] call EFUNC(common,addCanInteractWithCondition);

View File

@ -1,11 +0,0 @@
// by PabstMirror
#include "script_component.hpp"
GVAR(currentHeightChange) = 0;
[{_this call DFUNC(handleScrollWheel)}] call FUNC(common,addScrollWheelEventHandler);
if (isNil QGVAR(maxWeight)) then {
GVAR(maxWeight) = 800;
};

View File

@ -3,8 +3,12 @@
ADDON = false;
PREP(canDrag);
PREP(dragObject);
PREP(dragObjectPFH);
PREP(dropObject);
PREP(initObject);
PREP(setDraggable);
PREP(startDrag);
PREP(startDragPFH);
ADDON = true;

View File

@ -0,0 +1,54 @@
/*
* Author: commy2
*
* Drag an object. Called from ace_dragging_fnc_startDrag
*
* Argument:
* 0: Unit that should do the dragging (Object)
* 1: Object to drag (Object)
*
* Return value:
* NONE.
*/
#include "script_component.hpp"
private ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// get attachTo offset and direction.
private ["_position", "_direction"];
_position = _target getVariable [QGVAR(dragPosition), [0, 0, 0]];
_direction = _target getVariable [QGVAR(dragDirection), 0];
// 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];
// attach object
_target attachTo [_unit, _position];
_target setDir _direction;
// add scrollwheel action to release object
/*
_actionID = _unit getVariable ["AGM_Drag_ReleaseActionID", -1];
if (_actionID != -1) then {
_unit removeAction _actionID;
};
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize "STR_AGM_Drag_EndDrag"], "player call AGM_Drag_fnc_releaseObject;", nil, 20, false, true, "","player call AGM_Drag_fnc_isDraggingObject"];
_unit setVariable ["AGM_Drag_ReleaseActionID", _actionID];
*/
_unit setVariable [QGVAR(isDragging), true, true];
// check everything
[FUNC(dragObjectPFH), 0, [_unit, _target]] call CBA_fnc_addPerFrameHandler;
// reset current dragging height.
GVAR(currentHeightChange) = 0;

View File

@ -0,0 +1,30 @@
// by commy2
#include "script_component.hpp"
private ["_unit", "_target"];
_unit = _this select 0 select 0;
_target = _this select 0 select 1;
// drop if the player is dead
if !([_unit] call EFUNC(common,isAlive)) exitWith {
[_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
// drop if the crate is destroyed
if !([_target] call EFUNC(common,isAlive)) exitWith {
[_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
// drop if not in dragging anim. This also exits when entering a vehicle.
if !(animationState _unit in DRAG_ANIMATIONS) exitWith {
[_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
if !([_unit] call EFUNC(common,isPlayer)) exitWith {
[_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};

View File

@ -0,0 +1,36 @@
/*
* Author: commy2
*
* Drop a dragged object.
*
* Argument:
* 0: Unit that drags the other object (Object)
* 1: Dragged object to drop (Object)
*
* Return value:
* NONE.
*/
#include "script_component.hpp"
private ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// remove scroll wheel action
/*
_this removeAction (_this getVariable ["AGM_Drag_ReleaseActionID", -1]);
*/
// play release animation
_unit playAction "released";
// release object
detach _target;
_unit setVariable [QGVAR(isDragging), false, true];
// make object accesable for other units
[objNull, _target, true] call EFUNC(common,claim);
["fixPosition", _target, _target] call EFUNC(common,targetEvent);

View File

@ -54,4 +54,4 @@ _name = "drag";
_icon = "";
_selection = "";
[_type, 0, ["ACE_MainActions", _name], _name, _icon, _selection, FUNC(startDrag), FUNC(canDrag), 2] call EFUNC(interact_menu,addClassAction);
[_type, 0, ["ACE_MainActions", _name], _name, _icon, _selection, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}, 2] call EFUNC(interact_menu,addClassAction);

View File

@ -1,2 +1,37 @@
/*
* Author: commy2
*
* Start the dragging process.
*
* Argument:
* 0: Unit that should do the dragging (Object)
* 1: Object to drag (Object)
*
* Return value:
* NONE.
*/
#include "script_component.hpp"
hint str _target
private ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// @todo check weight
//_ableToDrag = ((_draggedObject call AGM_Drag_fnc_GetWeight) <= AGM_Drag_MaxWeight);
// 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);
_unit playActionNow "grabDrag";
[FUNC(startDragPFH), 0.2, [_unit, _target, time + 5]] call CBA_fnc_addPerFrameHandler;

View File

@ -0,0 +1,20 @@
// 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. Do nothing. Quit. time, because anim length is linked to ingame time.
if (time > _timeOut) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
// unit is ready to start dragging
if (animationState _unit in DRAG_ANIMATIONS) exitWith {
[_unit, _target] call FUNC(dragObject);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};

View File

@ -9,4 +9,6 @@
#define DEBUG_SETTINGS DEBUG_ENABLED_DRAGGING
#endif
#include "\z\ace\addons\main\script_macros.hpp"
#include "\z\ace\addons\main\script_macros.hpp"
#define DRAG_ANIMATIONS ["amovpercmstpslowwrfldnon_acinpknlmwlkslowwrfldb_2", "amovpercmstpsraswpstdnon_acinpknlmwlksnonwpstdb_2", "amovpercmstpsnonwnondnon_acinpknlmwlksnonwnondb_2", "acinpknlmstpsraswrfldnon", "acinpknlmstpsnonwpstdnon", "acinpknlmstpsnonwnondnon", "acinpknlmwlksraswrfldb", "acinpknlmwlksnonwnondb"]