2015-01-11 20:39:49 +00:00
|
|
|
/*
|
2015-03-27 16:53:04 +00:00
|
|
|
* Author: eRazeri, esteldunedain, PabstMirror
|
2015-02-01 20:56:19 +00:00
|
|
|
* Attach an item to the unit
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-03-27 05:02:54 +00:00
|
|
|
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
|
|
|
|
* 1: unit doing the attach (player) <OBJECT>
|
|
|
|
* 2: Array containing a string of the attachable item <ARRAY>
|
2015-02-01 20:56:19 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* Example:
|
2015-03-27 17:08:05 +00:00
|
|
|
* [bob, bob, ["light"]] call ace_attach_fnc_attach;
|
2015-02-01 20:56:19 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
2015-01-11 20:39:49 +00:00
|
|
|
|
2015-03-27 16:36:31 +00:00
|
|
|
private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID"];
|
2015-03-27 05:02:54 +00:00
|
|
|
|
2015-03-27 17:08:05 +00:00
|
|
|
PARAMS_3(_attachToVehicle,_unit,_args);
|
2015-03-27 16:14:19 +00:00
|
|
|
_itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam;
|
2015-02-15 14:31:09 +00:00
|
|
|
|
2015-03-27 05:02:54 +00:00
|
|
|
//Sanity Check (_unit has item in inventory, not over attach limit)
|
2015-03-27 16:14:19 +00:00
|
|
|
if ((_itemClassname == "") || {!(_this call FUNC(canAttach))}) exitWith {ERROR("Tried to attach, but check failed");};
|
2015-01-11 20:39:49 +00:00
|
|
|
|
2015-02-15 14:31:09 +00:00
|
|
|
_selfAttachPosition = [_unit, [-0.05, 0, 0.12], "rightshoulder"];
|
2015-01-11 20:39:49 +00:00
|
|
|
|
2015-04-10 02:36:28 +00:00
|
|
|
_itemVehClass = getText (configFile >> "CfgWeapons" >> _itemClassname >> "ACE_Attachable");
|
2015-04-10 01:49:50 +00:00
|
|
|
_onAtachText = getText (configFile >> "CfgWeapons" >> _itemClassname >> "displayName");
|
|
|
|
|
|
|
|
if (_itemVehClass == "") then {
|
2015-04-10 02:36:28 +00:00
|
|
|
_itemVehClass = getText (configFile >> "CfgMagazines" >> _itemClassname >> "ACE_Attachable");
|
2015-04-10 01:49:50 +00:00
|
|
|
_onAtachText = getText (configFile >> "CfgMagazines" >> _itemClassname >> "displayName");
|
2015-01-11 20:39:49 +00:00
|
|
|
};
|
|
|
|
|
2015-04-10 02:36:28 +00:00
|
|
|
if (_itemVehClass == "") exitWith {ERROR("no ACE_Attachable for Item");};
|
2015-04-10 01:49:50 +00:00
|
|
|
|
2015-05-28 19:59:04 +00:00
|
|
|
_onAtachText = format [localize LSTRING(Item_Attached), _onAtachText];
|
2015-01-30 20:32:21 +00:00
|
|
|
|
|
|
|
if (_unit == _attachToVehicle) then { //Self Attachment
|
2015-03-27 16:14:19 +00:00
|
|
|
_unit removeItem _itemClassname; // Remove item
|
2015-02-01 20:56:19 +00:00
|
|
|
_attachedItem = _itemVehClass createVehicle [0,0,0];
|
|
|
|
_attachedItem attachTo _selfAttachPosition;
|
|
|
|
[_onAtachText] call EFUNC(common,displayTextStructured);
|
2015-02-15 14:31:09 +00:00
|
|
|
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
|
2015-03-27 16:14:19 +00:00
|
|
|
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemClassname], true];
|
2015-01-30 20:32:21 +00:00
|
|
|
} else {
|
2015-03-27 16:14:19 +00:00
|
|
|
GVAR(placeAction) = -1;
|
|
|
|
|
|
|
|
_tempObject = _itemVehClass createVehicleLocal [0,0,-10000];
|
|
|
|
_tempObject enableSimulationGlobal false;
|
|
|
|
|
2015-02-01 20:56:19 +00:00
|
|
|
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2015-05-28 19:59:04 +00:00
|
|
|
//MenuBack isn't working for now (localize LSTRING(CancelAction))
|
|
|
|
[{[localize LSTRING(PlaceAction), ""] call EFUNC(interaction,showMouseHint)}, [], 0, 0] call EFUNC(common,waitAndExecute);
|
2015-03-27 16:14:19 +00:00
|
|
|
_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)];
|
|
|
|
|
2015-05-28 19:59:04 +00:00
|
|
|
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = 0}];
|
2015-03-27 16:53:04 +00:00
|
|
|
|
2015-03-27 16:14:19 +00:00
|
|
|
[{
|
2015-04-16 17:36:12 +00:00
|
|
|
private "_startingPosition";
|
2015-03-27 16:14:19 +00:00
|
|
|
PARAMS_2(_args,_pfID);
|
2015-03-27 16:36:31 +00:00
|
|
|
EXPLODE_7_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText,_actionID);
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2015-03-27 16:14:19 +00:00
|
|
|
if ((GVAR(placeAction) != -1) ||
|
|
|
|
{_unit != ACE_player} ||
|
|
|
|
{!([_unit, _attachToVehicle, []] call EFUNC(common,canInteractWith))} ||
|
|
|
|
{!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then {
|
|
|
|
|
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
|
|
|
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
|
|
|
[] call EFUNC(interaction,hideMouseHint);
|
|
|
|
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
|
|
|
//[_unit, "MenuBack", (_unit getVariable [QGVAR(cancelActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
2015-03-27 16:36:31 +00:00
|
|
|
_unit removeAction _actionID;
|
2015-03-27 16:53:04 +00:00
|
|
|
|
2015-03-27 16:14:19 +00:00
|
|
|
if (GVAR(placeAction) == 1) then {
|
2015-04-03 22:26:27 +00:00
|
|
|
_startingPosition = _tempObject modelToWorldVisual [0,0,0];
|
2015-03-27 16:14:19 +00:00
|
|
|
[_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]));;
|
|
|
|
};
|
2015-03-27 16:36:31 +00:00
|
|
|
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
2015-01-30 20:32:21 +00:00
|
|
|
};
|