From 9ae4f39d054bbb700ce0834855158f7a961fffdf Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 26 Mar 2015 17:49:11 -0500 Subject: [PATCH 1/9] Binary Seach for attach pos --- addons/attach/functions/fnc_placeApprove.sqf | 32 +++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/addons/attach/functions/fnc_placeApprove.sqf b/addons/attach/functions/fnc_placeApprove.sqf index c6277e2961..6b76dad3f9 100644 --- a/addons/attach/functions/fnc_placeApprove.sqf +++ b/addons/attach/functions/fnc_placeApprove.sqf @@ -15,8 +15,7 @@ */ #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 ["_setupObject", "_setupClassname", "_itemClassname", "_placementText", "_attachToVehicle", "_placer", "_startingPosition", "_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_keepGoingCloser", "_closeInMax", "_closeInMin", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"]; if (GVAR(pfeh_running)) then { [QGVAR(PlacementEachFrame),"OnEachFrame"] call BIS_fnc_removeStackedEventHandler; @@ -50,20 +49,23 @@ call EFUNC(interaction,hideMouseHint); _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 +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}; { @@ -73,21 +75,29 @@ while {_keepGoingCloser} do { //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}; + if (_attachToVehicle in lineIntersectsWith [_startASL, _endASL, _placer, _setupObject]) 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; + }; }; +_closeInDistance = (_closeInMax + _closeInMin) / 2; + //Delete Local Placement Object deleteVehicle _setupObject; //Checks -if ((_closeInDistance >= _distanceFromCenter) || (!([_placer,_attachToVehicle,_itemClassname] call FUNC(canAttach)))) exitWith { - TRACE_2("no valid spot found",_closeInDistance,_distanceFromCenter); +if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_placer,_attachToVehicle,_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 From efe57461b5da6e03826ab3f0376a33a9516f4a9f Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 26 Mar 2015 20:05:30 -0500 Subject: [PATCH 2/9] misc --- addons/attach/CfgVehicles.hpp | 8 ++++---- addons/attach/functions/fnc_attach.sqf | 6 ++++-- addons/attach/functions/fnc_canAttach.sqf | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/addons/attach/CfgVehicles.hpp b/addons/attach/CfgVehicles.hpp index 15eca2fb62..328ec851ed 100644 --- a/addons/attach/CfgVehicles.hpp +++ b/addons/attach/CfgVehicles.hpp @@ -4,9 +4,9 @@ class ACE_MainActions { \ class GVAR(AttachVehicle) { \ displayName = "$STR_ACE_Attach_AttachDetach"; \ - condition = QUOTE(([ARR_3(_player, _target, '')] call FUNC(canAttach))); \ + condition = QUOTE(([ARR_2(_player, _target)] call FUNC(canAttach))); \ statement = QUOTE( [ARR_2(_player, _target)] call FUNC(openAttachUI);); \ - exceptions[] = {"isNotDragging"}; \ + exceptions[] = {}; \ showDisabled = 0; \ priority = 0; \ icon = PATHTOF(UI\attach_ca.paa); \ @@ -16,7 +16,7 @@ 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"}; \ + exceptions[] = {}; \ showDisabled = 0; \ priority = 0; \ icon = PATHTOF(UI\detach_ca.paa); \ @@ -55,7 +55,7 @@ class CfgVehicles { class ACE_Equipment { class GVAR(Attach) { displayName = "$STR_ACE_Attach_AttachDetach"; - condition = QUOTE(([ARR_3(_player, _player, '')] call FUNC(canAttach))); + condition = QUOTE(([ARR_2(_player, _player)] call FUNC(canAttach))); statement = QUOTE( [ARR_2(_player, _player)] call FUNC(openAttachUI); ); exceptions[] = {"isNotDragging"}; showDisabled = 0; diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 655cac598b..733a9c81eb 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -83,8 +83,10 @@ if (_unit == _attachToVehicle) then { //Self Attachment }] 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); + // [{[localize "STR_ACE_Attach_PlaceAction", localize "STR_ACE_Attach_CancelAction"] call EFUNC(interaction,showMouseHint)}, [], 0, 0] call EFUNC(common,waitAndExecute); + //RMB is unusable for now, so don't show it: + [{[localize "STR_ACE_Attach_PlaceAction", ""] 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)]; + // _unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {GVAR(pfeh_running) && {!isNull (GVAR(setupObject))}}, {call FUNC(placeCancel);}] call EFUNC(common,AddActionEventHandler)]; }; diff --git a/addons/attach/functions/fnc_canAttach.sqf b/addons/attach/functions/fnc_canAttach.sqf index 1c33f7b112..d4095570ef 100644 --- a/addons/attach/functions/fnc_canAttach.sqf +++ b/addons/attach/functions/fnc_canAttach.sqf @@ -5,7 +5,7 @@ * Arguments: * 0: unit doing the attach (player) * 1: vehicle that it will be attached to (player or vehicle) - * 2: Name of the attachable item + * 2: Name of the attachable item * * Return Value: * Boolean @@ -17,7 +17,8 @@ */ #include "script_component.hpp" -PARAMS_3(_unit,_attachToVehicle,_item); +PARAMS_2(_unit,_attachToVehicle); +DEFAULT_PARAM(2,_item,""); private ["_attachLimit", "_attachedObjects"]; From d03e47407511444a642785bee6da41ffe263695e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 00:02:54 -0500 Subject: [PATCH 3/9] Replace selection dialog with interact children --- addons/attach/CfgVehicles.hpp | 22 +++---- addons/attach/XEH_preInit.sqf | 1 + addons/attach/functions/fnc_attach.sqf | 16 +++-- addons/attach/functions/fnc_canAttach.sqf | 20 +++--- addons/attach/functions/fnc_canDetach.sqf | 6 +- addons/attach/functions/fnc_detach.sqf | 8 +-- .../fnc_getChildrenAttachActions.sqf | 51 ++++++++++++++ addons/attach/functions/fnc_openAttachUI.sqf | 66 ------------------- addons/attach/functions/fnc_placeApprove.sqf | 2 +- 9 files changed, 92 insertions(+), 100 deletions(-) create mode 100644 addons/attach/functions/fnc_getChildrenAttachActions.sqf delete mode 100644 addons/attach/functions/fnc_openAttachUI.sqf diff --git a/addons/attach/CfgVehicles.hpp b/addons/attach/CfgVehicles.hpp index 328ec851ed..91155956d1 100644 --- a/addons/attach/CfgVehicles.hpp +++ b/addons/attach/CfgVehicles.hpp @@ -4,9 +4,9 @@ class ACE_MainActions { \ class GVAR(AttachVehicle) { \ displayName = "$STR_ACE_Attach_AttachDetach"; \ - condition = QUOTE(([ARR_2(_player, _target)] call FUNC(canAttach))); \ - statement = QUOTE( [ARR_2(_player, _target)] call FUNC(openAttachUI);); \ - exceptions[] = {}; \ + condition = QUOTE(_this call FUNC(canAttach)); \ + insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions)); \ + exceptions[] = {"isNotDragging"}; \ showDisabled = 0; \ priority = 0; \ icon = PATHTOF(UI\attach_ca.paa); \ @@ -14,9 +14,9 @@ }; \ 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[] = {}; \ + condition = QUOTE(_this call FUNC(canDetach)); \ + statement = QUOTE(_this call FUNC(detach) ); \ + exceptions[] = {"isNotDragging"}; \ showDisabled = 0; \ priority = 0; \ icon = PATHTOF(UI\detach_ca.paa); \ @@ -55,18 +55,18 @@ class CfgVehicles { class ACE_Equipment { class GVAR(Attach) { displayName = "$STR_ACE_Attach_AttachDetach"; - condition = QUOTE(([ARR_2(_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; diff --git a/addons/attach/XEH_preInit.sqf b/addons/attach/XEH_preInit.sqf index 63eb2e8438..d11a3992b5 100644 --- a/addons/attach/XEH_preInit.sqf +++ b/addons/attach/XEH_preInit.sqf @@ -6,6 +6,7 @@ PREP(attach); PREP(canAttach); PREP(canDetach); PREP(detach); +PREP(getChildrenAttachActions); PREP(openAttachUI); PREP(placeApprove); PREP(placeCancel); diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 733a9c81eb..6486a55d5f 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -3,9 +3,9 @@ * Attach an item to the unit * * Arguments: - * 0: unit doing the attach (player) - * 1: vehicle that it will be attached to (player or vehicle) - * 2: Name of the attachable item + * 0: vehicle that it will be attached to (player or vehicle) + * 1: unit doing the attach (player) + * 2: Array containing a string of the attachable item * * Return Value: * Nothing @@ -17,12 +17,14 @@ */ #include "script_component.hpp" -PARAMS_3(_unit,_attachToVehicle,_itemName); +PARAMS_3(_attachToVehicle,_unit,_args); + +private ["_item", "_itemVehClass", "_onAtachText", "_selfAttachPosition"]; + +_itemName = [_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 ((_itemName == "") || {!(_this call FUNC(canAttach))}) exitWith {ERROR("Tried to attach, but check failed");}; _itemVehClass = ""; _onAtachText = ""; diff --git a/addons/attach/functions/fnc_canAttach.sqf b/addons/attach/functions/fnc_canAttach.sqf index d4095570ef..fb83b44d26 100644 --- a/addons/attach/functions/fnc_canAttach.sqf +++ b/addons/attach/functions/fnc_canAttach.sqf @@ -3,9 +3,9 @@ * Check if a unit can attach a specific item. * * Arguments: - * 0: unit doing the attach (player) - * 1: vehicle that it will be attached to (player or vehicle) - * 2: Name of the attachable item + * 0: vehicle that it will be attached to (player or vehicle) + * 1: unit doing the attach (player) + * 2: Array empty or containing a string of the attachable item * * Return Value: * Boolean @@ -17,12 +17,16 @@ */ #include "script_component.hpp" -PARAMS_2(_unit,_attachToVehicle); -DEFAULT_PARAM(2,_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 + [""])} +_ret = (canStand _player) && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])}; + +systemChat format ["[%1] Checking = %2", _itemName, _ret ]; +x = _this; +_ret diff --git a/addons/attach/functions/fnc_canDetach.sqf b/addons/attach/functions/fnc_canDetach.sqf index ad2f68776c..a32440e56e 100644 --- a/addons/attach/functions/fnc_canDetach.sqf +++ b/addons/attach/functions/fnc_canDetach.sqf @@ -3,8 +3,8 @@ * Check if a unit has an item attached and if it can remove that item. * * Arguments: - * 0: unit doing the detaching (player) - * 1: vehicle that it will be detached from (player or vehicle) + * 0: vehicle that it will be detached from (player or vehicle) + * 1: unit doing the detaching (player) * * Return Value: * Boolean @@ -16,7 +16,7 @@ */ #include "script_component.hpp" -PARAMS_2(_unit,_attachToVehicle); +PARAMS_2(_attachToVehicle,_unit); private ["_attachedObjects", "_inRange"]; diff --git a/addons/attach/functions/fnc_detach.sqf b/addons/attach/functions/fnc_detach.sqf index 7b0d82dec1..0386f5452a 100644 --- a/addons/attach/functions/fnc_detach.sqf +++ b/addons/attach/functions/fnc_detach.sqf @@ -3,20 +3,20 @@ * Detach an item from a unit * * Arguments: - * 0: unit doing the attaching (player) - * 1: vehicle that it will be detached from (player or vehicle) + * 0: vehicle that it will be detached from (player or vehicle) + * 1: unit doing the detaching (player) * * 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"]; diff --git a/addons/attach/functions/fnc_getChildrenAttachActions.sqf b/addons/attach/functions/fnc_getChildrenAttachActions.sqf new file mode 100644 index 0000000000..13d0d0d84c --- /dev/null +++ b/addons/attach/functions/fnc_getChildrenAttachActions.sqf @@ -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 + * 1: Player + * + * Return value: + * ChildActiosn + * + * 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 diff --git a/addons/attach/functions/fnc_openAttachUI.sqf b/addons/attach/functions/fnc_openAttachUI.sqf deleted file mode 100644 index 1b95be9b84..0000000000 --- a/addons/attach/functions/fnc_openAttachUI.sqf +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Author: Garth de Wet (LH) - * Opens the UI for attaching objects. - * - * Arguments: - * 0: unit - * 1: target - * - * 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); diff --git a/addons/attach/functions/fnc_placeApprove.sqf b/addons/attach/functions/fnc_placeApprove.sqf index 6b76dad3f9..6870acb54f 100644 --- a/addons/attach/functions/fnc_placeApprove.sqf +++ b/addons/attach/functions/fnc_placeApprove.sqf @@ -92,7 +92,7 @@ _closeInDistance = (_closeInMax + _closeInMin) / 2; deleteVehicle _setupObject; //Checks -if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_placer,_attachToVehicle,_itemClassname] call FUNC(canAttach))}) exitWith { +if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _placer, _itemClassname] call FUNC(canAttach))}) exitWith { TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter); [localize "STR_ACE_Attach_Failed"] call EFUNC(common,displayTextStructured); }; From 51e8dbf53f7daed2c7ae3160e0ef72ce3b112f29 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 00:12:39 -0500 Subject: [PATCH 4/9] misc --- addons/attach/XEH_preInit.sqf | 1 - addons/attach/functions/fnc_canAttach.sqf | 6 +----- .../functions/fnc_getChildrenAttachActions.sqf | 2 +- addons/attach/functions/fnc_placeApprove.sqf | 16 ++++++++-------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/addons/attach/XEH_preInit.sqf b/addons/attach/XEH_preInit.sqf index d11a3992b5..c4629a2216 100644 --- a/addons/attach/XEH_preInit.sqf +++ b/addons/attach/XEH_preInit.sqf @@ -7,7 +7,6 @@ PREP(canAttach); PREP(canDetach); PREP(detach); PREP(getChildrenAttachActions); -PREP(openAttachUI); PREP(placeApprove); PREP(placeCancel); diff --git a/addons/attach/functions/fnc_canAttach.sqf b/addons/attach/functions/fnc_canAttach.sqf index fb83b44d26..944b0ed1a9 100644 --- a/addons/attach/functions/fnc_canAttach.sqf +++ b/addons/attach/functions/fnc_canAttach.sqf @@ -25,8 +25,4 @@ _itemName = [_args, 0, ""] call CBA_fnc_defaultParam; _attachLimit = [6, 1] select (_player == _attachToVehicle); _attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []]; -_ret = (canStand _player) && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])}; - -systemChat format ["[%1] Checking = %2", _itemName, _ret ]; -x = _this; -_ret +(canStand _player) && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])}; diff --git a/addons/attach/functions/fnc_getChildrenAttachActions.sqf b/addons/attach/functions/fnc_getChildrenAttachActions.sqf index 13d0d0d84c..6ff9410475 100644 --- a/addons/attach/functions/fnc_getChildrenAttachActions.sqf +++ b/addons/attach/functions/fnc_getChildrenAttachActions.sqf @@ -42,7 +42,7 @@ _actions = []; 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); + _action = [_x, _displayName, _picture, {_this call FUNC(attach)}, {_this call FUNC(canAttach)}, {}, [_x]] call EFUNC(interact_menu,createAction); _actions pushBack [_action, [], _target]; }; }; diff --git a/addons/attach/functions/fnc_placeApprove.sqf b/addons/attach/functions/fnc_placeApprove.sqf index 6870acb54f..b1bafe56ac 100644 --- a/addons/attach/functions/fnc_placeApprove.sqf +++ b/addons/attach/functions/fnc_placeApprove.sqf @@ -37,7 +37,7 @@ 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); +// [_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. @@ -56,6 +56,9 @@ _keepGoingCloser = true; _closeInMax = _startDistanceFromCenter; _closeInMin = 0; +//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]; @@ -73,12 +76,12 @@ while {(_closeInMax - _closeInMin) > 0.01} 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]]; + // drawLine3D [_startingPosShifted, _endPosShifted, [1,0,0,1]]; - if (_attachToVehicle in lineIntersectsWith [_startASL, _endASL, _placer, _setupObject]) exitWith {_doesIntersect = true}; + if (_attachToVehicle in lineIntersectsWith [_startASL, _endASL, _placer]) 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 { @@ -88,10 +91,7 @@ while {(_closeInMax - _closeInMin) > 0.01} do { _closeInDistance = (_closeInMax + _closeInMin) / 2; -//Delete Local Placement Object -deleteVehicle _setupObject; - -//Checks +//Checks (too close to center or can't attach) if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _placer, _itemClassname] call FUNC(canAttach))}) exitWith { TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter); [localize "STR_ACE_Attach_Failed"] call EFUNC(common,displayTextStructured); From f43666eb93be7f0a1092edd65a0c43b11977678d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 11:14:04 -0500 Subject: [PATCH 5/9] Use CBA PFEH instead of BI stacked --- addons/attach/CfgVehicles.hpp | 10 ++-- addons/attach/XEH_preInit.sqf | 1 - addons/attach/functions/fnc_canAttach.sqf | 4 +- addons/attach/functions/fnc_placeApprove.sqf | 51 +++++--------------- addons/attach/functions/fnc_placeCancel.sqf | 35 -------------- 5 files changed, 21 insertions(+), 80 deletions(-) delete mode 100644 addons/attach/functions/fnc_placeCancel.sqf diff --git a/addons/attach/CfgVehicles.hpp b/addons/attach/CfgVehicles.hpp index 91155956d1..ce9b1a7413 100644 --- a/addons/attach/CfgVehicles.hpp +++ b/addons/attach/CfgVehicles.hpp @@ -6,21 +6,21 @@ displayName = "$STR_ACE_Attach_AttachDetach"; \ condition = QUOTE(_this call FUNC(canAttach)); \ insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions)); \ - exceptions[] = {"isNotDragging"}; \ + 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(_this call FUNC(canDetach)); \ statement = QUOTE(_this call FUNC(detach) ); \ - exceptions[] = {"isNotDragging"}; \ + exceptions[] = {}; \ showDisabled = 0; \ - priority = 0; \ + priority = 0.1; \ icon = PATHTOF(UI\detach_ca.paa); \ - distance = 4; \ + distance = 4.5; \ }; \ }; \ }; diff --git a/addons/attach/XEH_preInit.sqf b/addons/attach/XEH_preInit.sqf index c4629a2216..06c6ed1b01 100644 --- a/addons/attach/XEH_preInit.sqf +++ b/addons/attach/XEH_preInit.sqf @@ -8,6 +8,5 @@ PREP(canDetach); PREP(detach); PREP(getChildrenAttachActions); PREP(placeApprove); -PREP(placeCancel); ADDON = true; diff --git a/addons/attach/functions/fnc_canAttach.sqf b/addons/attach/functions/fnc_canAttach.sqf index 944b0ed1a9..550e780342 100644 --- a/addons/attach/functions/fnc_canAttach.sqf +++ b/addons/attach/functions/fnc_canAttach.sqf @@ -25,4 +25,6 @@ _itemName = [_args, 0, ""] call CBA_fnc_defaultParam; _attachLimit = [6, 1] select (_player == _attachToVehicle); _attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []]; -(canStand _player) && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])}; +_playerPos = (ACE_player modelToWorld (ACE_player selectionPosition "pilot")); + +(canStand _player) && {(_attachToVehicle distance _player) < 7} && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_itemName in ((itemsWithMagazines _player) + [""])}; diff --git a/addons/attach/functions/fnc_placeApprove.sqf b/addons/attach/functions/fnc_placeApprove.sqf index b1bafe56ac..f371ef7050 100644 --- a/addons/attach/functions/fnc_placeApprove.sqf +++ b/addons/attach/functions/fnc_placeApprove.sqf @@ -1,6 +1,11 @@ /* * 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 @@ -15,43 +20,14 @@ */ #include "script_component.hpp" -private ["_setupObject", "_setupClassname", "_itemClassname", "_placementText", "_attachToVehicle", "_placer", "_startingPosition", "_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_keepGoingCloser", "_closeInMax", "_closeInMin", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_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"]; -if (GVAR(pfeh_running)) then { - [QGVAR(PlacementEachFrame),"OnEachFrame"] call BIS_fnc_removeStackedEventHandler; - GVAR(pfeh_running) = false; -}; +PARAMS_6(_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_startingPosition); -_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; _startDistanceFromCenter = vectorMagnitude _startingOffset; _closeInUnitVector = vectorNormalized (_startingOffset vectorFromTo [0,0,0]); -_keepGoingCloser = true; _closeInMax = _startDistanceFromCenter; _closeInMin = 0; @@ -76,9 +52,8 @@ while {(_closeInMax - _closeInMin) > 0.01} 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]) exitWith {_doesIntersect = true}; + 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]]; @@ -92,7 +67,7 @@ while {(_closeInMax - _closeInMin) > 0.01} do { _closeInDistance = (_closeInMax + _closeInMin) / 2; //Checks (too close to center or can't attach) -if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _placer, _itemClassname] call FUNC(canAttach))}) exitWith { +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); }; @@ -103,11 +78,11 @@ _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), []]; @@ -117,4 +92,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); diff --git a/addons/attach/functions/fnc_placeCancel.sqf b/addons/attach/functions/fnc_placeCancel.sqf deleted file mode 100644 index 3abdf848ba..0000000000 --- a/addons/attach/functions/fnc_placeCancel.sqf +++ /dev/null @@ -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; From 86c7776802d782f9b41bc9435c501c207197587c Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 11:14:19 -0500 Subject: [PATCH 6/9] and this --- addons/attach/functions/fnc_attach.sqf | 77 +++++++++++++++----------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 6486a55d5f..0cb2030caf 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -21,35 +21,35 @@ PARAMS_3(_attachToVehicle,_unit,_args); private ["_item", "_itemVehClass", "_onAtachText", "_selfAttachPosition"]; -_itemName = [_args, 0, ""] call CBA_fnc_defaultParam; +_itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam; //Sanity Check (_unit has item in inventory, not over attach limit) -if ((_itemName == "") || {!(_this call FUNC(canAttach))}) exitWith {ERROR("Tried to attach, but check failed");}; +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"; }; }; @@ -57,38 +57,49 @@ 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); - }; - 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); - //RMB is unusable for now, so don't show it: + //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)]; - _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)]; + [{ + PARAMS_2(_args,_pfID); + EXPLODE_6_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText); + + if ((GVAR(placeAction) != -1) || + {_unit != ACE_player} || + {!([_unit, _attachToVehicle, []] call EFUNC(common,canInteractWith))} || + {!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then { + + systemChat "exiting"; + + [_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); + + 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]));; + }; + }, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText]] call CBA_fnc_addPerFrameHandler; }; From 91a1ed32643db3daa19335a5f94c542d67840f7e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 11:36:31 -0500 Subject: [PATCH 7/9] Cancle attach action --- addons/attach/functions/fnc_attach.sqf | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 0cb2030caf..6b7de1e72f 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -19,7 +19,7 @@ PARAMS_3(_attachToVehicle,_unit,_args); -private ["_item", "_itemVehClass", "_onAtachText", "_selfAttachPosition"]; +private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID"]; _itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam; @@ -76,23 +76,24 @@ if (_unit == _attachToVehicle) then { //Self Attachment _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 ["%1", localize "STR_ACE_Attach_CancelAction"], {GVAR(placeAction) = 0}]; + [{ PARAMS_2(_args,_pfID); - EXPLODE_6_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText); + 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 { - systemChat "exiting"; - [_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); @@ -101,5 +102,5 @@ if (_unit == _attachToVehicle) then { //Self Attachment } else { _tempObject setPosATL ((ASLtoATL eyePos _unit) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]));; }; - }, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText]] call CBA_fnc_addPerFrameHandler; + }, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler; }; From 4d62865ea2d06411771fb4c2f6326c08e6bd897a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 11:53:04 -0500 Subject: [PATCH 8/9] Stop placement on interact_menu open --- addons/attach/CfgEventHandlers.hpp | 6 +++++- addons/attach/XEH_clientInit.sqf | 6 ++++++ addons/attach/functions/fnc_attach.sqf | 6 +++--- addons/attach/functions/fnc_detach.sqf | 6 +++--- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 addons/attach/XEH_clientInit.sqf diff --git a/addons/attach/CfgEventHandlers.hpp b/addons/attach/CfgEventHandlers.hpp index f0a9f14d91..3daad1425a 100644 --- a/addons/attach/CfgEventHandlers.hpp +++ b/addons/attach/CfgEventHandlers.hpp @@ -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) ); + }; +}; diff --git a/addons/attach/XEH_clientInit.sqf b/addons/attach/XEH_clientInit.sqf new file mode 100644 index 0000000000..f7e663c2ae --- /dev/null +++ b/addons/attach/XEH_clientInit.sqf @@ -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); diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 6b7de1e72f..2a79a28699 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -1,5 +1,5 @@ /* - * Author: eRazeri and esteldunedain + * Author: eRazeri, esteldunedain, PabstMirror * Attach an item to the unit * * Arguments: @@ -77,7 +77,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment // _unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {true}, {GVAR(placeAction) = 0;}] call EFUNC(common,AddActionEventHandler)]; _actionID = _unit addAction [format ["%1", localize "STR_ACE_Attach_CancelAction"], {GVAR(placeAction) = 0}]; - + [{ PARAMS_2(_args,_pfID); EXPLODE_7_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText,_actionID); @@ -93,7 +93,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment [_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); diff --git a/addons/attach/functions/fnc_detach.sqf b/addons/attach/functions/fnc_detach.sqf index 0386f5452a..124e5910d6 100644 --- a/addons/attach/functions/fnc_detach.sqf +++ b/addons/attach/functions/fnc_detach.sqf @@ -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); }; }; From 47c72ac4aeae2a98afa6660c668834134ea28bb2 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 27 Mar 2015 12:08:05 -0500 Subject: [PATCH 9/9] Disable Debug Laser / Commenting --- addons/attach/functions/fnc_attach.sqf | 5 ++--- addons/attach/functions/fnc_canAttach.sqf | 4 ++-- addons/attach/functions/fnc_canDetach.sqf | 4 ++-- addons/attach/functions/fnc_placeApprove.sqf | 11 ++++++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 2a79a28699..a8b73052dc 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -11,16 +11,15 @@ * Nothing * * Example: - * Nothing + * [bob, bob, ["light"]] call ace_attach_fnc_attach; * * Public: No */ #include "script_component.hpp" -PARAMS_3(_attachToVehicle,_unit,_args); - 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) diff --git a/addons/attach/functions/fnc_canAttach.sqf b/addons/attach/functions/fnc_canAttach.sqf index 550e780342..966794b32f 100644 --- a/addons/attach/functions/fnc_canAttach.sqf +++ b/addons/attach/functions/fnc_canAttach.sqf @@ -8,10 +8,10 @@ * 2: Array empty or containing a string of the attachable item * * Return Value: - * Boolean + * Can Attach * * Example: - * Nothing + * [bob, bob, ["light"]] call ace_attach_fnc_canAttach; * * Public: No */ diff --git a/addons/attach/functions/fnc_canDetach.sqf b/addons/attach/functions/fnc_canDetach.sqf index a32440e56e..dc335e6bb6 100644 --- a/addons/attach/functions/fnc_canDetach.sqf +++ b/addons/attach/functions/fnc_canDetach.sqf @@ -7,10 +7,10 @@ * 1: unit doing the detaching (player) * * Return Value: - * Boolean + * Can Detach * * Example: - * Nothing + * [bob, bob] call ace_attach_fnc_canDetach; * * Public: No */ diff --git a/addons/attach/functions/fnc_placeApprove.sqf b/addons/attach/functions/fnc_placeApprove.sqf index f371ef7050..576721cf59 100644 --- a/addons/attach/functions/fnc_placeApprove.sqf +++ b/addons/attach/functions/fnc_placeApprove.sqf @@ -8,13 +8,18 @@ * This is VERY computationaly intensive, but doesn't happen that often. * * Arguments: - * Nothing + * 0: Unit (player) + * 1: attachToVehicle + * 2: Item Classname (cfgWeapon/cfgMagazine) + * 3: Light Vehicle Classname + * 4: On Attach Text + * 5: Starting Pos of dummy item * * Return Value: * Nothing * * Example: - * Nothing + * No * * Public: No */ @@ -52,7 +57,7 @@ while {(_closeInMax - _closeInMin) > 0.01} 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]]; + // 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]];