From 0b2b4d73971889678a18c3e6040221a6030e1aaa Mon Sep 17 00:00:00 2001 From: Steve Zhao Date: Mon, 11 Oct 2021 04:29:09 -0400 Subject: [PATCH] Medical - Improve keybind to open med menu for vehicle occupant under cursor (#8160) * add lineIntersectsSurfaces to med menu key * fix _target = nil if no intersections * only look through player and player vehicle * Update addons/medical_gui/XEH_postInit.sqf Co-authored-by: commy2 Co-authored-by: PabstMirror Co-authored-by: commy2 --- addons/medical_gui/XEH_postInit.sqf | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/medical_gui/XEH_postInit.sqf b/addons/medical_gui/XEH_postInit.sqf index c6dd4e2722..6127a1a013 100644 --- a/addons/medical_gui/XEH_postInit.sqf +++ b/addons/medical_gui/XEH_postInit.sqf @@ -33,13 +33,26 @@ GVAR(selfInteractionActions) = []; }] call CBA_fnc_addEventHandler; ["ACE3 Common", QGVAR(openMedicalMenuKey), localize LSTRING(OpenMedicalMenu), { - // Get target (cursorTarget and cursorObject), if not valid then target is ACE_player + // Get target (cursorTarget, cursorObject, and lineIntersectsSurfaces along camera to maxDistance), if not valid then target is ACE_player TRACE_3("Open menu key",cursorTarget,cursorObject,ACE_player); private _target = cursorTarget; if !(_target isKindOf "CAManBase" && {[ACE_player, _target] call FUNC(canOpenMenu)}) then { _target = cursorObject; if !(_target isKindOf "CAManBase" && {[ACE_player, _target] call FUNC(canOpenMenu)}) then { - _target = ACE_player; + private _start = AGLToASL positionCameraToWorld [0, 0, 0]; + private _end = AGLToASL positionCameraToWorld [0, 0, GVAR(maxDistance)]; + private _intersections = lineIntersectsSurfaces [_start, _end, ACE_player, objNull, true, -1, "FIRE"]; + { + _x params ["", "", "_intersectObject"]; + // Only look "through" player and player's vehicle + if (!(_intersectObject isKindOf "CAManBase") && {_intersectObject != vehicle ACE_player}) exitWith {}; + if (_intersectObject != ACE_player && {_intersectObject isKindOf "CAManBase" && {[ACE_player, _intersectObject] call FUNC(canOpenMenu)}}) exitWith { + _target =_intersectObject + }; + } forEach _intersections; + if (!(_target isKindOf "CAManBase") || {!([ACE_player, _target] call FUNC(canOpenMenu))}) then { + _target = ACE_player; + }; }; };