From c452f94779aa670587c81a14222d42e6cd3b85ab Mon Sep 17 00:00:00 2001 From: mrschick <58027418+mrschick@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:31:30 +0200 Subject: [PATCH] Fix water actions on vehicles with no waterActionOffset --- addons/field_rations/XEH_postInit.sqf | 8 +++--- .../fnc_addWaterSourceInteractions.sqf | 27 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/addons/field_rations/XEH_postInit.sqf b/addons/field_rations/XEH_postInit.sqf index 9344eebcbb..d11c4b4450 100644 --- a/addons/field_rations/XEH_postInit.sqf +++ b/addons/field_rations/XEH_postInit.sqf @@ -17,7 +17,7 @@ if !(hasInterface) exitWith {}; }; // Compile water source actions - private _mainAction = [ + GVAR(mainAction) = [ QGVAR(waterSource), LLSTRING(WaterSource), QPATHTOF(ui\icon_water_tap.paa), @@ -40,7 +40,7 @@ if !(hasInterface) exitWith {}; [false, false, false, false, true] ] call EFUNC(interact_menu,createAction); - private _subActions = [ + GVAR(subActions) = [ [ QGVAR(checkWater), LLSTRING(CheckWater), @@ -70,10 +70,10 @@ if !(hasInterface) exitWith {}; ]; // Add water source actions to helper - [QGVAR(helper), 0, [], _mainAction] call EFUNC(interact_menu,addActionToClass); + [QGVAR(helper), 0, [], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass); { [QGVAR(helper), 0, [QGVAR(waterSource)], _x] call EFUNC(interact_menu,addActionToClass); - } forEach _subActions; + } forEach GVAR(subActions); // Add inventory context menu option to consume items ["ACE_ItemCore", ["CONTAINER"], LSTRING(EatDrink), [], QPATHTOF(ui\icon_survival.paa), diff --git a/addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf b/addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf index d45ea877ca..ae69fee97d 100644 --- a/addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf +++ b/addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf @@ -49,13 +49,28 @@ TRACE_1("Starting interact PFH",_interactionType); if (_waterRemaining != REFILL_WATER_DISABLED) then { private _offset = [_x] call FUNC(getActionOffset); - private _helper = QGVAR(helper) createVehicleLocal [0, 0, 0]; - _helper setVariable [QGVAR(waterSource), _x]; - _helper attachTo [_x, _offset]; + if (_offset isEqualTo [0,0,0]) then { + if !(_x getVariable [QGVAR(waterSourceActionsAdded), false]) then { + private _vehicle = _x; + _vehicle setVariable [QGVAR(waterSource), _vehicle]; + _sourcesHelped pushBack _vehicle; + // Add water source actions to the vehicle itself + private _mainAction = [_vehicle, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToObject); + { + [_vehicle, 0, _mainAction, _x] call EFUNC(interact_menu,addActionToObject); + } forEach GVAR(subActions); + _vehicle setVariable [QGVAR(waterSourceActionsAdded), true]; + TRACE_3("Added interaction to vehicle",_x,typeOf _x,_waterRemaining); + }; + } else { + private _helper = QGVAR(helper) createVehicleLocal [0, 0, 0]; + _helper setVariable [QGVAR(waterSource), _x]; + _helper attachTo [_x, _offset]; - _addedHelpers pushBack _helper; - _sourcesHelped pushBack _x; - TRACE_3("Added interaction helper",_x,typeOf _x,_waterRemaining); + _addedHelpers pushBack _helper; + _sourcesHelped pushBack _x; + TRACE_3("Added interaction helper",_x,typeOf _x,_waterRemaining); + }; }; }; } forEach nearestObjects [ACE_player, [], 15];