mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #261 from KoffeinFlummi/attachCleanup
Attach cleanup
This commit is contained in:
commit
41489e271c
@ -1,6 +1,10 @@
|
||||
|
||||
class Extended_PreInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE(call COMPILE_FILE(XEH_preInit));
|
||||
};
|
||||
};
|
||||
class Extended_PostInit_EventHandlers {
|
||||
class ADDON {
|
||||
clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) );
|
||||
};
|
||||
};
|
||||
|
@ -4,23 +4,23 @@
|
||||
class ACE_MainActions { \
|
||||
class GVAR(AttachVehicle) { \
|
||||
displayName = "$STR_ACE_Attach_AttachDetach"; \
|
||||
condition = QUOTE(([ARR_3(_player, _target, '')] call FUNC(canAttach))); \
|
||||
statement = QUOTE( [ARR_2(_player, _target)] call FUNC(openAttachUI);); \
|
||||
exceptions[] = {"isNotDragging"}; \
|
||||
condition = QUOTE(_this call FUNC(canAttach)); \
|
||||
insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions)); \
|
||||
exceptions[] = {}; \
|
||||
showDisabled = 0; \
|
||||
priority = 0; \
|
||||
icon = PATHTOF(UI\attach_ca.paa); \
|
||||
distance = 4; \
|
||||
distance = 4.5; \
|
||||
}; \
|
||||
class GVAR(DetachVehicle) { \
|
||||
displayName = "$STR_ACE_Attach_Detach"; \
|
||||
condition = QUOTE(([ARR_2(_player, _target)] call FUNC(canDetach))); \
|
||||
statement = QUOTE( [ARR_2(_player, _target)] call FUNC(detach) ); \
|
||||
exceptions[] = {"isNotDragging"}; \
|
||||
condition = QUOTE(_this call FUNC(canDetach)); \
|
||||
statement = QUOTE(_this call FUNC(detach) ); \
|
||||
exceptions[] = {}; \
|
||||
showDisabled = 0; \
|
||||
priority = 0; \
|
||||
priority = 0.1; \
|
||||
icon = PATHTOF(UI\detach_ca.paa); \
|
||||
distance = 4; \
|
||||
distance = 4.5; \
|
||||
}; \
|
||||
}; \
|
||||
};
|
||||
@ -55,18 +55,18 @@ class CfgVehicles {
|
||||
class ACE_Equipment {
|
||||
class GVAR(Attach) {
|
||||
displayName = "$STR_ACE_Attach_AttachDetach";
|
||||
condition = QUOTE(([ARR_3(_player, _player, '')] call FUNC(canAttach)));
|
||||
statement = QUOTE( [ARR_2(_player, _player)] call FUNC(openAttachUI); );
|
||||
condition = QUOTE(_this call FUNC(canAttach));
|
||||
insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions));
|
||||
exceptions[] = {"isNotDragging"};
|
||||
showDisabled = 0;
|
||||
priority = 5;
|
||||
icon = PATHTOF(UI\attach_ca.paa);
|
||||
hotkey = "T";
|
||||
// hotkey = "T";
|
||||
};
|
||||
class GVAR(Detach) {
|
||||
displayName = "$STR_ACE_Attach_Detach";
|
||||
condition = QUOTE(([ARR_2(_player, _player)] call FUNC(canDetach)));
|
||||
statement = QUOTE( [ARR_2(_player, _player)] call FUNC(detach) );
|
||||
condition = QUOTE(_this call FUNC(canDetach));
|
||||
statement = QUOTE(_this call FUNC(detach));
|
||||
exceptions[] = {"isNotDragging"};
|
||||
showDisabled = 0;
|
||||
priority = 5;
|
||||
|
6
addons/attach/XEH_clientInit.sqf
Normal file
6
addons/attach/XEH_clientInit.sqf
Normal file
@ -0,0 +1,6 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
if (!hasInterface) exitWith {};
|
||||
|
||||
//If attach placing, stop when opening menu:
|
||||
["interactMenuOpened", {GVAR(placeAction) = 0;}] call EFUNC(common,addEventHandler);
|
@ -6,8 +6,7 @@ PREP(attach);
|
||||
PREP(canAttach);
|
||||
PREP(canDetach);
|
||||
PREP(detach);
|
||||
PREP(openAttachUI);
|
||||
PREP(getChildrenAttachActions);
|
||||
PREP(placeApprove);
|
||||
PREP(placeCancel);
|
||||
|
||||
ADDON = true;
|
||||
|
@ -1,53 +1,54 @@
|
||||
/*
|
||||
* Author: eRazeri and esteldunedain
|
||||
* Author: eRazeri, esteldunedain, PabstMirror
|
||||
* Attach an item to the unit
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit doing the attach (player) <OBJECT>
|
||||
* 1: vehicle that it will be attached to (player or vehicle) <OBJECT>
|
||||
* 2: Name of the attachable item <STRING>
|
||||
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
|
||||
* 1: unit doing the attach (player) <OBJECT>
|
||||
* 2: Array containing a string of the attachable item <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
* [bob, bob, ["light"]] call ace_attach_fnc_attach;
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_3(_unit,_attachToVehicle,_itemName);
|
||||
private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID"];
|
||||
|
||||
PARAMS_3(_attachToVehicle,_unit,_args);
|
||||
_itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam;
|
||||
|
||||
//Sanity Check (_unit has item in inventory, not over attach limit)
|
||||
if !([_unit, _attachToVehicle, _itemName] call FUNC(canAttach)) exitWith {ERROR("Tried to attach, but check failed");};
|
||||
|
||||
private ["_itemVehClass", "_onAtachText", "_selfAttachPosition"];
|
||||
if ((_itemClassname == "") || {!(_this call FUNC(canAttach))}) exitWith {ERROR("Tried to attach, but check failed");};
|
||||
|
||||
_itemVehClass = "";
|
||||
_onAtachText = "";
|
||||
_selfAttachPosition = [_unit, [-0.05, 0, 0.12], "rightshoulder"];
|
||||
|
||||
switch (true) do {
|
||||
case (_itemName == "ACE_IR_Strobe_Item"): {
|
||||
case (_itemClassname == "ACE_IR_Strobe_Item"): {
|
||||
_itemVehClass = "ACE_IR_Strobe_Effect";
|
||||
_onAtachText = localize "STR_ACE_Attach_IrStrobe_Attached";
|
||||
//_selfAttachPosition = [_unit, [0, -0.11, 0.16], "pilot"]; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri
|
||||
};
|
||||
case (_itemName == "B_IR_Grenade"): {
|
||||
case (_itemClassname == "B_IR_Grenade"): {
|
||||
_itemVehClass = "B_IRStrobe";
|
||||
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
|
||||
};
|
||||
case (_itemName == "O_IR_Grenade"): {
|
||||
case (_itemClassname == "O_IR_Grenade"): {
|
||||
_itemVehClass = "O_IRStrobe";
|
||||
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
|
||||
};
|
||||
case (_itemName == "I_IR_Grenade"): {
|
||||
case (_itemClassname == "I_IR_Grenade"): {
|
||||
_itemVehClass = "I_IRStrobe";
|
||||
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
|
||||
};
|
||||
case (toLower _itemName in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]): {
|
||||
_itemVehClass = _itemName;
|
||||
case (toLower _itemClassname in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]): {
|
||||
_itemVehClass = _itemClassname;
|
||||
_onAtachText = localize "STR_ACE_Attach_Chemlight_Attached";
|
||||
};
|
||||
};
|
||||
@ -55,36 +56,50 @@ switch (true) do {
|
||||
if (_itemVehClass == "") exitWith {ERROR("no _itemVehClass for Item");};
|
||||
|
||||
if (_unit == _attachToVehicle) then { //Self Attachment
|
||||
_unit removeItem _itemName; // Remove item
|
||||
_unit removeItem _itemClassname; // Remove item
|
||||
_attachedItem = _itemVehClass createVehicle [0,0,0];
|
||||
_attachedItem attachTo _selfAttachPosition;
|
||||
[_onAtachText] call EFUNC(common,displayTextStructured);
|
||||
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemName], true];
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemClassname], true];
|
||||
} else {
|
||||
GVAR(setupObject) = _itemVehClass createVehicleLocal [0,0,-10000];
|
||||
GVAR(setupObject) enableSimulationGlobal false;
|
||||
GVAR(SetupPlacmentText) = _onAtachText;
|
||||
GVAR(SetupPlacmentItem) = _itemName;
|
||||
GVAR(SetupAttachVehicle) = _attachToVehicle;
|
||||
GVAR(placer) = _unit;
|
||||
GVAR(placeAction) = -1;
|
||||
|
||||
_tempObject = _itemVehClass createVehicleLocal [0,0,-10000];
|
||||
_tempObject enableSimulationGlobal false;
|
||||
|
||||
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
|
||||
|
||||
[QGVAR(PlacementEachFrame),"OnEachFrame", {
|
||||
private "_player";
|
||||
_player = ACE_player;
|
||||
//Stop if player switch or player gets to far from vehicle
|
||||
if (GVAR(placer) != _player || {_player distance GVAR(SetupAttachVehicle) > 7}) exitWith {
|
||||
call FUNC(placeCancel);
|
||||
//MenuBack isn't working for now (localize "STR_ACE_Attach_CancelAction")
|
||||
[{[localize "STR_ACE_Attach_PlaceAction", ""] call EFUNC(interaction,showMouseHint)}, [], 0, 0] call EFUNC(common,waitAndExecute);
|
||||
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = 1;}] call EFUNC(common,AddActionEventHandler)];
|
||||
// _unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {true}, {GVAR(placeAction) = 0;}] call EFUNC(common,AddActionEventHandler)];
|
||||
|
||||
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize "STR_ACE_Attach_CancelAction"], {GVAR(placeAction) = 0}];
|
||||
|
||||
[{
|
||||
PARAMS_2(_args,_pfID);
|
||||
EXPLODE_7_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText,_actionID);
|
||||
|
||||
if ((GVAR(placeAction) != -1) ||
|
||||
{_unit != ACE_player} ||
|
||||
{!([_unit, _attachToVehicle, []] call EFUNC(common,canInteractWith))} ||
|
||||
{!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then {
|
||||
|
||||
[_pfID] call CBA_fnc_removePerFrameHandler;
|
||||
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
||||
[] call EFUNC(interaction,hideMouseHint);
|
||||
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
||||
//[_unit, "MenuBack", (_unit getVariable [QGVAR(cancelActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
||||
_unit removeAction _actionID;
|
||||
|
||||
if (GVAR(placeAction) == 1) then {
|
||||
_startingPosition = _tempObject modelToWorld [0,0,0];
|
||||
[_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _startingPosition] call FUNC(placeApprove);
|
||||
};
|
||||
deleteVehicle _tempObject;
|
||||
} else {
|
||||
_tempObject setPosATL ((ASLtoATL eyePos _unit) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]));;
|
||||
};
|
||||
GVAR(pfeh_running) = true;
|
||||
_pos = (ASLtoATL eyePos _player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]);
|
||||
GVAR(setupObject) setPosATL _pos;
|
||||
}] call BIS_fnc_addStackedEventHandler; // @todo replace with CBA PFH
|
||||
|
||||
//had to delay the mouseHint, not sure why
|
||||
[{[localize "STR_ACE_Attach_PlaceAction", localize "STR_ACE_Attach_CancelAction"] call EFUNC(interaction,showMouseHint)}, [], 0, 0] call EFUNC(common,waitAndExecute);
|
||||
|
||||
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {GVAR(pfeh_running) && {!isNull (GVAR(setupObject))}}, {call FUNC(placeApprove);}] call EFUNC(common,AddActionEventHandler)];
|
||||
_unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {GVAR(pfeh_running) && {!isNull (GVAR(setupObject))}}, {call FUNC(placeCancel);}] call EFUNC(common,AddActionEventHandler)];
|
||||
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
||||
};
|
||||
|
@ -3,25 +3,28 @@
|
||||
* Check if a unit can attach a specific item.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit doing the attach (player) <OBJECT>
|
||||
* 1: vehicle that it will be attached to (player or vehicle) <OBJECT>
|
||||
* 2: Name of the attachable item <STRING>
|
||||
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
|
||||
* 1: unit doing the attach (player) <OBJECT>
|
||||
* 2: Array empty or containing a string of the attachable item <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* Boolean <BOOL>
|
||||
* Can Attach <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
* [bob, bob, ["light"]] call ace_attach_fnc_canAttach;
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_3(_unit,_attachToVehicle,_item);
|
||||
PARAMS_3(_attachToVehicle,_player,_args);
|
||||
|
||||
private ["_attachLimit", "_attachedObjects"];
|
||||
private ["_itemName", "_attachLimit", "_attachedObjects"];
|
||||
|
||||
_attachLimit = [10, 1] select (_unit == _attachToVehicle);
|
||||
_itemName = [_args, 0, ""] call CBA_fnc_defaultParam;
|
||||
_attachLimit = [6, 1] select (_player == _attachToVehicle);
|
||||
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
||||
|
||||
canStand _unit && {alive _attachToVehicle} && {count _attachedObjects < _attachLimit} && {_item in (itemsWithMagazines _unit + [""])}
|
||||
_playerPos = (ACE_player modelToWorld (ACE_player selectionPosition "pilot"));
|
||||
|
||||
(canStand _player) && {(_attachToVehicle distance _player) < 7} && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])};
|
||||
|
@ -3,20 +3,20 @@
|
||||
* Check if a unit has an item attached and if it can remove that item.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit doing the detaching (player) <STRING>
|
||||
* 1: vehicle that it will be detached from (player or vehicle) <OBJECT>
|
||||
* 0: vehicle that it will be detached from (player or vehicle) <OBJECT>
|
||||
* 1: unit doing the detaching (player) <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Boolean <BOOL>
|
||||
* Can Detach <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
* [bob, bob] call ace_attach_fnc_canDetach;
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_unit,_attachToVehicle);
|
||||
PARAMS_2(_attachToVehicle,_unit);
|
||||
|
||||
private ["_attachedObjects", "_inRange"];
|
||||
|
||||
|
@ -3,20 +3,20 @@
|
||||
* Detach an item from a unit
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit doing the attaching (player) <STRING>
|
||||
* 1: vehicle that it will be detached from (player or vehicle) <OBJECT>
|
||||
* 0: vehicle that it will be detached from (player or vehicle) <OBJECT>
|
||||
* 1: unit doing the detaching (player) <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
* [car, bob] call ace_attach_fnc_detach
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_unit,_attachToVehicle);
|
||||
PARAMS_2(_attachToVehicle,_unit);
|
||||
|
||||
private ["_attachedObjects", "_attachedItems"];
|
||||
|
||||
@ -74,13 +74,13 @@ _attachToVehicle setVariable [QGVAR(ItemNames), _attachedItems, true];
|
||||
|
||||
// Display message
|
||||
switch (true) do {
|
||||
case (_itemName == "ACE_IR_Strobe_Item") : {
|
||||
case (_itemName == "ACE_IR_Strobe_Item") : {
|
||||
[localize "STR_ACE_Attach_IrStrobe_Detached"] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
case (toLower _itemName in ["b_ir_grenade", "o_ir_grenade", "i_ir_grenade"]) : {
|
||||
case (toLower _itemName in ["b_ir_grenade", "o_ir_grenade", "i_ir_grenade"]) : {
|
||||
[localize "STR_ACE_Attach_IrGrenade_Detached"] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
case (toLower _itemName in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]) : {
|
||||
case (toLower _itemName in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]) : {
|
||||
[localize "STR_ACE_Attach_Chemlight_Detached"] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
};
|
||||
|
51
addons/attach/functions/fnc_getChildrenAttachActions.sqf
Normal file
51
addons/attach/functions/fnc_getChildrenAttachActions.sqf
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Author: Garth de Wet (LH), PabstMirror
|
||||
* Show the ammo counts for a static weapon.
|
||||
* Called from "insertChildren" on interact_menu
|
||||
*
|
||||
* Argument:
|
||||
* 0: Target <OBJECT>
|
||||
* 1: Player <OBJECT>
|
||||
*
|
||||
* Return value:
|
||||
* ChildActiosn<ARRAY>
|
||||
*
|
||||
* Example:
|
||||
* [player, player] call ace_attach_fnc_getChildrenAttachActions
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_target,_player);
|
||||
|
||||
_listed = [];
|
||||
_actions = [];
|
||||
|
||||
{
|
||||
if !(_x in _listed) then {
|
||||
_listed pushBack _x;
|
||||
_item = ConfigFile >> "CfgMagazines" >> _x;
|
||||
if (getNumber (_item >> "ACE_Attachable") == 1) then {
|
||||
_displayName = getText(_item >> "displayName");
|
||||
_picture = getText(_item >> "picture");
|
||||
_action = [_x, _displayName, _picture, {_this call FUNC(attach)}, {_this call FUNC(canAttach)}, {}, [_x]] call EFUNC(interact_menu,createAction);
|
||||
_actions pushBack [_action, [], _target];
|
||||
};
|
||||
};
|
||||
} forEach (magazines _player);
|
||||
|
||||
{
|
||||
if !(_x in _listed) then {
|
||||
_listed pushBack _x;
|
||||
_item = ConfigFile >> "CfgWeapons" >> _x;
|
||||
if (getNumber (_item >> "ACE_Attachable") == 1) then {
|
||||
_displayName = getText(_item >> "displayName");
|
||||
_picture = getText(_item >> "picture");
|
||||
_action = [_x, _displayName, _picture, {_this call FUNC(attach)}, {_this call FUNC(canAttach)}, {}, [_x]] call EFUNC(interact_menu,createAction);
|
||||
_actions pushBack [_action, [], _target];
|
||||
};
|
||||
};
|
||||
} forEach (items _player);
|
||||
|
||||
_actions
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Author: Garth de Wet (LH)
|
||||
* Opens the UI for attaching objects.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit <STRING>
|
||||
* 1: target <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_actions", "_attachables", "_item"];
|
||||
|
||||
PARAMS_2(_unit,_target);
|
||||
|
||||
GVAR(attachTarget) = _target;
|
||||
_listed = [];
|
||||
_attachables = magazines _unit;
|
||||
_actions = [localize "STR_ACE_Attach_AttachDetach", localize "STR_ACE_Attach_Attach"] call EFUNC(interaction,prepareSelectMenu);
|
||||
{
|
||||
if !(_x in _listed) then {
|
||||
_item = ConfigFile >> "CfgMagazines" >> _x;
|
||||
if (getNumber (_item >> "ACE_Attachable") == 1) then {
|
||||
_actions = [
|
||||
_actions,
|
||||
getText(_item >> "displayName"),
|
||||
getText(_item >> "picture"),
|
||||
_x
|
||||
] call EFUNC(interaction,addSelectableItem);
|
||||
};
|
||||
_listed pushBack _x;
|
||||
};
|
||||
} forEach _attachables;
|
||||
_attachables = items _unit;
|
||||
{
|
||||
if !(_x in _listed) then {
|
||||
_item = ConfigFile >> "CfgWeapons" >> _x;
|
||||
if (getNumber (_item >> "ACE_Attachable") == 1) then {
|
||||
_actions = [
|
||||
_actions,
|
||||
getText(_item >> "displayName"),
|
||||
getText(_item >> "picture"),
|
||||
_x
|
||||
] call EFUNC(interaction,addSelectableItem);
|
||||
};
|
||||
_listed pushBack _x;
|
||||
};
|
||||
} forEach _attachables;
|
||||
|
||||
[
|
||||
_actions,
|
||||
{
|
||||
[ACE_player, GVAR(attachTarget), _this] call FUNC(attach);
|
||||
call EFUNC(interaction,hideMenu);
|
||||
},
|
||||
{
|
||||
call EFUNC(interaction,hideMenu);
|
||||
}
|
||||
] call EFUNC(interaction,openSelectMenu);
|
@ -1,69 +1,55 @@
|
||||
/*
|
||||
* Author: Pabst Mirror (based on Explosive attach by Garth de Wet (LH))
|
||||
* Approves placement of the lightObject, scans for an appropriate location and attaches
|
||||
* A player can release the attachObject with it floating in mid-air.
|
||||
* This will use lineIntersectsWith to scan towards the center of the vehicle to find a collision
|
||||
* ArmA's collision detection is of couse terrible and often misses collisions (difference between what we see and collision LOD)
|
||||
* So it does multiple scans at slighly different angles
|
||||
* This is VERY computationaly intensive, but doesn't happen that often.
|
||||
*
|
||||
* Arguments:
|
||||
* Nothing
|
||||
* 0: Unit (player) <OBJECT>
|
||||
* 1: attachToVehicle <OBJECT>
|
||||
* 2: Item Classname (cfgWeapon/cfgMagazine) <STRING>
|
||||
* 3: Light Vehicle Classname <STRING>
|
||||
* 4: On Attach Text <STRING>
|
||||
* 5: Starting Pos of dummy item <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
* No
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_setupObject", "_setupClassname", "_itemClassname", "_placementText", "_attachToVehicle", "_placer", "_startingPosition", "_startingOffset", "_distanceFromCenter", "_closeInUnitVector", "_keepGoingCloser", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"];
|
||||
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_setupObject", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"];
|
||||
|
||||
PARAMS_6(_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_startingPosition);
|
||||
|
||||
if (GVAR(pfeh_running)) then {
|
||||
[QGVAR(PlacementEachFrame),"OnEachFrame"] call BIS_fnc_removeStackedEventHandler;
|
||||
GVAR(pfeh_running) = false;
|
||||
};
|
||||
|
||||
_setupObject = GVAR(setupObject);
|
||||
_setupClassname = typeOf _setupObject;
|
||||
_itemClassname = GVAR(SetupPlacmentItem);
|
||||
_placementText = GVAR(SetupPlacmentText);
|
||||
_attachToVehicle = GVAR(SetupAttachVehicle);
|
||||
_placer = GVAR(placer);
|
||||
|
||||
GVAR(SetupPlacmentItem) = "";
|
||||
GVAR(SetupPlacmentText) = "";
|
||||
GVAR(setupObject) = objNull;
|
||||
GVAR(SetupAttachVehicle) = objNull;
|
||||
GVAR(placer) = objNull;
|
||||
|
||||
[_placer, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
||||
[_placer, "DefaultAction", _placer getVariable [QGVAR(placeActionEH), -1]] call EFUNC(common,removeActionEventHandler);
|
||||
[_placer, "MenuBack", _placer getVariable [QGVAR(cancelActionEH), -1]] call EFUNC(common,removeActionEventHandler);
|
||||
call EFUNC(interaction,hideMouseHint);
|
||||
|
||||
//A player can release the attachObject with it floating in mid-air.
|
||||
//This will use lineIntersectsWith to scan towards the center of the vehicle to find a collision
|
||||
//ArmA's collision detection is of couse terrible and often misses collisions (difference between what we see and collision LOD)
|
||||
//So it does multiple scans at slighly different angles
|
||||
//This is VERY computationaly intensive, but doesn't happen that often.
|
||||
|
||||
_startingPosition = _setupObject modelToWorld [0,0,0];
|
||||
_startingOffset = _attachToVehicle worldToModel _startingPosition;
|
||||
|
||||
_distanceFromCenter = vectorMagnitude _startingOffset;
|
||||
_startDistanceFromCenter = vectorMagnitude _startingOffset;
|
||||
_closeInUnitVector = vectorNormalized (_startingOffset vectorFromTo [0,0,0]);
|
||||
_keepGoingCloser = true;
|
||||
_closeInDistance = 0;
|
||||
|
||||
while {_keepGoingCloser} do {
|
||||
if (_closeInDistance >= _distanceFromCenter) exitWith {};
|
||||
_closeInMax = _startDistanceFromCenter;
|
||||
_closeInMin = 0;
|
||||
|
||||
_closeInDistance = _closeInDistance + 0.01; //10mm each step
|
||||
//Delete Local Placement Object
|
||||
deleteVehicle _setupObject;
|
||||
|
||||
while {(_closeInMax - _closeInMin) > 0.01} do {
|
||||
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
||||
// systemChat format ["Trying %1 from %2 start %3", _closeInDistance, [_closeInMax, _closeInMin], _startDistanceFromCenter];
|
||||
_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
|
||||
_endPosTestOffset set [2, (_startingOffset select 2)];
|
||||
_endPosTest = _attachToVehicle modelToWorld _endPosTestOffset;
|
||||
|
||||
_doesIntersect = false;
|
||||
{
|
||||
if (_doesIntersect) exitWith {};
|
||||
_startingPosShifted = _startingPosition vectorAdd _x;
|
||||
_startASL = if (surfaceIsWater _startingPosShifted) then {_startingPosShifted} else {ATLtoASL _startingPosShifted};
|
||||
{
|
||||
@ -71,33 +57,37 @@ while {_keepGoingCloser} do {
|
||||
_endASL = if (surfaceIsWater _startingPosShifted) then {_endPosShifted} else {ATLtoASL _endPosShifted};
|
||||
|
||||
//Uncomment to see the lazor show, and see how the scanning works:
|
||||
drawLine3D [_startingPosShifted, _endPosShifted, [1,0,0,1]];
|
||||
|
||||
if (_attachToVehicle in lineIntersectsWith [_startASL, _endASL, _placer, _setupObject]) exitWith {_keepGoingCloser = false};
|
||||
// drawLine3D [_startingPosShifted, _endPosShifted, [1,0,0,1]];
|
||||
if (_attachToVehicle in lineIntersectsWith [_startASL, _endASL, _unit]) exitWith {_doesIntersect = true};
|
||||
} forEach [[0,0,0.045], [0,0,-0.045], [0,0.045,0], [0,-0.045,0], [0.045,0,0], [-0.045,0,0]];
|
||||
} forEach [[0,0,0], [0,0,0.05], [0,0,-0.05]];
|
||||
|
||||
if (_doesIntersect) then {
|
||||
_closeInMax = _closeInDistance;
|
||||
} else {
|
||||
_closeInMin = _closeInDistance;
|
||||
};
|
||||
};
|
||||
|
||||
//Delete Local Placement Object
|
||||
deleteVehicle _setupObject;
|
||||
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
||||
|
||||
//Checks
|
||||
if ((_closeInDistance >= _distanceFromCenter) || (!([_placer,_attachToVehicle,_itemClassname] call FUNC(canAttach)))) exitWith {
|
||||
TRACE_2("no valid spot found",_closeInDistance,_distanceFromCenter);
|
||||
//Checks (too close to center or can't attach)
|
||||
if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) exitWith {
|
||||
TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter);
|
||||
[localize "STR_ACE_Attach_Failed"] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
|
||||
//Move it out slightly, for visability sake (better to look a little funny than be embedded//sunk in the hull)
|
||||
//Move it out slightly, for visability sake (better to look a little funny than be embedded//sunk in the hull and be useless)
|
||||
_closeInDistance = (_closeInDistance - 0.0085);
|
||||
|
||||
//Create New 'real' Object
|
||||
_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
|
||||
_endPosTestOffset set [2, (_startingOffset select 2)];
|
||||
_attachedObject = _setupClassname createVehicle (getPos _placer);
|
||||
_attachedObject = _itemVehClass createVehicle (getPos _unit);
|
||||
_attachedObject attachTo [_attachToVehicle, _endPosTestOffset];
|
||||
|
||||
//Remove Item from inventory
|
||||
_placer removeItem _itemClassname;
|
||||
_unit removeItem _itemClassname;
|
||||
|
||||
//Add Object to ACE_AttachedObjects and ACE_AttachedItemNames
|
||||
_currentObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
||||
@ -107,4 +97,4 @@ _currentItemNames = _attachToVehicle getVariable [QGVAR(ItemNames), []];
|
||||
_currentItemNames pushBack _itemClassname;
|
||||
_attachToVehicle setVariable [QGVAR(ItemNames), _currentItemNames, true];
|
||||
|
||||
[_placementText] call EFUNC(common,displayTextStructured);
|
||||
[_onAtachText] call EFUNC(common,displayTextStructured);
|
||||
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Author: Pabst Mirror (based on Explosive attach by Garth de Wet (LH))
|
||||
* Cancels placement of the lightObject
|
||||
*
|
||||
* Arguments:
|
||||
* Nothing
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* Nothing
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
if (GVAR(pfeh_running)) then {
|
||||
[QGVAR(PlacementEachFrame),"OnEachFrame"] call BIS_fnc_removeStackedEventHandler;
|
||||
GVAR(pfeh_running) = false;
|
||||
};
|
||||
if (!isNull (GVAR(setupObject))) then {
|
||||
deleteVehicle GVAR(setupObject);
|
||||
};
|
||||
|
||||
[GVAR(placer), QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
||||
call EFUNC(interaction,hideMouseHint);
|
||||
[GVAR(placer), "DefaultAction", GVAR(placer) getVariable [QGVAR(placeActionEH), -1]] call EFUNC(common,removeActionEventHandler);
|
||||
[GVAR(placer), "MenuBack", GVAR(placer) getVariable [QGVAR(cancelActionEH), -1]] call EFUNC(common,removeActionEventHandler);
|
||||
|
||||
GVAR(placer) = objNull;
|
||||
GVAR(SetupPlacmentItem) = "";
|
||||
GVAR(SetupPlacmentText) = "";
|
||||
GVAR(setupObject) = objNull;
|
||||
GVAR(SetupAttachVehicle) = objNull;
|
Loading…
Reference in New Issue
Block a user