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:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2015-02-01 20:56:19 +00:00
|
|
|
*
|
|
|
|
* 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-08-28 21:57:16 +00:00
|
|
|
params ["_attachToVehicle","_unit","_args", ["_silentScripted", false]];
|
2015-08-06 18:17:59 +00:00
|
|
|
_args params [["_itemClassname","", [""]]];
|
2015-08-28 21:57:16 +00:00
|
|
|
TRACE_4("params",_attachToVehicle,_unit,_itemClassname,_silentScripted);
|
2015-02-15 14:31:09 +00:00
|
|
|
|
2015-08-28 21:57:16 +00:00
|
|
|
//Sanity Check (_unit has item in inventory, not over attach limit)
|
|
|
|
if ((_itemClassname == "") || {(!_silentScripted) && {!(_this call FUNC(canAttach))}}) exitWith {ERROR("Tried to attach, but check failed");};
|
2015-01-11 20:39:49 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _itemVehClass = getText (configFile >> "CfgWeapons" >> _itemClassname >> "ACE_Attachable");
|
|
|
|
private _onAttachText = getText (configFile >> "CfgWeapons" >> _itemClassname >> "displayName");
|
2015-04-10 01:49:50 +00:00
|
|
|
|
|
|
|
if (_itemVehClass == "") then {
|
2015-04-10 02:36:28 +00:00
|
|
|
_itemVehClass = getText (configFile >> "CfgMagazines" >> _itemClassname >> "ACE_Attachable");
|
2017-10-10 14:39:59 +00:00
|
|
|
_onAttachText = 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
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _onAttachText = format [localize LSTRING(Item_Attached), _onAttachText];
|
2015-01-30 20:32:21 +00:00
|
|
|
|
|
|
|
if (_unit == _attachToVehicle) then { //Self Attachment
|
2017-10-10 14:39:59 +00:00
|
|
|
private _attachedItem = _itemVehClass createVehicle [0,0,0];
|
2016-05-09 10:51:28 +00:00
|
|
|
_attachedItem attachTo [_unit, [0.05, -0.09, 0.1], "leftshoulder"];
|
2015-08-28 21:57:16 +00:00
|
|
|
if (!_silentScripted) then {
|
|
|
|
_unit removeItem _itemClassname; // Remove item
|
2017-12-16 15:20:43 +00:00
|
|
|
[_onAttachText, 2] call EFUNC(common,displayTextStructured);
|
2015-08-28 21:57:16 +00:00
|
|
|
};
|
|
|
|
_unit setVariable [QGVAR(attached), [[_attachedItem, _itemClassname]], true];
|
2015-01-30 20:32:21 +00:00
|
|
|
} else {
|
2015-06-19 18:32:42 +00:00
|
|
|
GVAR(placeAction) = PLACE_WAITING;
|
2015-03-27 16:14:19 +00:00
|
|
|
|
2016-01-19 15:34:59 +00:00
|
|
|
[_unit, "forceWalk", "ACE_Attach", true] call EFUNC(common,statusEffect_set);
|
2017-12-07 17:26:21 +00:00
|
|
|
[_unit, "blockThrow", "ACE_Attach", true] call EFUNC(common,statusEffect_set);
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2016-05-22 13:27:24 +00:00
|
|
|
[{[localize LSTRING(PlaceAction), ""] call EFUNC(interaction,showMouseHint)}, []] call CBA_fnc_execNextFrame;
|
2015-06-19 18:32:42 +00:00
|
|
|
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)];
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = PLACE_CANCEL}];
|
2015-03-27 16:14:19 +00:00
|
|
|
|
2015-06-19 18:32:42 +00:00
|
|
|
//Display to show virtual object:
|
2017-10-10 14:39:59 +00:00
|
|
|
private _model = getText (configFile >> "CfgAmmo" >> _itemVehClass >> "model");
|
2015-06-19 18:32:42 +00:00
|
|
|
if (_model == "") then {
|
|
|
|
_model = getText (configFile >> "CfgVehicles" >> _itemVehClass >> "model");
|
|
|
|
};
|
|
|
|
//"\A3\Weapons_F\empty.p3d" is fine, but ctrlSetModel ""; - will crash game!
|
|
|
|
if (_model == "") exitWith {ERROR("No Model");};
|
|
|
|
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutRsc [QGVAR(virtualAmmo), "PLAIN", 0, false];
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModel _model;
|
2015-03-27 16:53:04 +00:00
|
|
|
|
2015-03-27 16:14:19 +00:00
|
|
|
[{
|
2015-08-04 22:47:31 +00:00
|
|
|
params ["_args","_idPFH"];
|
2017-10-10 14:39:59 +00:00
|
|
|
_args params ["_unit","_attachToVehicle","_itemClassname","_itemVehClass","_onAttachText","_actionID"];
|
2015-06-19 18:32:42 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,0.6]) vectorDiff (positionCameraToWorld [0,0,0]);
|
2015-07-08 20:53:31 +00:00
|
|
|
if (cameraView == "EXTERNAL") then {
|
|
|
|
_virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0]));
|
|
|
|
};
|
2017-10-10 14:39:59 +00:00
|
|
|
private _virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition);
|
|
|
|
private _lineInterection = lineIntersects [eyePos ACE_player, _virtualPosASL, ACE_player];
|
2015-07-01 19:53:59 +00:00
|
|
|
|
|
|
|
//Don't allow placing in a bad position:
|
|
|
|
if (_lineInterection && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;};
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2015-06-19 18:32:42 +00:00
|
|
|
if ((GVAR(placeAction) != PLACE_WAITING) ||
|
2015-03-27 16:14:19 +00:00
|
|
|
{_unit != ACE_player} ||
|
2017-08-22 18:30:56 +00:00
|
|
|
{!([_unit, _attachToVehicle, ["isNotSwimming"]] call EFUNC(common,canInteractWith))} ||
|
2015-03-27 16:14:19 +00:00
|
|
|
{!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then {
|
|
|
|
|
2015-08-04 22:47:31 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
2016-01-19 15:34:59 +00:00
|
|
|
[_unit, "forceWalk", "ACE_Attach", false] call EFUNC(common,statusEffect_set);
|
2017-12-07 17:26:21 +00:00
|
|
|
[_unit, "blockThrow", "ACE_Attach", false] call EFUNC(common,statusEffect_set);
|
2015-03-27 16:14:19 +00:00
|
|
|
[] call EFUNC(interaction,hideMouseHint);
|
|
|
|
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -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-06-19 18:32:42 +00:00
|
|
|
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
|
|
|
|
|
|
|
|
if (GVAR(placeAction) == PLACE_APPROVE) then {
|
2017-10-10 14:39:59 +00:00
|
|
|
[_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAttachText, _virtualPos] call FUNC(placeApprove);
|
2015-03-27 16:14:19 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-06-19 18:32:42 +00:00
|
|
|
//Show the virtual object:
|
2015-07-01 19:53:59 +00:00
|
|
|
if (_lineInterection) then {
|
2015-06-19 18:32:42 +00:00
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false;
|
|
|
|
} else {
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow true;
|
2017-10-10 14:39:59 +00:00
|
|
|
private _screenPos = worldToScreen _virtualPos;
|
2015-06-21 01:40:17 +00:00
|
|
|
if (_screenPos isEqualTo []) exitWith {
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false;
|
|
|
|
};
|
2017-10-10 14:39:59 +00:00
|
|
|
private _realDistance = (_virtualPos distance (positionCameraToWorld [0,0,0])) / ((call CBA_fnc_getFov) select 1);
|
2015-06-21 01:40:17 +00:00
|
|
|
_screenPos = [(_screenPos select 0), _realDistance, (_screenPos select 1)];
|
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetPosition _screenPos;
|
2017-10-10 14:39:59 +00:00
|
|
|
private _dir = (positionCameraToWorld [0,0,1]) vectorFromTo (positionCameraToWorld [0,0,0]);
|
|
|
|
private _angle = asin (_dir select 2);
|
|
|
|
private _up = [0, cos _angle, sin _angle];
|
2015-06-19 18:32:42 +00:00
|
|
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModelDirAndUp [[1,0,0], _up];
|
|
|
|
};
|
2015-03-27 16:14:19 +00:00
|
|
|
};
|
2017-10-10 14:39:59 +00:00
|
|
|
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAttachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
2015-01-30 20:32:21 +00:00
|
|
|
};
|