From d13e1f874a5a074d4491f1caa7f8adf0c5a86ee3 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 02:18:16 -0600 Subject: [PATCH 1/7] Attach - On Vehicles Adds the ability to attach to vehicles (chemlights, IR grenades). 3 positions, left and right of driver and the rear. --- .../attach_findVehicleModelPositions.sqf | 18 +++ AGM_Attach/config.cpp | 109 +++++++++++++++++- AGM_Attach/functions/fn_attach.sqf | 50 +++++--- AGM_Attach/functions/fn_canAttach.sqf | 2 +- AGM_Attach/functions/fn_canDetach.sqf | 2 +- AGM_Attach/functions/fn_detach.sqf | 22 ++-- AGM_Attach/functions/fn_openAttachUI.sqf | 42 ++++--- AGM_Attach/functions/fn_vehicleCanAttach.sqf | 35 ++++++ AGM_Attach/functions/fn_vehicleCanDetach.sqf | 35 ++++++ .../functions/fn_vehicleGetAttachPoint.sqf | 71 ++++++++++++ 10 files changed, 332 insertions(+), 54 deletions(-) create mode 100644 .devfiles/scripts/attach_findVehicleModelPositions.sqf create mode 100644 AGM_Attach/functions/fn_vehicleCanAttach.sqf create mode 100644 AGM_Attach/functions/fn_vehicleCanDetach.sqf create mode 100644 AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf diff --git a/.devfiles/scripts/attach_findVehicleModelPositions.sqf b/.devfiles/scripts/attach_findVehicleModelPositions.sqf new file mode 100644 index 000000000..eb8535485 --- /dev/null +++ b/.devfiles/scripts/attach_findVehicleModelPositions.sqf @@ -0,0 +1,18 @@ +//Pabst Mirror +//AGM_Attach - Helper for finding good attach points on vehicles (based on explosive placement) + + +TEST_LIGHT = "B_IRStrobe" createVehicle (getpos player); +TEST_LIGHT enableSimulation false; + +["asdf","OnEachFrame", { + _pos = (ASLtoATL eyePos player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]); + TEST_LIGHT setPosATL _pos; + + LightPos = cursorTarget worldToModel _pos; + hintSilent format ["LightPos: %1", LightPos]; +}] call BIS_fnc_addStackedEventHandler; + +//check debug: +//typeOf cursorTarget +//LightPos \ No newline at end of file diff --git a/AGM_Attach/config.cpp b/AGM_Attach/config.cpp index d0f954697..ab9428ebb 100644 --- a/AGM_Attach/config.cpp +++ b/AGM_Attach/config.cpp @@ -21,14 +21,81 @@ class CfgFunctions { class canDetach; class detach; class openAttachUI; + class vehicleCanAttach; + class vehicleCanDetach; + class vehicleGetAttachPoint; }; }; }; #define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \ - name = #ITEM; \ - count = COUNT; \ -}; + name = #ITEM; \ + count = COUNT; \ + }; + +#define MACRO_ATTACHTOVEHICLE \ + class AGM_Actions { \ + class AGM_Attach_right { \ + displayName = "$STR_AGM_Attach_AttachDetach"; \ + condition = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_vehicleCanAttach"; \ + statement = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_openAttachUI;"; \ + exceptions[] = {"AGM_Drag_isNotDragging"}; \ + showDisabled = 0; \ + priority = 0; \ + icon = "\AGM_Attach\UI\attach_ca.paa"; \ + hotkey = "T"; \ + }; \ + class AGM_Attach_Detach_right { \ + displayName = "$STR_AGM_Attach_Detach"; \ + condition = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_vehicleCanDetach"; \ + statement = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_detach"; \ + exceptions[] = {"AGM_Drag_isNotDragging"}; \ + showDisabled = 0; \ + priority = 0; \ + icon = "\AGM_Attach\UI\detach_ca.paa"; \ + hotkey = "T"; \ + }; \ + class AGM_Attach_left { \ + displayName = "$STR_AGM_Attach_AttachDetach"; \ + condition = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_vehicleCanAttach"; \ + statement = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_openAttachUI;"; \ + exceptions[] = {"AGM_Drag_isNotDragging"}; \ + showDisabled = 0; \ + priority = 0; \ + icon = "\AGM_Attach\UI\attach_ca.paa"; \ + hotkey = "T"; \ + }; \ + class AGM_Attach_Detach_left { \ + displayName = "$STR_AGM_Attach_Detach"; \ + condition = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_vehicleCanDetach"; \ + statement = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_detach"; \ + exceptions[] = {"AGM_Drag_isNotDragging"}; \ + showDisabled = 0; \ + priority = 0; \ + icon = "\AGM_Attach\UI\detach_ca.paa"; \ + hotkey = "T"; \ + }; \ + class AGM_Attach_rear { \ + displayName = "$STR_AGM_Attach_AttachDetach"; \ + condition = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_vehicleCanAttach"; \ + statement = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_openAttachUI;"; \ + exceptions[] = {"AGM_Drag_isNotDragging"}; \ + showDisabled = 0; \ + priority = 0; \ + icon = "\AGM_Attach\UI\attach_ca.paa"; \ + hotkey = "T"; \ + }; \ + class AGM_Attach_Detach_rear { \ + displayName = "$STR_AGM_Attach_Detach"; \ + condition = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_vehicleCanDetach"; \ + statement = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_detach"; \ + exceptions[] = {"AGM_Drag_isNotDragging"}; \ + showDisabled = 0; \ + priority = 0; \ + icon = "\AGM_Attach\UI\detach_ca.paa"; \ + hotkey = "T"; \ + }; \ + }; class CfgVehicles { class Man; @@ -38,7 +105,7 @@ class CfgVehicles { class AGM_Attach { displayName = "$STR_AGM_Attach_AttachDetach"; condition = "[_player, ''] call AGM_Attach_fnc_canAttach"; - statement = "[_player] call AGM_Attach_fnc_openAttachUI;"; + statement = "[_player, _player, 'self'] call AGM_Attach_fnc_openAttachUI;"; exceptions[] = {"AGM_Drag_isNotDragging"}; showDisabled = 0; priority = 5; @@ -48,7 +115,7 @@ class CfgVehicles { class AGM_Attach_Detach { displayName = "$STR_AGM_Attach_Detach"; condition = "[_player] call AGM_Attach_fnc_canDetach"; - statement = "[_player] call AGM_Attach_fnc_detach"; + statement = "[_player, _player, 'self'] call AGM_Attach_fnc_detach"; exceptions[] = {"AGM_Drag_isNotDragging"}; showDisabled = 0; priority = 5; @@ -59,6 +126,38 @@ class CfgVehicles { }; }; + class LandVehicle; + class Car: LandVehicle { + MACRO_ATTACHTOVEHICLE + }; + class Tank: LandVehicle { + MACRO_ATTACHTOVEHICLE + }; + class Air; + class Helicopter: Air { + MACRO_ATTACHTOVEHICLE + }; + class Plane: Air { + MACRO_ATTACHTOVEHICLE + }; + class Ship; + class Ship_F: Ship { + MACRO_ATTACHTOVEHICLE + }; + + class Car_F: Car {}; + class Hatchback_01_base_F: Car_F { + AGM_AttachPoint_left[] = {-0.929688,0.789063,-0.23848}; + AGM_AttachPoint_right[] = {0.741211,0.85791,-0.224247}; + AGM_AttachPoint_rear[] = {0,-2.095,0.182854}; + }; + class Truck_F: Car_F {}; + class Truck_03_base_F: Truck_F { + AGM_AttachPoint_left[] = {-1.16321,3.62256,0.0160751}; + AGM_AttachPoint_right[] = {1.28906,3.63965,-0.033287}; + AGM_AttachPoint_rear[] = {0,-4.65674,-0.80201}; + }; + class All; class AGM_IR_Strobe_Effect: All { scope = 1; diff --git a/AGM_Attach/functions/fn_attach.sqf b/AGM_Attach/functions/fn_attach.sqf index c82e4a2d2..fadfdd56a 100644 --- a/AGM_Attach/functions/fn_attach.sqf +++ b/AGM_Attach/functions/fn_attach.sqf @@ -4,49 +4,56 @@ Author: eRazeri and CAA-Picard Attach an item to the unit Arguments: -0: unit -1: Item name + 0: OBJECT - unit doing the attaching (player) + 1: OBJECT - vehicle that it will be attached to (player or vehicle) + 2: STRING - placement point name (self, right, left, back) + 3: STRING - classname of attached item (from CfgMagazines or CfgWeapons) Return Value: -none + none */ - -private ["_unit", "_itemName", "_attachedItem"]; +private ["_unit", "_attachToVehicle", "_attachToPointName", "_itemName", "_attachPosition", "_attachedItem"]; _unit = _this select 0; -_itemName = _this select 1; +_attachToVehicle = _this select 1; +_attachToPointName = _this select 2; +_itemName = _this select 3; // Check if unit has an attached item -if (_unit getVariable ["AGM_AttachedItemName", ""] != "") exitWith {}; +if (_attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""] != "") exitWith {}; // Check if the unit still has the item if !((_itemName in items _unit) or (_itemName in magazines _unit)) exitWith {}; +_attachPosition = if (_unit == _attachToVehicle) then { + [_unit, [-0.05,0,0.12], "rightshoulder"]; +} else { + [_attachToVehicle, ([_attachToVehicle, _attachToPointName] call AGM_Attach_fnc_vehicleGetAttachPoint)]; +}; + +_attachedItem = objNull; + // Attach item switch true do { - case (_itemName == "AGM_IR_Strobe_Item") : { + case (_itemName == "AGM_IR_Strobe_Item"): { _attachedItem = "AGM_IR_Strobe_Effect" createVehicle [0,0,0]; - _attachedItem attachTo [_unit,[0,-0.11,0.16],"pilot"];//makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri + if (_unit == _attachToVehicle) then {_attachPosition = [_unit,[0,-0.11,0.16],"pilot"];}; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri [localize "STR_AGM_Attach_IrStrobe_Attached"] call AGM_Core_fnc_displayTextStructured; }; - case (_itemName == "B_IR_Grenade") : { + case (_itemName == "B_IR_Grenade"): { _attachedItem = "B_IRStrobe" createVehicle [0,0,0]; - _attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"]; [localize "STR_AGM_Attach_IrGrenade_Attached"] call AGM_Core_fnc_displayTextStructured; }; - case (_itemName == "O_IR_Grenade") : { + case (_itemName == "O_IR_Grenade"): { _attachedItem = "O_IRStrobe" createVehicle [0,0,0]; - _attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"]; [localize "STR_AGM_Attach_IrGrenade_Attached"] call AGM_Core_fnc_displayTextStructured; }; - case (_itemName == "I_IR_Grenade") : { + case (_itemName == "I_IR_Grenade"): { _attachedItem = "I_IRStrobe" createVehicle [0,0,0]; - _attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"]; [localize "STR_AGM_Attach_IrGrenade_Attached"] call AGM_Core_fnc_displayTextStructured; }; - case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : { + case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): { _attachedItem = _itemName createVehicle [0,0,0]; - _attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"]; [localize "STR_AGM_Attach_Chemlight_Attached"] call AGM_Core_fnc_displayTextStructured; }; default { @@ -54,7 +61,12 @@ switch true do { }; }; +if (isNull _attachedItem) exitWith {["AGM_Attach_fnc_attach - could not createVehicle from Item [%1]", _itemName] call bis_fnc_error;}; + +_attachedItem attachTo _attachPosition; + // Remove item _unit removeItem _itemName; -_unit setVariable ["AGM_AttachedItemName", _itemName, true]; -_unit setVariable ["AGM_AttachedItem", _attachedItem, true]; + +_attachToVehicle setVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), _itemName, true]; +_attachToVehicle setVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), _attachedItem, true]; diff --git a/AGM_Attach/functions/fn_canAttach.sqf b/AGM_Attach/functions/fn_canAttach.sqf index 0401f9d21..f3702f5ac 100644 --- a/AGM_Attach/functions/fn_canAttach.sqf +++ b/AGM_Attach/functions/fn_canAttach.sqf @@ -16,4 +16,4 @@ private ["_unit", "_item"]; _unit = _this select 0; _item = _this select 1; -canStand _unit && {_unit getVariable ["AGM_AttachedItemName", ""] == ""} && {_item in (magazines _unit + items _unit + [""])} +canStand _unit && {_unit getVariable ["AGM_AttachedItemName_self", ""] == ""} && {_item in (magazines _unit + items _unit + [""])} diff --git a/AGM_Attach/functions/fn_canDetach.sqf b/AGM_Attach/functions/fn_canDetach.sqf index fcda3cbdd..a588fe2e2 100644 --- a/AGM_Attach/functions/fn_canDetach.sqf +++ b/AGM_Attach/functions/fn_canDetach.sqf @@ -14,4 +14,4 @@ private "_unit"; _unit = _this select 0; -canStand _unit && {_unit getVariable ["AGM_AttachedItemName", ""] != ""} +canStand _unit && {_unit getVariable ["AGM_AttachedItemName_self", ""] != ""} diff --git a/AGM_Attach/functions/fn_detach.sqf b/AGM_Attach/functions/fn_detach.sqf index f84bb163c..8b1ff9c1d 100644 --- a/AGM_Attach/functions/fn_detach.sqf +++ b/AGM_Attach/functions/fn_detach.sqf @@ -4,16 +4,20 @@ Author: eRazeri and CAA-Picard Detach an item from a unit Arguments: -unit + 0: OBJECT - unit doing the attaching (player) + 1: OBJECT - vehicle that it will be attached to (player or vehicle) + 2: STRING - placement point name (self, right, left, back) Return Value: -none + none */ - -private ["_unit", "_itemName", "_count", "_attachedItem"]; +private ["_unit", "_attachToVehicle", "_attachToPointName", "_itemName", "_count", "_attachedItem"]; _unit = _this select 0; -_itemName = _unit getVariable ["AGM_AttachedItemName", ""]; +_attachToVehicle = _this select 1; +_attachToPointName = _this select 2; + +_itemName = _attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""]; // Check if unit has an attached item if (_itemName == "") exitWith {}; @@ -27,7 +31,7 @@ if ((count items _unit) + (count magazines _unit) <= _count) exitWith { if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") then { // Hack for dealing with X_IR_Grenade effect not dissapearing on deleteVehicle - [_unit getVariable "AGM_AttachedItem", _unit] spawn { + [(_attachToVehicle getVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), objNull]), _unit] spawn { _attachedItem = _this select 0; _unit = _this select 1; detach _attachedItem; @@ -39,12 +43,12 @@ if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == " else { // Delete attached item - deleteVehicle (_unit getVariable "AGM_AttachedItem"); + deleteVehicle (_attachToVehicle getVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), objNull]); }; // Reset unit variables -_unit setVariable ["AGM_AttachedItemName","", true]; -_unit setVariable ["AGM_AttachedItem",nil, true]; +_attachToVehicle setVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), "", true]; +_attachToVehicle setVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), nil, true]; // Display message switch true do { diff --git a/AGM_Attach/functions/fn_openAttachUI.sqf b/AGM_Attach/functions/fn_openAttachUI.sqf index 2a1f0cf78..ba593c2fc 100644 --- a/AGM_Attach/functions/fn_openAttachUI.sqf +++ b/AGM_Attach/functions/fn_openAttachUI.sqf @@ -13,10 +13,14 @@ Nothing Example: - [player] call AGM_Attach_fnc_openAttachUI; + [player, player, "self"] call AGM_Attach_fnc_openAttachUI; */ -private ["_unit", "_actions", "_attachables", "_item"]; +private ["_unit", "_attachToVehicle", "_attachToPointName", "_listed", "_attachables", "_actions", "_item"]; + _unit = _this select 0; +_attachToVehicle = _this select 1; +_attachToPointName = _this select 2; + _listed = []; _attachables = magazines _unit; _actions = [localize "STR_AGM_Attach_AttachDetach", localize "STR_AGM_Attach_Attach"] call AGM_Interaction_fnc_prepareSelectMenu; @@ -25,10 +29,10 @@ _actions = [localize "STR_AGM_Attach_AttachDetach", localize "STR_AGM_Attach_Att _item = ConfigFile >> "CfgMagazines" >> _x; if (getNumber (_item >> "AGM_Attachable") == 1) then { _actions = [ - _actions, - getText(_item >> "displayName"), - getText(_item >> "picture"), - _x + _actions, + getText(_item >> "displayName"), + getText(_item >> "picture"), + _x ] call AGM_Interaction_fnc_AddSelectableItem; }; _listed pushBack _x; @@ -40,10 +44,10 @@ _attachables = items _unit; _item = ConfigFile >> "CfgWeapons" >> _x; if (getNumber (_item >> "AGM_Attachable") == 1) then { _actions = [ - _actions, - getText(_item >> "displayName"), - getText(_item >> "picture"), - _x + _actions, + getText(_item >> "displayName"), + getText(_item >> "picture"), + _x ] call AGM_Interaction_fnc_AddSelectableItem; }; _listed pushBack _x; @@ -51,13 +55,13 @@ _attachables = items _unit; } forEach _attachables; [ - _actions, - { - [AGM_player, _this] call AGM_Attach_fnc_attach; - call AGM_Interaction_fnc_hideMenu; - }, - { - call AGM_Interaction_fnc_hideMenu; - if !(profileNamespace getVariable ["AGM_Interaction_AutoCloseMenu", false]) then {"Default" call AGM_Interaction_fnc_openMenuSelf}; - } +_actions, +compile format [" + [AGM_player, AGM_Interaction_Target, '%1', _this] call AGM_Attach_fnc_attach; + call AGM_Interaction_fnc_hideMenu; + ", _attachToPointName], //ugh, compile +{ + call AGM_Interaction_fnc_hideMenu; + if !(profileNamespace getVariable ["AGM_Interaction_AutoCloseMenu", false]) then {"Default" call AGM_Interaction_fnc_openMenuSelf}; +} ] call AGM_Interaction_fnc_openSelectMenu; diff --git a/AGM_Attach/functions/fn_vehicleCanAttach.sqf b/AGM_Attach/functions/fn_vehicleCanAttach.sqf new file mode 100644 index 000000000..8b9377f37 --- /dev/null +++ b/AGM_Attach/functions/fn_vehicleCanAttach.sqf @@ -0,0 +1,35 @@ +/* +Name: AGM_Attach_fnc_vehicleCanAttach + +Author: Pabst Mirror + +Description: + Tests if the unit can attach to the vehicle at the given point + +Parameters: + 0: OBJECT - unit doing the attaching (usualy the player) + 1: OBJECT - vehicle that it will be attached to (player or vehicle) + 2: STRING - placement point name (self, right, left, back) + +Returns: + BOOL + +Example: + [player, tank, "rear"] call AGM_Attach_fnc_vehicleCanAttach +*/ +private ["_unit", "_attachToVehicle", "_attachToPointName", "_modelPosition", "_worldPos", "_unitPos", "_2dDistance"]; + +_unit = _this select 0; +_attachToVehicle = _this select 1; +_attachToPointName = _this select 2; + +_modelPosition = [_attachToVehicle, _attachToPointName] call AGM_Attach_fnc_vehicleGetAttachPoint; +_worldPos = _attachToVehicle modelToWorld _modelPosition; +_unitPos = getPos _unit; + +//Just look at the "2d" distance +_worldPos set [2, 0]; +_unitPos set [2, 0]; +_2dDistance = _worldPos distance _unitPos; + +canStand _unit && {alive _attachToVehicle} && {_attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""] == ""} && {_2dDistance < 2.3} diff --git a/AGM_Attach/functions/fn_vehicleCanDetach.sqf b/AGM_Attach/functions/fn_vehicleCanDetach.sqf new file mode 100644 index 000000000..2aeba72ac --- /dev/null +++ b/AGM_Attach/functions/fn_vehicleCanDetach.sqf @@ -0,0 +1,35 @@ +/* +Name: AGM_Attach_fnc_vehicleCanDetach + +Author: Pabst Mirror + +Description: + Tests if the unit can detach from the vehicle at the given point + +Parameters: + 0: OBJECT - unit doing the attaching (usualy the player) + 1: OBJECT - vehicle that it will be attached to (player or vehicle) + 2: STRING - placement point name (self, right, left, back) + +Returns: + BOOL + +Example: + [player, tank, "rear"] call AGM_Attach_fnc_vehicleCanDetach +*/ +private ["_unit", "_attachToVehicle", "_attachToPointName", "_modelPosition", "_worldPos", "_unitPos", "_2dDistance"]; + +_unit = _this select 0; +_attachToVehicle = _this select 1; +_attachToPointName = _this select 2; + +_modelPosition = [_attachToVehicle, _attachToPointName] call AGM_Attach_fnc_vehicleGetAttachPoint; +_worldPos = _attachToVehicle modelToWorld _modelPosition; +_unitPos = getPos _unit; + +//Just look at the "2d" distance +_worldPos set [2, 0]; +_unitPos set [2, 0]; +_2dDistance = _worldPos distance _unitPos; + +canStand _unit && {alive _attachToVehicle} && {_attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""] != ""} && {_2dDistance < 2.3} diff --git a/AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf b/AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf new file mode 100644 index 000000000..ceff86f2f --- /dev/null +++ b/AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf @@ -0,0 +1,71 @@ +/* +Name: AGM_Attach_fnc_vehicleGetAttachPoint + +Author: Pabst Mirror + +Description: + Gets a attach point for a vehicle (in model space cords). Will check the config for AGM_AttachPoint_X first. + Otherwise it finds a solution using lineIntersectsWith. + +Parameters: + 0: OBJECT - vehicle + 1: STRING - placement point name (right, left, back) + +Returns: + Nothing + +Example: +called from module +*/ +private ["_vehicle", "_attachPointLocation", "_config", "_returnAttachPoint", "_bbox", "_driverPos", "_posX", "_minHeight", "_maxHeight", "_curHeight", "_position0", "_position1", "_posZ", "_minBack", "_maxBack", "_curBack"]; + +_vehicle = _this select 0; +_attachPointLocation = _this select 1; + +_config = configFile >> "CfgVehicles" >> (typeOf _vehicle); + +_returnAttachPoint = getArray (_config >> format ["AGM_AttachPoint_%1", _attachPointLocation]); +if ((count _returnAttachPoint) == 0) then { + //Find the location on the model using intersections + _bbox = boundingBoxReal _vehicle; + if (_attachPointLocation in ["left", "right"]) then { + _driverPos = _vehicle selectionPosition (getText (_config >> "memoryPointsGetInDriver")); + _posX = if (_attachPointLocation == "right") then { + 0.425 * (abs (_driverPos select 0)) + } else { + -0.425 * (abs (_driverPos select 0)) + }; + _minHeight = (_bbox select 0) select 2; + _maxHeight = (_bbox select 1) select 2; + _curHeight = _maxHeight; + _position0 = _vehicle modeltoWorld [_posX, (_driverPos select 1), (_maxHeight + 0.05)]; + + while {_curHeight > _minHeight} do { + _position1 = _vehicle modelToWorld [_posX, (_driverPos select 1), (_curHeight)]; + if (_vehicle in lineIntersectsWith [(ATLToASL _position0), (ATLToASL _position1), player]) exitWith {}; + _curHeight = _curHeight - 0.01; + }; + _curHeight = _curHeight + 0.025; + //Raise up a little so it's not sunk into the hull + //sometimes it's too much, but better then hidden + + _returnAttachPoint = [_posX, (_driverPos select 1), _curHeight]; + }; + + if (_attachPointLocation == "rear") then { + _posZ = ((_bbox select 0) select 2) + 0.75; + _minBack = (_bbox select 0) select 1; + _maxBack = (_bbox select 1) select 1; + _curBack = _minBack; + _position0 = _vehicle modeltoWorld [0, (_minBack - 0.05), _posZ]; + while {_curBack < _maxBack} do { + _position1 = _vehicle modelToWorld [0, _curBack, _posZ]; + if (_vehicle in lineIntersectsWith [(ATLToASL _position0), (ATLToASL _position1), player]) exitWith {}; + _curBack = _curBack + 0.01; + }; + _curBack = _curBack - 0.1; + _returnAttachPoint = [0, _curBack, _posZ]; + }; +}; + +_returnAttachPoint From fd6f4c1cb71daeb84bf1ff0d672c3926b7156e35 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 03:35:54 -0600 Subject: [PATCH 2/7] Cleanup, formating --- AGM_Attach/config.cpp | 6 +++--- AGM_Attach/functions/fn_attach.sqf | 3 ++- AGM_Attach/functions/fn_openAttachUI.sqf | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/AGM_Attach/config.cpp b/AGM_Attach/config.cpp index ab9428ebb..d5c0eb63c 100644 --- a/AGM_Attach/config.cpp +++ b/AGM_Attach/config.cpp @@ -29,9 +29,9 @@ class CfgFunctions { }; #define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \ - name = #ITEM; \ - count = COUNT; \ - }; + name = #ITEM; \ + count = COUNT; \ +}; #define MACRO_ATTACHTOVEHICLE \ class AGM_Actions { \ diff --git a/AGM_Attach/functions/fn_attach.sqf b/AGM_Attach/functions/fn_attach.sqf index fadfdd56a..22e90a101 100644 --- a/AGM_Attach/functions/fn_attach.sqf +++ b/AGM_Attach/functions/fn_attach.sqf @@ -33,7 +33,7 @@ _attachPosition = if (_unit == _attachToVehicle) then { _attachedItem = objNull; -// Attach item + switch true do { case (_itemName == "AGM_IR_Strobe_Item"): { _attachedItem = "AGM_IR_Strobe_Effect" createVehicle [0,0,0]; @@ -63,6 +63,7 @@ switch true do { if (isNull _attachedItem) exitWith {["AGM_Attach_fnc_attach - could not createVehicle from Item [%1]", _itemName] call bis_fnc_error;}; +// Attach item _attachedItem attachTo _attachPosition; // Remove item diff --git a/AGM_Attach/functions/fn_openAttachUI.sqf b/AGM_Attach/functions/fn_openAttachUI.sqf index ba593c2fc..245a29b39 100644 --- a/AGM_Attach/functions/fn_openAttachUI.sqf +++ b/AGM_Attach/functions/fn_openAttachUI.sqf @@ -59,7 +59,7 @@ _actions, compile format [" [AGM_player, AGM_Interaction_Target, '%1', _this] call AGM_Attach_fnc_attach; call AGM_Interaction_fnc_hideMenu; - ", _attachToPointName], //ugh, compile +", _attachToPointName], //ugh, compile { call AGM_Interaction_fnc_hideMenu; if !(profileNamespace getVariable ["AGM_Interaction_AutoCloseMenu", false]) then {"Default" call AGM_Interaction_fnc_openMenuSelf}; From ea1ded63c4b1c77b57d29ab11db9a59ec15d981a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 20:50:50 -0600 Subject: [PATCH 3/7] Attach To Vehicle - Rewrite Based partialy on AGM_explosive. Allows muliple points. --- AGM_Attach/config.cpp | 68 ++---------- AGM_Attach/functions/fn_Place_Approve.sqf | 88 +++++++++++++++ AGM_Attach/functions/fn_Place_Cancel.sqf | 37 +++++++ AGM_Attach/functions/fn_attach.sqf | 104 +++++++++++------- AGM_Attach/functions/fn_canAttach.sqf | 4 +- AGM_Attach/functions/fn_canDetach.sqf | 5 +- AGM_Attach/functions/fn_detach.sqf | 54 ++++++--- AGM_Attach/functions/fn_openAttachUI.sqf | 6 +- AGM_Attach/functions/fn_vehicleCanAttach.sqf | 19 +--- AGM_Attach/functions/fn_vehicleCanDetach.sqf | 31 +++--- .../functions/fn_vehicleGetAttachPoint.sqf | 71 ------------ AGM_Attach/stringtable.xml | 22 ++++ 12 files changed, 284 insertions(+), 225 deletions(-) create mode 100644 AGM_Attach/functions/fn_Place_Approve.sqf create mode 100644 AGM_Attach/functions/fn_Place_Cancel.sqf delete mode 100644 AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf diff --git a/AGM_Attach/config.cpp b/AGM_Attach/config.cpp index d5c0eb63c..13a8c26d9 100644 --- a/AGM_Attach/config.cpp +++ b/AGM_Attach/config.cpp @@ -21,9 +21,10 @@ class CfgFunctions { class canDetach; class detach; class openAttachUI; + class Place_Approve; + class Place_Cancel; class vehicleCanAttach; class vehicleCanDetach; - class vehicleGetAttachPoint; }; }; }; @@ -37,8 +38,8 @@ class CfgFunctions { class AGM_Actions { \ class AGM_Attach_right { \ displayName = "$STR_AGM_Attach_AttachDetach"; \ - condition = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_vehicleCanAttach"; \ - statement = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_openAttachUI;"; \ + condition = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_vehicleCanAttach"; \ + statement = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_openAttachUI;"; \ exceptions[] = {"AGM_Drag_isNotDragging"}; \ showDisabled = 0; \ priority = 0; \ @@ -47,48 +48,8 @@ class CfgFunctions { }; \ class AGM_Attach_Detach_right { \ displayName = "$STR_AGM_Attach_Detach"; \ - condition = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_vehicleCanDetach"; \ - statement = "[_player, AGM_Interaction_Target, 'right'] call AGM_Attach_fnc_detach"; \ - exceptions[] = {"AGM_Drag_isNotDragging"}; \ - showDisabled = 0; \ - priority = 0; \ - icon = "\AGM_Attach\UI\detach_ca.paa"; \ - hotkey = "T"; \ - }; \ - class AGM_Attach_left { \ - displayName = "$STR_AGM_Attach_AttachDetach"; \ - condition = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_vehicleCanAttach"; \ - statement = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_openAttachUI;"; \ - exceptions[] = {"AGM_Drag_isNotDragging"}; \ - showDisabled = 0; \ - priority = 0; \ - icon = "\AGM_Attach\UI\attach_ca.paa"; \ - hotkey = "T"; \ - }; \ - class AGM_Attach_Detach_left { \ - displayName = "$STR_AGM_Attach_Detach"; \ - condition = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_vehicleCanDetach"; \ - statement = "[_player, AGM_Interaction_Target, 'left'] call AGM_Attach_fnc_detach"; \ - exceptions[] = {"AGM_Drag_isNotDragging"}; \ - showDisabled = 0; \ - priority = 0; \ - icon = "\AGM_Attach\UI\detach_ca.paa"; \ - hotkey = "T"; \ - }; \ - class AGM_Attach_rear { \ - displayName = "$STR_AGM_Attach_AttachDetach"; \ - condition = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_vehicleCanAttach"; \ - statement = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_openAttachUI;"; \ - exceptions[] = {"AGM_Drag_isNotDragging"}; \ - showDisabled = 0; \ - priority = 0; \ - icon = "\AGM_Attach\UI\attach_ca.paa"; \ - hotkey = "T"; \ - }; \ - class AGM_Attach_Detach_rear { \ - displayName = "$STR_AGM_Attach_Detach"; \ - condition = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_vehicleCanDetach"; \ - statement = "[_player, AGM_Interaction_Target, 'rear'] call AGM_Attach_fnc_detach"; \ + condition = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_vehicleCanDetach"; \ + statement = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_detach"; \ exceptions[] = {"AGM_Drag_isNotDragging"}; \ showDisabled = 0; \ priority = 0; \ @@ -105,7 +66,7 @@ class CfgVehicles { class AGM_Attach { displayName = "$STR_AGM_Attach_AttachDetach"; condition = "[_player, ''] call AGM_Attach_fnc_canAttach"; - statement = "[_player, _player, 'self'] call AGM_Attach_fnc_openAttachUI;"; + statement = "[_player, _player] call AGM_Attach_fnc_openAttachUI;"; exceptions[] = {"AGM_Drag_isNotDragging"}; showDisabled = 0; priority = 5; @@ -115,7 +76,7 @@ class CfgVehicles { class AGM_Attach_Detach { displayName = "$STR_AGM_Attach_Detach"; condition = "[_player] call AGM_Attach_fnc_canDetach"; - statement = "[_player, _player, 'self'] call AGM_Attach_fnc_detach"; + statement = "[_player, _player] call AGM_Attach_fnc_detach"; exceptions[] = {"AGM_Drag_isNotDragging"}; showDisabled = 0; priority = 5; @@ -145,19 +106,6 @@ class CfgVehicles { MACRO_ATTACHTOVEHICLE }; - class Car_F: Car {}; - class Hatchback_01_base_F: Car_F { - AGM_AttachPoint_left[] = {-0.929688,0.789063,-0.23848}; - AGM_AttachPoint_right[] = {0.741211,0.85791,-0.224247}; - AGM_AttachPoint_rear[] = {0,-2.095,0.182854}; - }; - class Truck_F: Car_F {}; - class Truck_03_base_F: Truck_F { - AGM_AttachPoint_left[] = {-1.16321,3.62256,0.0160751}; - AGM_AttachPoint_right[] = {1.28906,3.63965,-0.033287}; - AGM_AttachPoint_rear[] = {0,-4.65674,-0.80201}; - }; - class All; class AGM_IR_Strobe_Effect: All { scope = 1; diff --git a/AGM_Attach/functions/fn_Place_Approve.sqf b/AGM_Attach/functions/fn_Place_Approve.sqf new file mode 100644 index 000000000..76d1b5d15 --- /dev/null +++ b/AGM_Attach/functions/fn_Place_Approve.sqf @@ -0,0 +1,88 @@ +/* + Name: AGM_Attach_fnc_Place_Approve + + Author(s): + Pabst Mirror (based on Explosive attach by Garth de Wet (LH)) + + Description: + Approves placement of the lightObject, releases the placement object for it to settle in a location + + Parameters: + Nothing + + Returns: + Nothing + + Example: + call AGM_Attach_fnc_Place_Approve; +*/ +if (AGM_Attach_pfeh_running) then { + ["AGM_Attach_Placement","OnEachFrame"] call BIS_fnc_removeStackedEventHandler; + AGM_Attach_pfeh_running = false; +}; + +_setupObject = AGM_Attach_SetupObject; +_setupClassname = typeOf _setupObject; +_itemClassname = AGM_Attach_SetupPlacmentItem; +_placementText = AGM_Attach_SetupPlacmentText; +_attachToVehicle = AGM_Attach_SetupAttachVehicle; + +AGM_Attach_SetupPlacmentItem = ""; +AGM_Attach_SetupPlacmentText = ""; +AGM_Attach_SetupObject = objNull; +AGM_Attach_SetupAttachVehicle = objNull; +AGM_Attach_placer forceWalk false; +AGM_Attach_placer = objNull; + +_player = AGM_player; +[_player, "DefaultAction", _player getVariable ["AGM_Attach_Place", -1]] call AGM_Core_fnc_removeActionEventHandler; +[_player, "MenuBack", _player getVariable ["AGM_Attach_Cancel", -1]] call AGM_Core_fnc_removeActionEventHandler; +call AGM_Interaction_fnc_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. + +_position0 = getPosAtl _setupObject; +_closeInRatio = 1; +_offset = _attachToVehicle worldToModel _position0; +_keepGoingCloser = true; +while {_keepGoingCloser} do { + _closeInRatio = _closeInRatio - 0.004; + if (_closeInRatio <= 0) exitWith {}; + { + _pos0temp = _position0 vectorAdd _x; + { + _position1 = [(_offset select 0) * _closeInRatio, (_offset select 1) * _closeInRatio, (_offset select 2)]; + _position1 = _attachToVehicle modelToWorld _position1; + _position1 = _position1 vectorAdd _x; + //Uncomment to see the lazor show, and see how the scanning works: + // drawLine3D [_pos0temp, _position1, [1,0,0,1]]; + if (_attachToVehicle in lineIntersectsWith [(ATLToASL _pos0temp), (ATLToASL _position1), player, _setupObject]) exitWith {_keepGoingCloser = false}; + } forEach [[0,0,0], [0,0,0.075], [0,0,-0.075], [0,0.075,0], [0,-0.075,0], [0.075,0,0], [-.075,0,0]]; + } forEach [[0,0,0], [0,0,0.075], [0,0,-0.075]]; +}; +//Move it out slightly, for visability sake (better to look a little funny than be embedded//sunk in the hull) +_closeInRatio = (_closeInRatio + 0.006) min 1; + +//Delete Local Placement Object +deleteVehicle _setupObject; + +//Create New 'real' Object +_attachedObject = _setupClassname createVehicle (getPos _player); +_attachedObject attachTo [_attachToVehicle, [(_offset select 0) * _closeInRatio, (_offset select 1) * _closeInRatio, (_offset select 2)]]; + +//Remove Item from inventory +_player removeItem _itemClassname; + +//Add Object to AGM_AttachedObjects and AGM_AttachedItemNames +_currentObjects = _attachToVehicle getVariable ["AGM_AttachedObjects", []]; +_currentObjects pushBack _attachedObject; +_attachToVehicle setVariable ["AGM_AttachedObjects", _currentObjects, true]; +_currentItemNames = _attachToVehicle getVariable ["AGM_AttachedItemNames", []]; +_currentItemNames pushBack _itemClassname; +_attachToVehicle setVariable ["AGM_AttachedItemNames", _currentItemNames, true]; + +[_placementText] call AGM_Core_fnc_displayTextStructured; diff --git a/AGM_Attach/functions/fn_Place_Cancel.sqf b/AGM_Attach/functions/fn_Place_Cancel.sqf new file mode 100644 index 000000000..4b6ac3613 --- /dev/null +++ b/AGM_Attach/functions/fn_Place_Cancel.sqf @@ -0,0 +1,37 @@ +/* + Name: AGM_Attach_fnc_Place_Cancel + + Author(s): + Pabst Mirror (based on Explosive attach by Garth de Wet (LH)) + + Description: + Cancels placement of the lightObject + + Parameters: + Nothing + + Returns: + Nothing + + Example: + call AGM_Attach_fnc_Place_Cancel; +*/ +if (AGM_Attach_pfeh_running) then { + ["AGM_Attach_Placement","OnEachFrame"] call BIS_fnc_removeStackedEventHandler; + AGM_Attach_pfeh_running = false; +}; +if (!isNull (AGM_Attach_SetupObject)) then { + deleteVehicle AGM_Attach_SetupObject; +}; +AGM_Attach_SetupPlacmentItem = ""; +AGM_Attach_SetupPlacmentText = ""; +AGM_Attach_SetupObject = objNull; +AGM_Attach_SetupAttachVehicle = objNull; +if (isNil {AGM_Attach_placer}) then { + AGM_Attach_placer = objNull; +}; +AGM_Attach_placer forceWalk false; +AGM_Attach_placer = objNull; +call AGM_Interaction_fnc_hideMouseHint; +[AGM_player, "DefaultAction", AGM_player getVariable ["AGM_Attach_Place", -1]] call AGM_Core_fnc_removeActionEventHandler; +[AGM_player, "MenuBack", AGM_player getVariable ["AGM_Attach_Cancel", -1]] call AGM_Core_fnc_removeActionEventHandler; diff --git a/AGM_Attach/functions/fn_attach.sqf b/AGM_Attach/functions/fn_attach.sqf index 22e90a101..4b31f4870 100644 --- a/AGM_Attach/functions/fn_attach.sqf +++ b/AGM_Attach/functions/fn_attach.sqf @@ -1,73 +1,95 @@ /* +Name: AGM_Attach_fnc_attach + Author: eRazeri and CAA-Picard -Attach an item to the unit +Attach an item to the unit. For vehicles, it starts the custom placement) Arguments: - 0: OBJECT - unit doing the attaching (player) - 1: OBJECT - vehicle that it will be attached to (player or vehicle) - 2: STRING - placement point name (self, right, left, back) - 3: STRING - classname of attached item (from CfgMagazines or CfgWeapons) +0: OBJECT - unit doing the attaching (player) +1: OBJECT - vehicle that it will be attached to (player or vehicle) +2: STRING - classname of attached item (from CfgMagazines or CfgWeapons) Return Value: - none +none */ private ["_unit", "_attachToVehicle", "_attachToPointName", "_itemName", "_attachPosition", "_attachedItem"]; _unit = _this select 0; _attachToVehicle = _this select 1; -_attachToPointName = _this select 2; -_itemName = _this select 3; +_itemName = _this select 2; -// Check if unit has an attached item -if (_attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""] != "") exitWith {}; +// For Self Placement - Check if unit has an attached item +if (_unit == _attachToVehicle) then { + if ((count (_attachToVehicle getVariable ["AGM_AttachedObjects", []])) > 0) exitWith {}; +}; // Check if the unit still has the item if !((_itemName in items _unit) or (_itemName in magazines _unit)) exitWith {}; -_attachPosition = if (_unit == _attachToVehicle) then { - [_unit, [-0.05,0,0.12], "rightshoulder"]; -} else { - [_attachToVehicle, ([_attachToVehicle, _attachToPointName] call AGM_Attach_fnc_vehicleGetAttachPoint)]; -}; - -_attachedItem = objNull; - +_selfAttachPosition = [_unit, [-0.05,0,0.12], "rightshoulder"]; +_itemVehClass = ""; +_onAtachText = ""; switch true do { - case (_itemName == "AGM_IR_Strobe_Item"): { - _attachedItem = "AGM_IR_Strobe_Effect" createVehicle [0,0,0]; - if (_unit == _attachToVehicle) then {_attachPosition = [_unit,[0,-0.11,0.16],"pilot"];}; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri - [localize "STR_AGM_Attach_IrStrobe_Attached"] call AGM_Core_fnc_displayTextStructured; +case (_itemName == "AGM_IR_Strobe_Item"): { + _itemVehClass = "AGM_IR_Strobe_Effect"; + _onAtachText = localize "STR_AGM_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"): { - _attachedItem = "B_IRStrobe" createVehicle [0,0,0]; - [localize "STR_AGM_Attach_IrGrenade_Attached"] call AGM_Core_fnc_displayTextStructured; +case (_itemName == "B_IR_Grenade"): { + _itemVehClass = "B_IRStrobe"; + _onAtachText = localize "STR_AGM_Attach_IrGrenade_Attached"; }; - case (_itemName == "O_IR_Grenade"): { - _attachedItem = "O_IRStrobe" createVehicle [0,0,0]; - [localize "STR_AGM_Attach_IrGrenade_Attached"] call AGM_Core_fnc_displayTextStructured; +case (_itemName == "O_IR_Grenade"): { + _itemVehClass = "O_IRStrobe"; + _onAtachText = localize "STR_AGM_Attach_IrGrenade_Attached"; }; - case (_itemName == "I_IR_Grenade"): { - _attachedItem = "I_IRStrobe" createVehicle [0,0,0]; - [localize "STR_AGM_Attach_IrGrenade_Attached"] call AGM_Core_fnc_displayTextStructured; +case (_itemName == "I_IR_Grenade"): { + _itemVehClass = "I_IRStrobe"; + _onAtachText = localize "STR_AGM_Attach_IrGrenade_Attached"; }; - case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): { - _attachedItem = _itemName createVehicle [0,0,0]; - [localize "STR_AGM_Attach_Chemlight_Attached"] call AGM_Core_fnc_displayTextStructured; +case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): { + _itemVehClass = _itemName; + _onAtachText = localize "STR_AGM_Attach_Chemlight_Attached"; }; default { if (true) exitWith {}; }; }; -if (isNull _attachedItem) exitWith {["AGM_Attach_fnc_attach - could not createVehicle from Item [%1]", _itemName] call bis_fnc_error;}; +if (_itemVehClass == "") exitWith {["AGM_Attach_fnc_attach - no _itemVehClass for Item [%1]", _itemName] call bis_fnc_error;}; -// Attach item -_attachedItem attachTo _attachPosition; +if (_unit == _attachToVehicle) then { //Self Attachment + _unit removeItem _itemName; // Remove item + _attachedItem = _itemVehClass createVehicle [0,0,0]; + _attachedItem attachTo _selfAttachPosition; + [_onAtachText] call AGM_Core_fnc_displayTextStructured; + _attachToVehicle setVariable ["AGM_AttachedObjects", [_attachedItem], true]; + _attachToVehicle setVariable ["AGM_AttachedItemNames", [_itemName], true]; +} else { + AGM_Attach_SetupObject = _itemVehClass createVehicleLocal [0,0,-10000]; + AGM_Attach_SetupObject enableSimulationGlobal false; + AGM_Attach_SetupPlacmentText = _onAtachText; + AGM_Attach_SetupPlacmentItem = _itemName; + AGM_Attach_SetupAttachVehicle = _attachToVehicle; + AGM_Attach_placer = _unit; + _unit forceWalk true; -// Remove item -_unit removeItem _itemName; + ["AGM_Attach_Placement","OnEachFrame", { + private "_player"; + _player = AGM_player; + //Stop if player switch or player gets to far from vehicle + if ((AGM_Attach_placer != _player) || ((_player distance AGM_Attach_SetupAttachVehicle) > 9)) exitWith { + call AGM_Attach_fnc_Place_Cancel; + }; + AGM_Attach_pfeh_running = true; + _pos = (ASLtoATL eyePos _player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]); + AGM_Attach_SetupObject setPosATL _pos; + }] call BIS_fnc_addStackedEventHandler; -_attachToVehicle setVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), _itemName, true]; -_attachToVehicle setVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), _attachedItem, true]; + //had to spawn the mouseHint, not sure why + [localize "STR_AGM_Attach_PlaceAction", localize "STR_AGM_Attach_CancelAction"] spawn AGM_Interaction_fnc_showMouseHint; + _unit setVariable ["AGM_Attach_Place", [_unit, "DefaultAction", {AGM_Attach_pfeh_running AND !isNull (AGM_Attach_SetupObject)}, {call AGM_Attach_fnc_Place_Approve;}] call AGM_Core_fnc_AddActionEventHandler]; + _unit setVariable ["AGM_Attach_Cancel", [_unit, "MenuBack", {AGM_Attach_pfeh_running AND !isNull (AGM_Attach_SetupObject)}, {call AGM_Attach_fnc_Place_Cancel;}] call AGM_Core_fnc_AddActionEventHandler]; +}; diff --git a/AGM_Attach/functions/fn_canAttach.sqf b/AGM_Attach/functions/fn_canAttach.sqf index f3702f5ac..0b3be9454 100644 --- a/AGM_Attach/functions/fn_canAttach.sqf +++ b/AGM_Attach/functions/fn_canAttach.sqf @@ -1,7 +1,7 @@ /* * Author: commy2 * - * Check if a unit can attach a specific item. + * Check if a unit can attach a specific item to themselves. * * Argument: * 0: Unit that wants to attach the object (Object) @@ -16,4 +16,4 @@ private ["_unit", "_item"]; _unit = _this select 0; _item = _this select 1; -canStand _unit && {_unit getVariable ["AGM_AttachedItemName_self", ""] == ""} && {_item in (magazines _unit + items _unit + [""])} +canStand _unit && {(count (_unit getVariable ["AGM_AttachedObjects", []])) == 0} && {_item in (magazines _unit + items _unit + [""])} diff --git a/AGM_Attach/functions/fn_canDetach.sqf b/AGM_Attach/functions/fn_canDetach.sqf index a588fe2e2..5f87aa677 100644 --- a/AGM_Attach/functions/fn_canDetach.sqf +++ b/AGM_Attach/functions/fn_canDetach.sqf @@ -1,4 +1,5 @@ -/* +/* AGM_Attach_fnc_canDetach + * * Author: commy2 * * Check if a unit has an item attached and if it can remove that item. @@ -14,4 +15,4 @@ private "_unit"; _unit = _this select 0; -canStand _unit && {_unit getVariable ["AGM_AttachedItemName_self", ""] != ""} +canStand _unit && {(count (_unit getVariable ["AGM_AttachedObjects", []])) != 0} diff --git a/AGM_Attach/functions/fn_detach.sqf b/AGM_Attach/functions/fn_detach.sqf index 8b1ff9c1d..96e15fcae 100644 --- a/AGM_Attach/functions/fn_detach.sqf +++ b/AGM_Attach/functions/fn_detach.sqf @@ -1,4 +1,6 @@ /* +Name: AGM_Attach_fnc_detach + Author: eRazeri and CAA-Picard Detach an item from a unit @@ -6,7 +8,6 @@ Detach an item from a unit Arguments: 0: OBJECT - unit doing the attaching (player) 1: OBJECT - vehicle that it will be attached to (player or vehicle) - 2: STRING - placement point name (self, right, left, back) Return Value: none @@ -15,12 +16,29 @@ private ["_unit", "_attachToVehicle", "_attachToPointName", "_itemName", "_count _unit = _this select 0; _attachToVehicle = _this select 1; -_attachToPointName = _this select 2; -_itemName = _attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""]; +_attachedObjectsArray = _attachToVehicle getVariable ["AGM_AttachedObjects", []]; +_attachedItemsArray = _attachToVehicle getVariable ["AGM_AttachedItemNames", []]; +_attachedObject = objNull; +_itemName = ""; + +//Find closest attached object +_minDistance = 1000; +_unitPos = getPos _unit; +_unitPos set [2,0]; +{ + _objectPos = getPos _x; + _objectPos set [2, 0]; + if ((_objectPos distance _unitPos) < _minDistance) then { + _minDistance = (_objectPos distance _unitPos); + _attachedObject = _x; + _itemName = _attachedItemsArray select _forEachIndex; + }; +} forEach _attachedObjectsArray; -// Check if unit has an attached item -if (_itemName == "") exitWith {}; +//Error Checking +if (isNull _attachedObject) exitWith {["AGM_Attach_fnc_detach - null _attachedObject [%1]", _this] call bis_fnc_error;}; +if (_itemName == "") exitWith {["AGM_Attach_fnc_detach - _itemName is empty"] call bis_fnc_error;}; // Add item to inventory _count = (count items _unit) + (count magazines _unit); @@ -31,7 +49,7 @@ if ((count items _unit) + (count magazines _unit) <= _count) exitWith { if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") then { // Hack for dealing with X_IR_Grenade effect not dissapearing on deleteVehicle - [(_attachToVehicle getVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), objNull]), _unit] spawn { + [_attachedObject, _unit] spawn { _attachedItem = _this select 0; _unit = _this select 1; detach _attachedItem; @@ -39,26 +57,30 @@ if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == " sleep 0.5; deleteVehicle _attachedItem; }; -} -else -{ +} else { // Delete attached item - deleteVehicle (_attachToVehicle getVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), objNull]); + deleteVehicle _attachedObject; }; -// Reset unit variables -_attachToVehicle setVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), "", true]; -_attachToVehicle setVariable [(format ["AGM_AttachedItem_%1", _attachToPointName]), nil, true]; +// Remove Deleted (null) entries +{ + if (isNull _x) then { + _attachedObjectsArray deleteAt _forEachIndex; + _attachedItemsArray deleteAt _forEachIndex; + }; +} forEach _attachedObjectsArray; +_attachToVehicle setVariable ["AGM_AttachedObjects", _attachedObjectsArray, true]; +_attachToVehicle setVariable ["AGM_AttachedItemNames", _attachedItemsArray, true]; // Display message switch true do { - case (_itemName == "AGM_IR_Strobe_Item") : { +case (_itemName == "AGM_IR_Strobe_Item") : { [localize "STR_AGM_Attach_IrStrobe_Detached"] call AGM_Core_fnc_displayTextStructured; }; - case (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") : { +case (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") : { [localize "STR_AGM_Attach_IrGrenade_Detached"] call AGM_Core_fnc_displayTextStructured; }; - case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : { +case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : { [localize "STR_AGM_Attach_Chemlight_Detached"] call AGM_Core_fnc_displayTextStructured; }; default { diff --git a/AGM_Attach/functions/fn_openAttachUI.sqf b/AGM_Attach/functions/fn_openAttachUI.sqf index 245a29b39..b2fd3cad1 100644 --- a/AGM_Attach/functions/fn_openAttachUI.sqf +++ b/AGM_Attach/functions/fn_openAttachUI.sqf @@ -56,10 +56,10 @@ _attachables = items _unit; [ _actions, -compile format [" - [AGM_player, AGM_Interaction_Target, '%1', _this] call AGM_Attach_fnc_attach; +{ + [AGM_player, AGM_Interaction_Target, _this] call AGM_Attach_fnc_attach; call AGM_Interaction_fnc_hideMenu; -", _attachToPointName], //ugh, compile +}, { call AGM_Interaction_fnc_hideMenu; if !(profileNamespace getVariable ["AGM_Interaction_AutoCloseMenu", false]) then {"Default" call AGM_Interaction_fnc_openMenuSelf}; diff --git a/AGM_Attach/functions/fn_vehicleCanAttach.sqf b/AGM_Attach/functions/fn_vehicleCanAttach.sqf index 8b9377f37..901ec98e1 100644 --- a/AGM_Attach/functions/fn_vehicleCanAttach.sqf +++ b/AGM_Attach/functions/fn_vehicleCanAttach.sqf @@ -4,32 +4,21 @@ Name: AGM_Attach_fnc_vehicleCanAttach Author: Pabst Mirror Description: - Tests if the unit can attach to the vehicle at the given point + Tests if the unit can attach to the vehicle Parameters: 0: OBJECT - unit doing the attaching (usualy the player) 1: OBJECT - vehicle that it will be attached to (player or vehicle) - 2: STRING - placement point name (self, right, left, back) Returns: BOOL Example: - [player, tank, "rear"] call AGM_Attach_fnc_vehicleCanAttach + [player, tank] call AGM_Attach_fnc_vehicleCanAttach */ -private ["_unit", "_attachToVehicle", "_attachToPointName", "_modelPosition", "_worldPos", "_unitPos", "_2dDistance"]; +private ["_unit", "_attachToVehicle"]; _unit = _this select 0; _attachToVehicle = _this select 1; -_attachToPointName = _this select 2; -_modelPosition = [_attachToVehicle, _attachToPointName] call AGM_Attach_fnc_vehicleGetAttachPoint; -_worldPos = _attachToVehicle modelToWorld _modelPosition; -_unitPos = getPos _unit; - -//Just look at the "2d" distance -_worldPos set [2, 0]; -_unitPos set [2, 0]; -_2dDistance = _worldPos distance _unitPos; - -canStand _unit && {alive _attachToVehicle} && {_attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""] == ""} && {_2dDistance < 2.3} +canStand _unit && {alive _attachToVehicle} diff --git a/AGM_Attach/functions/fn_vehicleCanDetach.sqf b/AGM_Attach/functions/fn_vehicleCanDetach.sqf index 2aeba72ac..14f9f773f 100644 --- a/AGM_Attach/functions/fn_vehicleCanDetach.sqf +++ b/AGM_Attach/functions/fn_vehicleCanDetach.sqf @@ -4,32 +4,33 @@ Name: AGM_Attach_fnc_vehicleCanDetach Author: Pabst Mirror Description: - Tests if the unit can detach from the vehicle at the given point + Tests if the unit can detach from the vehicle Parameters: - 0: OBJECT - unit doing the attaching (usualy the player) + 0: OBJECT - unit doing the detaching (usualy the player) 1: OBJECT - vehicle that it will be attached to (player or vehicle) - 2: STRING - placement point name (self, right, left, back) Returns: BOOL Example: - [player, tank, "rear"] call AGM_Attach_fnc_vehicleCanDetach + [player, tank] call AGM_Attach_fnc_vehicleCanDetach */ -private ["_unit", "_attachToVehicle", "_attachToPointName", "_modelPosition", "_worldPos", "_unitPos", "_2dDistance"]; +private ["_unit", "_attachToVehicle", "_attachToPointName", "_modelPosition", "_worldPos", "_unitPos", "_minDistance"]; _unit = _this select 0; _attachToVehicle = _this select 1; -_attachToPointName = _this select 2; -_modelPosition = [_attachToVehicle, _attachToPointName] call AGM_Attach_fnc_vehicleGetAttachPoint; -_worldPos = _attachToVehicle modelToWorld _modelPosition; -_unitPos = getPos _unit; - -//Just look at the "2d" distance -_worldPos set [2, 0]; -_unitPos set [2, 0]; -_2dDistance = _worldPos distance _unitPos; +_attachedObjects = _attachToVehicle getVariable ["AGM_AttachedObjects", []]; -canStand _unit && {alive _attachToVehicle} && {_attachToVehicle getVariable [(format ["AGM_AttachedItemName_%1", _attachToPointName]), ""] != ""} && {_2dDistance < 2.3} +//Scan if unit is within range (using 2d distance) +_unitPos = getPos _unit; +_unitPos set [2,0]; +_minDistance = 1000; +{ + _objectPos = getPos _x; + _objectPos set [2, 0]; + _minDistance = _minDistance min (_objectPos distance _unitPos); +} forEach _attachedObjects; + +canStand _unit && {alive _attachToVehicle} && {_minDistance < 2.4} diff --git a/AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf b/AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf deleted file mode 100644 index ceff86f2f..000000000 --- a/AGM_Attach/functions/fn_vehicleGetAttachPoint.sqf +++ /dev/null @@ -1,71 +0,0 @@ -/* -Name: AGM_Attach_fnc_vehicleGetAttachPoint - -Author: Pabst Mirror - -Description: - Gets a attach point for a vehicle (in model space cords). Will check the config for AGM_AttachPoint_X first. - Otherwise it finds a solution using lineIntersectsWith. - -Parameters: - 0: OBJECT - vehicle - 1: STRING - placement point name (right, left, back) - -Returns: - Nothing - -Example: -called from module -*/ -private ["_vehicle", "_attachPointLocation", "_config", "_returnAttachPoint", "_bbox", "_driverPos", "_posX", "_minHeight", "_maxHeight", "_curHeight", "_position0", "_position1", "_posZ", "_minBack", "_maxBack", "_curBack"]; - -_vehicle = _this select 0; -_attachPointLocation = _this select 1; - -_config = configFile >> "CfgVehicles" >> (typeOf _vehicle); - -_returnAttachPoint = getArray (_config >> format ["AGM_AttachPoint_%1", _attachPointLocation]); -if ((count _returnAttachPoint) == 0) then { - //Find the location on the model using intersections - _bbox = boundingBoxReal _vehicle; - if (_attachPointLocation in ["left", "right"]) then { - _driverPos = _vehicle selectionPosition (getText (_config >> "memoryPointsGetInDriver")); - _posX = if (_attachPointLocation == "right") then { - 0.425 * (abs (_driverPos select 0)) - } else { - -0.425 * (abs (_driverPos select 0)) - }; - _minHeight = (_bbox select 0) select 2; - _maxHeight = (_bbox select 1) select 2; - _curHeight = _maxHeight; - _position0 = _vehicle modeltoWorld [_posX, (_driverPos select 1), (_maxHeight + 0.05)]; - - while {_curHeight > _minHeight} do { - _position1 = _vehicle modelToWorld [_posX, (_driverPos select 1), (_curHeight)]; - if (_vehicle in lineIntersectsWith [(ATLToASL _position0), (ATLToASL _position1), player]) exitWith {}; - _curHeight = _curHeight - 0.01; - }; - _curHeight = _curHeight + 0.025; - //Raise up a little so it's not sunk into the hull - //sometimes it's too much, but better then hidden - - _returnAttachPoint = [_posX, (_driverPos select 1), _curHeight]; - }; - - if (_attachPointLocation == "rear") then { - _posZ = ((_bbox select 0) select 2) + 0.75; - _minBack = (_bbox select 0) select 1; - _maxBack = (_bbox select 1) select 1; - _curBack = _minBack; - _position0 = _vehicle modeltoWorld [0, (_minBack - 0.05), _posZ]; - while {_curBack < _maxBack} do { - _position1 = _vehicle modelToWorld [0, _curBack, _posZ]; - if (_vehicle in lineIntersectsWith [(ATLToASL _position0), (ATLToASL _position1), player]) exitWith {}; - _curBack = _curBack + 0.01; - }; - _curBack = _curBack - 0.1; - _returnAttachPoint = [0, _curBack, _posZ]; - }; -}; - -_returnAttachPoint diff --git a/AGM_Attach/stringtable.xml b/AGM_Attach/stringtable.xml index 42d2fa493..473d67539 100644 --- a/AGM_Attach/stringtable.xml +++ b/AGM_Attach/stringtable.xml @@ -133,6 +133,28 @@ O Marcador IV permite que você sinalize sua posição através de um pulso visível somente com equipamento de visão noturna. La Strobo IR è una luce stroboscopica che ti permette di segnalare la tua posizione grazie all'emissione di impulsi ad infrarossi visibili solo con i visori notturni. Az infravörös jeladóval megjelölheted a helyzetedet úgy, hogy annak pulzáló fénye csak éjjellátó készülékkel látható. + + + Place + Platzieren + Colocar + Umieść + Placer + Položit + Colocar + Posiziona + Elhelyez + + + Cancel + Abbrechen + Cancelar + Anuluj + Annuler + Zrušit + Cancelar + Annulla + Mégse From f1517139b2281c1932547827eff2cac8ec2cf565 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 21:02:22 -0600 Subject: [PATCH 4/7] Formating --- AGM_Attach/functions/fn_Place_Approve.sqf | 20 ++++++++++---------- AGM_Attach/functions/fn_attach.sqf | 12 ++++++------ AGM_Attach/functions/fn_vehicleCanDetach.sqf | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/AGM_Attach/functions/fn_Place_Approve.sqf b/AGM_Attach/functions/fn_Place_Approve.sqf index 76d1b5d15..596efa8c0 100644 --- a/AGM_Attach/functions/fn_Place_Approve.sqf +++ b/AGM_Attach/functions/fn_Place_Approve.sqf @@ -1,18 +1,18 @@ /* Name: AGM_Attach_fnc_Place_Approve - + Author(s): Pabst Mirror (based on Explosive attach by Garth de Wet (LH)) - + Description: Approves placement of the lightObject, releases the placement object for it to settle in a location - + Parameters: Nothing - + Returns: Nothing - + Example: call AGM_Attach_fnc_Place_Approve; */ @@ -58,11 +58,11 @@ while {_keepGoingCloser} do { _position1 = [(_offset select 0) * _closeInRatio, (_offset select 1) * _closeInRatio, (_offset select 2)]; _position1 = _attachToVehicle modelToWorld _position1; _position1 = _position1 vectorAdd _x; - //Uncomment to see the lazor show, and see how the scanning works: + //Uncomment to see the lazor show, and see how the scanning works: // drawLine3D [_pos0temp, _position1, [1,0,0,1]]; if (_attachToVehicle in lineIntersectsWith [(ATLToASL _pos0temp), (ATLToASL _position1), player, _setupObject]) exitWith {_keepGoingCloser = false}; - } forEach [[0,0,0], [0,0,0.075], [0,0,-0.075], [0,0.075,0], [0,-0.075,0], [0.075,0,0], [-.075,0,0]]; - } forEach [[0,0,0], [0,0,0.075], [0,0,-0.075]]; + } forEach [[0,0,0], [0,0,0.075], [0,0,-0.075], [0,0.075,0], [0,-0.075,0], [0.075,0,0], [-.075,0,0]]; + } forEach [[0,0,0], [0,0,0.075], [0,0,-0.075]]; }; //Move it out slightly, for visability sake (better to look a little funny than be embedded//sunk in the hull) _closeInRatio = (_closeInRatio + 0.006) min 1; @@ -75,11 +75,11 @@ _attachedObject = _setupClassname createVehicle (getPos _player); _attachedObject attachTo [_attachToVehicle, [(_offset select 0) * _closeInRatio, (_offset select 1) * _closeInRatio, (_offset select 2)]]; //Remove Item from inventory -_player removeItem _itemClassname; +_player removeItem _itemClassname; //Add Object to AGM_AttachedObjects and AGM_AttachedItemNames _currentObjects = _attachToVehicle getVariable ["AGM_AttachedObjects", []]; -_currentObjects pushBack _attachedObject; +_currentObjects pushBack _attachedObject; _attachToVehicle setVariable ["AGM_AttachedObjects", _currentObjects, true]; _currentItemNames = _attachToVehicle getVariable ["AGM_AttachedItemNames", []]; _currentItemNames pushBack _itemClassname; diff --git a/AGM_Attach/functions/fn_attach.sqf b/AGM_Attach/functions/fn_attach.sqf index 4b31f4870..7c42aa189 100644 --- a/AGM_Attach/functions/fn_attach.sqf +++ b/AGM_Attach/functions/fn_attach.sqf @@ -32,24 +32,24 @@ _itemVehClass = ""; _onAtachText = ""; switch true do { -case (_itemName == "AGM_IR_Strobe_Item"): { + case (_itemName == "AGM_IR_Strobe_Item"): { _itemVehClass = "AGM_IR_Strobe_Effect"; _onAtachText = localize "STR_AGM_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 (_itemName == "B_IR_Grenade"): { _itemVehClass = "B_IRStrobe"; _onAtachText = localize "STR_AGM_Attach_IrGrenade_Attached"; }; -case (_itemName == "O_IR_Grenade"): { + case (_itemName == "O_IR_Grenade"): { _itemVehClass = "O_IRStrobe"; _onAtachText = localize "STR_AGM_Attach_IrGrenade_Attached"; }; -case (_itemName == "I_IR_Grenade"): { + case (_itemName == "I_IR_Grenade"): { _itemVehClass = "I_IRStrobe"; _onAtachText = localize "STR_AGM_Attach_IrGrenade_Attached"; }; -case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): { + case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): { _itemVehClass = _itemName; _onAtachText = localize "STR_AGM_Attach_Chemlight_Attached"; }; @@ -79,7 +79,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment ["AGM_Attach_Placement","OnEachFrame", { private "_player"; _player = AGM_player; - //Stop if player switch or player gets to far from vehicle + //Stop if player switch or player gets to far from vehicle if ((AGM_Attach_placer != _player) || ((_player distance AGM_Attach_SetupAttachVehicle) > 9)) exitWith { call AGM_Attach_fnc_Place_Cancel; }; diff --git a/AGM_Attach/functions/fn_vehicleCanDetach.sqf b/AGM_Attach/functions/fn_vehicleCanDetach.sqf index 14f9f773f..5a7b6b4bc 100644 --- a/AGM_Attach/functions/fn_vehicleCanDetach.sqf +++ b/AGM_Attach/functions/fn_vehicleCanDetach.sqf @@ -5,7 +5,7 @@ Author: Pabst Mirror Description: Tests if the unit can detach from the vehicle - + Parameters: 0: OBJECT - unit doing the detaching (usualy the player) 1: OBJECT - vehicle that it will be attached to (player or vehicle) @@ -28,9 +28,9 @@ _unitPos = getPos _unit; _unitPos set [2,0]; _minDistance = 1000; { - _objectPos = getPos _x; - _objectPos set [2, 0]; - _minDistance = _minDistance min (_objectPos distance _unitPos); + _objectPos = getPos _x; + _objectPos set [2, 0]; + _minDistance = _minDistance min (_objectPos distance _unitPos); } forEach _attachedObjects; canStand _unit && {alive _attachToVehicle} && {_minDistance < 2.4} From aa0a952508d974bdf25b34d829b66bbe6b9a5ea6 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 21:21:49 -0600 Subject: [PATCH 5/7] hotkey conflict --- .../attach_findVehicleModelPositions.sqf | 18 ------------------ AGM_Attach/config.cpp | 1 - 2 files changed, 19 deletions(-) delete mode 100644 .devfiles/scripts/attach_findVehicleModelPositions.sqf diff --git a/.devfiles/scripts/attach_findVehicleModelPositions.sqf b/.devfiles/scripts/attach_findVehicleModelPositions.sqf deleted file mode 100644 index eb8535485..000000000 --- a/.devfiles/scripts/attach_findVehicleModelPositions.sqf +++ /dev/null @@ -1,18 +0,0 @@ -//Pabst Mirror -//AGM_Attach - Helper for finding good attach points on vehicles (based on explosive placement) - - -TEST_LIGHT = "B_IRStrobe" createVehicle (getpos player); -TEST_LIGHT enableSimulation false; - -["asdf","OnEachFrame", { - _pos = (ASLtoATL eyePos player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]); - TEST_LIGHT setPosATL _pos; - - LightPos = cursorTarget worldToModel _pos; - hintSilent format ["LightPos: %1", LightPos]; -}] call BIS_fnc_addStackedEventHandler; - -//check debug: -//typeOf cursorTarget -//LightPos \ No newline at end of file diff --git a/AGM_Attach/config.cpp b/AGM_Attach/config.cpp index 13a8c26d9..b3b095510 100644 --- a/AGM_Attach/config.cpp +++ b/AGM_Attach/config.cpp @@ -54,7 +54,6 @@ class CfgFunctions { showDisabled = 0; \ priority = 0; \ icon = "\AGM_Attach\UI\detach_ca.paa"; \ - hotkey = "T"; \ }; \ }; From 017e8e87e5796c0fa56d0f388a824b4db6171522 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 21:26:40 -0600 Subject: [PATCH 6/7] Private Variables --- AGM_Attach/functions/fn_Place_Approve.sqf | 2 ++ AGM_Attach/functions/fn_attach.sqf | 2 +- AGM_Attach/functions/fn_detach.sqf | 3 ++- AGM_Attach/functions/fn_vehicleCanDetach.sqf | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AGM_Attach/functions/fn_Place_Approve.sqf b/AGM_Attach/functions/fn_Place_Approve.sqf index 596efa8c0..54d5ae46f 100644 --- a/AGM_Attach/functions/fn_Place_Approve.sqf +++ b/AGM_Attach/functions/fn_Place_Approve.sqf @@ -16,6 +16,8 @@ Example: call AGM_Attach_fnc_Place_Approve; */ +private ["_setupObject", "_setupClassname", "_itemClassname", "_placementText", "_attachToVehicle", "_player", "_position0", "_closeInRatio", "_offset", "_keepGoingCloser", "_pos0temp", "_position1", "_attachedObject", "_currentObjects", "_currentItemNames"]; + if (AGM_Attach_pfeh_running) then { ["AGM_Attach_Placement","OnEachFrame"] call BIS_fnc_removeStackedEventHandler; AGM_Attach_pfeh_running = false; diff --git a/AGM_Attach/functions/fn_attach.sqf b/AGM_Attach/functions/fn_attach.sqf index 7c42aa189..9bb0cca51 100644 --- a/AGM_Attach/functions/fn_attach.sqf +++ b/AGM_Attach/functions/fn_attach.sqf @@ -13,7 +13,7 @@ Arguments: Return Value: none */ -private ["_unit", "_attachToVehicle", "_attachToPointName", "_itemName", "_attachPosition", "_attachedItem"]; +private ["_unit", "_attachToVehicle", "_itemName", "_selfAttachPosition", "_itemVehClass", "_onAtachText", "_attachedItem", "_player"]; _unit = _this select 0; _attachToVehicle = _this select 1; diff --git a/AGM_Attach/functions/fn_detach.sqf b/AGM_Attach/functions/fn_detach.sqf index 96e15fcae..85c2f10a6 100644 --- a/AGM_Attach/functions/fn_detach.sqf +++ b/AGM_Attach/functions/fn_detach.sqf @@ -12,7 +12,8 @@ Arguments: Return Value: none */ -private ["_unit", "_attachToVehicle", "_attachToPointName", "_itemName", "_count", "_attachedItem"]; +private ["_unit", "_attachToVehicle", "_attachedObjectsArray", "_attachedItemsArray", "_attachedObject", "_itemName", "_minDistance", "_unitPos", "_objectPos", "_count", "_attachedItem"]; + _unit = _this select 0; _attachToVehicle = _this select 1; diff --git a/AGM_Attach/functions/fn_vehicleCanDetach.sqf b/AGM_Attach/functions/fn_vehicleCanDetach.sqf index 5a7b6b4bc..33119b7f1 100644 --- a/AGM_Attach/functions/fn_vehicleCanDetach.sqf +++ b/AGM_Attach/functions/fn_vehicleCanDetach.sqf @@ -16,7 +16,7 @@ Returns: Example: [player, tank] call AGM_Attach_fnc_vehicleCanDetach */ -private ["_unit", "_attachToVehicle", "_attachToPointName", "_modelPosition", "_worldPos", "_unitPos", "_minDistance"]; +private ["_unit", "_attachToVehicle", "_attachedObjects", "_unitPos", "_minDistance", "_objectPos"]; _unit = _this select 0; _attachToVehicle = _this select 1; From 94002f41b68ade5b5bd036f5deeb9fe6c30ae971 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 6 Dec 2014 21:32:27 -0600 Subject: [PATCH 7/7] Formating --- AGM_Attach/config.cpp | 4 +-- AGM_Attach/functions/fn_openAttachUI.sqf | 36 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/AGM_Attach/config.cpp b/AGM_Attach/config.cpp index b3b095510..f591394ca 100644 --- a/AGM_Attach/config.cpp +++ b/AGM_Attach/config.cpp @@ -36,7 +36,7 @@ class CfgFunctions { #define MACRO_ATTACHTOVEHICLE \ class AGM_Actions { \ - class AGM_Attach_right { \ + class AGM_AttachVehicle { \ displayName = "$STR_AGM_Attach_AttachDetach"; \ condition = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_vehicleCanAttach"; \ statement = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_openAttachUI;"; \ @@ -46,7 +46,7 @@ class CfgFunctions { icon = "\AGM_Attach\UI\attach_ca.paa"; \ hotkey = "T"; \ }; \ - class AGM_Attach_Detach_right { \ + class AGM_Attach_DetachVehicle { \ displayName = "$STR_AGM_Attach_Detach"; \ condition = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_vehicleCanDetach"; \ statement = "[_player, AGM_Interaction_Target] call AGM_Attach_fnc_detach"; \ diff --git a/AGM_Attach/functions/fn_openAttachUI.sqf b/AGM_Attach/functions/fn_openAttachUI.sqf index b2fd3cad1..bd58fdde1 100644 --- a/AGM_Attach/functions/fn_openAttachUI.sqf +++ b/AGM_Attach/functions/fn_openAttachUI.sqf @@ -13,7 +13,7 @@ Nothing Example: - [player, player, "self"] call AGM_Attach_fnc_openAttachUI; + [player, player] call AGM_Attach_fnc_openAttachUI; */ private ["_unit", "_attachToVehicle", "_attachToPointName", "_listed", "_attachables", "_actions", "_item"]; @@ -29,10 +29,10 @@ _actions = [localize "STR_AGM_Attach_AttachDetach", localize "STR_AGM_Attach_Att _item = ConfigFile >> "CfgMagazines" >> _x; if (getNumber (_item >> "AGM_Attachable") == 1) then { _actions = [ - _actions, - getText(_item >> "displayName"), - getText(_item >> "picture"), - _x + _actions, + getText(_item >> "displayName"), + getText(_item >> "picture"), + _x ] call AGM_Interaction_fnc_AddSelectableItem; }; _listed pushBack _x; @@ -44,10 +44,10 @@ _attachables = items _unit; _item = ConfigFile >> "CfgWeapons" >> _x; if (getNumber (_item >> "AGM_Attachable") == 1) then { _actions = [ - _actions, - getText(_item >> "displayName"), - getText(_item >> "picture"), - _x + _actions, + getText(_item >> "displayName"), + getText(_item >> "picture"), + _x ] call AGM_Interaction_fnc_AddSelectableItem; }; _listed pushBack _x; @@ -55,13 +55,13 @@ _attachables = items _unit; } forEach _attachables; [ -_actions, -{ - [AGM_player, AGM_Interaction_Target, _this] call AGM_Attach_fnc_attach; - call AGM_Interaction_fnc_hideMenu; -}, -{ - call AGM_Interaction_fnc_hideMenu; - if !(profileNamespace getVariable ["AGM_Interaction_AutoCloseMenu", false]) then {"Default" call AGM_Interaction_fnc_openMenuSelf}; -} + _actions, + { + [AGM_player, AGM_Interaction_Target, _this] call AGM_Attach_fnc_attach; + call AGM_Interaction_fnc_hideMenu; + }, + { + call AGM_Interaction_fnc_hideMenu; + if !(profileNamespace getVariable ["AGM_Interaction_AutoCloseMenu", false]) then {"Default" call AGM_Interaction_fnc_openMenuSelf}; + } ] call AGM_Interaction_fnc_openSelectMenu;