mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
function to drop object, fix position event
This commit is contained in:
parent
ad181de578
commit
27404fed1b
@ -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 {
|
||||
|
@ -56,6 +56,7 @@ PREP(execRemoteFnc);
|
||||
PREP(executePersistent);
|
||||
PREP(filter);
|
||||
PREP(fixLoweredRifleAnimation);
|
||||
PREP(fixPosition);
|
||||
PREP(getAllDefinedSetVariables);
|
||||
PREP(getAllGear);
|
||||
PREP(getCaptivityStatus);
|
||||
|
29
addons/common/functions/fnc_fixPosition.sqf
Normal file
29
addons/common/functions/fnc_fixPosition.sqf
Normal 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;
|
||||
};
|
@ -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));
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
13
addons/dragging/XEH_clientInit.sqf
Normal file
13
addons/dragging/XEH_clientInit.sqf
Normal 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);
|
@ -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;
|
||||
};
|
@ -3,8 +3,12 @@
|
||||
ADDON = false;
|
||||
|
||||
PREP(canDrag);
|
||||
PREP(dragObject);
|
||||
PREP(dragObjectPFH);
|
||||
PREP(dropObject);
|
||||
PREP(initObject);
|
||||
PREP(setDraggable);
|
||||
PREP(startDrag);
|
||||
PREP(startDragPFH);
|
||||
|
||||
ADDON = true;
|
||||
|
54
addons/dragging/functions/fnc_dragObject.sqf
Normal file
54
addons/dragging/functions/fnc_dragObject.sqf
Normal 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;
|
30
addons/dragging/functions/fnc_dragObjectPFH.sqf
Normal file
30
addons/dragging/functions/fnc_dragObjectPFH.sqf
Normal 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;
|
||||
};
|
36
addons/dragging/functions/fnc_dropObject.sqf
Normal file
36
addons/dragging/functions/fnc_dropObject.sqf
Normal 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);
|
@ -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);
|
||||
|
@ -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;
|
||||
|
20
addons/dragging/functions/fnc_startDragPFH.sqf
Normal file
20
addons/dragging/functions/fnc_startDragPFH.sqf
Normal 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;
|
||||
};
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user