ACE3/addons/attach/functions/fnc_attach.sqf

106 lines
4.8 KiB
Plaintext
Raw Normal View History

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:
* 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 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
//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
_itemVehClass = "";
_onAtachText = "";
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-02-15 14:31:09 +00:00
switch (true) do {
2015-03-27 16:14:19 +00:00
case (_itemClassname == "ACE_IR_Strobe_Item"): {
2015-02-01 20:56:19 +00:00
_itemVehClass = "ACE_IR_Strobe_Effect";
_onAtachText = localize "STR_ACE_Attach_IrStrobe_Attached";
2015-02-15 14:31:09 +00:00
//_selfAttachPosition = [_unit, [0, -0.11, 0.16], "pilot"]; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri
2015-02-01 20:56:19 +00:00
};
2015-03-27 16:14:19 +00:00
case (_itemClassname == "B_IR_Grenade"): {
2015-02-01 20:56:19 +00:00
_itemVehClass = "B_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
2015-03-27 16:14:19 +00:00
case (_itemClassname == "O_IR_Grenade"): {
2015-02-01 20:56:19 +00:00
_itemVehClass = "O_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
2015-03-27 16:14:19 +00:00
case (_itemClassname == "I_IR_Grenade"): {
2015-02-01 20:56:19 +00:00
_itemVehClass = "I_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
2015-03-27 16:14:19 +00:00
case (toLower _itemClassname in ["chemlight_blue", "chemlight_green", "chemlight_red", "chemlight_yellow"]): {
_itemVehClass = _itemClassname;
2015-02-01 20:56:19 +00:00
_onAtachText = localize "STR_ACE_Attach_Chemlight_Attached";
};
2015-01-11 20:39:49 +00:00
};
if (_itemVehClass == "") exitWith {ERROR("no _itemVehClass for Item");};
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];
} 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-03-27 16:14:19 +00:00
//MenuBack isn't working for now (localize "STR_ACE_Attach_CancelAction")
2015-03-27 01:05:30 +00:00
[{[localize "STR_ACE_Attach_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-03-27 16:36:31 +00:00
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize "STR_ACE_Attach_CancelAction"], {GVAR(placeAction) = 0}];
2015-03-27 16:53:04 +00:00
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-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 {
_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;
};