mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Attach use purely virtual object (no setPos)
This commit is contained in:
parent
7129cb34fd
commit
25df7aad09
30
addons/attach/GUI_VirtualAmmo.hpp
Normal file
30
addons/attach/GUI_VirtualAmmo.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
class RscTitles {
|
||||||
|
class GVAR(virtualAmmo) {
|
||||||
|
idd = -1;
|
||||||
|
movingEnable = 1;
|
||||||
|
duration = 9999999;
|
||||||
|
fadein = 0;
|
||||||
|
fadeout = 0;
|
||||||
|
onLoad = "uiNamespace setVariable ['ACE_attach_virtualAmmoDisplay', (_this select 0)];";
|
||||||
|
class controls {};
|
||||||
|
class objects {
|
||||||
|
class TheObject {
|
||||||
|
idc = 800851;
|
||||||
|
type = 82;
|
||||||
|
model = "\a3\weapons_f\Ammo\Handgrenade.p3d";
|
||||||
|
scale = 1;
|
||||||
|
direction[] = {0, 0, 1};
|
||||||
|
up[] = {0, 1, 0};
|
||||||
|
x = 0.5;
|
||||||
|
y = 0.5;
|
||||||
|
z = 1;
|
||||||
|
xBack = 0.5;
|
||||||
|
yBack = 0.5;
|
||||||
|
zBack = 0.5;
|
||||||
|
inBack = 0;
|
||||||
|
enableZoom = 0;
|
||||||
|
zoomDuration = 1;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
@ -16,3 +16,4 @@ class CfgPatches {
|
|||||||
#include "CfgMagazines.hpp"
|
#include "CfgMagazines.hpp"
|
||||||
#include "CfgVehicles.hpp"
|
#include "CfgVehicles.hpp"
|
||||||
#include "CfgWeapons.hpp"
|
#include "CfgWeapons.hpp"
|
||||||
|
#include "GUI_VirtualAmmo.hpp"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID"];
|
private ["_itemClassname", "_itemVehClass", "_onAtachText", "_selfAttachPosition", "_attachedItem", "_tempObject", "_actionID", "_model"];
|
||||||
|
|
||||||
PARAMS_3(_attachToVehicle,_unit,_args);
|
PARAMS_3(_attachToVehicle,_unit,_args);
|
||||||
_itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam;
|
_itemClassname = [_args, 0, ""] call CBA_fnc_defaultParam;
|
||||||
@ -47,26 +47,35 @@ if (_unit == _attachToVehicle) then { //Self Attachment
|
|||||||
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
|
_attachToVehicle setVariable [QGVAR(Objects), [_attachedItem], true];
|
||||||
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemClassname], true];
|
_attachToVehicle setVariable [QGVAR(ItemNames), [_itemClassname], true];
|
||||||
} else {
|
} else {
|
||||||
GVAR(placeAction) = -1;
|
GVAR(placeAction) = PLACE_WAITING;
|
||||||
|
|
||||||
_tempObject = _itemVehClass createVehicleLocal [0,0,-10000];
|
|
||||||
_tempObject enableSimulationGlobal false;
|
|
||||||
|
|
||||||
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
|
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
|
||||||
|
|
||||||
//MenuBack isn't working for now (localize "STR_ACE_Attach_CancelAction")
|
|
||||||
[{[localize LSTRING(PlaceAction), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame);
|
[{[localize LSTRING(PlaceAction), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame);
|
||||||
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = 1;}] call EFUNC(common,AddActionEventHandler)];
|
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)];
|
||||||
// _unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {true}, {GVAR(placeAction) = 0;}] call EFUNC(common,AddActionEventHandler)];
|
|
||||||
|
|
||||||
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = 0}];
|
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = PLACE_CANCEL}];
|
||||||
|
|
||||||
|
//Display to show virtual object:
|
||||||
|
private [];
|
||||||
|
_model = getText (configFile >> "CfgAmmo" >> _itemVehClass >> "model");
|
||||||
|
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;
|
||||||
|
|
||||||
[{
|
[{
|
||||||
private "_startingPosition";
|
private "_startingPosition";
|
||||||
PARAMS_2(_args,_pfID);
|
PARAMS_2(_args,_pfID);
|
||||||
EXPLODE_7_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_tempObject,_onAtachText,_actionID);
|
EXPLODE_6_PVT(_args,_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_actionID);
|
||||||
|
|
||||||
if ((GVAR(placeAction) != -1) ||
|
_virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,0.5] vectorDiff positionCameraToWorld [0,0,0]);
|
||||||
|
_virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition);
|
||||||
|
|
||||||
|
if ((GVAR(placeAction) != PLACE_WAITING) ||
|
||||||
{_unit != ACE_player} ||
|
{_unit != ACE_player} ||
|
||||||
{!([_unit, _attachToVehicle, []] call EFUNC(common,canInteractWith))} ||
|
{!([_unit, _attachToVehicle, []] call EFUNC(common,canInteractWith))} ||
|
||||||
{!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then {
|
{!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then {
|
||||||
@ -75,16 +84,28 @@ if (_unit == _attachToVehicle) then { //Self Attachment
|
|||||||
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
|
||||||
[] call EFUNC(interaction,hideMouseHint);
|
[] call EFUNC(interaction,hideMouseHint);
|
||||||
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
[_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;
|
_unit removeAction _actionID;
|
||||||
|
|
||||||
if (GVAR(placeAction) == 1) then {
|
(QGVAR(virtualAmmo) call BIS_fnc_rscLayer) cutText ["", "PLAIN"];
|
||||||
_startingPosition = _tempObject modelToWorldVisual [0,0,0];
|
|
||||||
[_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _startingPosition] call FUNC(placeApprove);
|
if (GVAR(placeAction) == PLACE_APPROVE) then {
|
||||||
|
[_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _virtualPos] call FUNC(placeApprove);
|
||||||
};
|
};
|
||||||
deleteVehicle _tempObject;
|
|
||||||
} else {
|
} else {
|
||||||
_tempObject setPosATL ((ASLtoATL eyePos _unit) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]));;
|
//Show the virtual object:
|
||||||
|
if (lineIntersects [eyePos ACE_player, _virtualPosASL, ACE_player]) then {
|
||||||
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow false;
|
||||||
|
} else {
|
||||||
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlShow true;
|
||||||
|
_pos = worldToScreen _virtualPos;
|
||||||
|
_realDistance = _virtualPos distance (positionCameraToWorld [0,0,0]);
|
||||||
|
_pos = [(_pos select 0), _realDistance, (_pos select 1)];
|
||||||
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetPosition _pos;
|
||||||
|
_dir = (positionCameraToWorld [0,0,1]) vectorFromTo (positionCameraToWorld [0,0,0]);
|
||||||
|
_angle = asin (_dir select 2);
|
||||||
|
_up = [0, cos _angle, sin _angle];
|
||||||
|
((uiNamespace getVariable [QGVAR(virtualAmmoDisplay), displayNull]) displayCtrl 800851) ctrlSetModelDirAndUp [[1,0,0], _up];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _tempObject, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
}, 0, [_unit, _attachToVehicle, _itemClassname, _itemVehClass, _onAtachText, _actionID]] call CBA_fnc_addPerFrameHandler;
|
||||||
};
|
};
|
||||||
|
@ -9,4 +9,8 @@
|
|||||||
#define DEBUG_SETTINGS DEBUG_SETTINGS_ATTACH
|
#define DEBUG_SETTINGS DEBUG_SETTINGS_ATTACH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "\z\ace\addons\main\script_macros.hpp"
|
#include "\z\ace\addons\main\script_macros.hpp"
|
||||||
|
|
||||||
|
#define PLACE_WAITING -1
|
||||||
|
#define PLACE_CANCEL 0
|
||||||
|
#define PLACE_APPROVE 1
|
||||||
|
Loading…
Reference in New Issue
Block a user