From de82b06b6d7f9c5be48b7c997d6e5b92b946ae51 Mon Sep 17 00:00:00 2001 From: Cat Harsis <101965352+TACHarsis@users.noreply.github.com> Date: Thu, 26 Jan 2023 23:02:22 +0100 Subject: [PATCH 1/3] Refuel - Added events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added ´ace_refuel_fuelSourceInitialized´ and `ace_refuel_jerryCanInitalized´ events * Updated documentation --- addons/refuel/functions/fnc_initSource.sqf | 14 ++++++++------ addons/refuel/functions/fnc_makeJerryCan.sqf | 8 +++++++- docs/wiki/framework/refuel-framework.md | 7 +++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/addons/refuel/functions/fnc_initSource.sqf b/addons/refuel/functions/fnc_initSource.sqf index c484c151f48..38c6c612f95 100644 --- a/addons/refuel/functions/fnc_initSource.sqf +++ b/addons/refuel/functions/fnc_initSource.sqf @@ -15,12 +15,14 @@ * Public: No */ -if (!hasInterface) exitWith {}; - params ["_source"]; TRACE_2("init",_source,typeOf _source); -[_source, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToObject); -{ - [_source, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToObject); -} forEach GVAR(actions); +if (hasInterface) then { + [_source, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToObject); + { + [_source, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToObject); + } forEach GVAR(actions); +}; + +[QGVAR(fuelSourceInitialized), [_source]] call CBA_fnc_localEvent; diff --git a/addons/refuel/functions/fnc_makeJerryCan.sqf b/addons/refuel/functions/fnc_makeJerryCan.sqf index c5fbc1ef09d..c33c09960fe 100644 --- a/addons/refuel/functions/fnc_makeJerryCan.sqf +++ b/addons/refuel/functions/fnc_makeJerryCan.sqf @@ -24,8 +24,14 @@ if (isNull _target || _target setVariable [QGVAR(jerryCan), true]; _target setVariable [QGVAR(source), _target]; - _target setVariable [QGVAR(capacity), _fuelAmount]; + +if (isServer) then { + [_target, _fuelAmount] call FUNC(setFuel); // has global effects + [QVAR(jerryCanInitalized), [_target]] call CBA_fnc_globalevent; +}; + + if (isServer) then { [_target, _fuelAmount] call FUNC(setFuel); }; // Main Action diff --git a/docs/wiki/framework/refuel-framework.md b/docs/wiki/framework/refuel-framework.md index 2679dc9fbfd..73a2ca08d60 100644 --- a/docs/wiki/framework/refuel-framework.md +++ b/docs/wiki/framework/refuel-framework.md @@ -125,3 +125,10 @@ The jerry can will now have a volume of 200 liters. ---| --------- | ----------- 0 | `cursorObject` | Fuel source object 1 | `100` | Fuel supply + +## 3. Events + +| Name | Arguments | Global? | Added in | +| ------------- | ------------- | ------------- | +| ace_refuel_fuelSourceInitialized | Fuel source (OBJECT), items (BOOL or ARRAY) | No | 3.16.0 | +| ace_refuel_jerryCanInitalized | Jerry can (OBJECT) | Yes | 3.16.0 | From 9e32300a1c495f9e6454b8db81e87d18f082a693 Mon Sep 17 00:00:00 2001 From: Cat Harsis <101965352+TACHarsis@users.noreply.github.com> Date: Thu, 26 Jan 2023 23:45:14 +0100 Subject: [PATCH 2/3] Cleaner implementation && more coherent with analog rearm event --- addons/refuel/functions/fnc_initSource.sqf | 14 ++++++-------- addons/refuel/functions/fnc_makeJerryCan.sqf | 2 +- addons/refuel/functions/fnc_makeSource.sqf | 12 +++++++----- docs/wiki/framework/refuel-framework.md | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addons/refuel/functions/fnc_initSource.sqf b/addons/refuel/functions/fnc_initSource.sqf index 38c6c612f95..c484c151f48 100644 --- a/addons/refuel/functions/fnc_initSource.sqf +++ b/addons/refuel/functions/fnc_initSource.sqf @@ -15,14 +15,12 @@ * Public: No */ +if (!hasInterface) exitWith {}; + params ["_source"]; TRACE_2("init",_source,typeOf _source); -if (hasInterface) then { - [_source, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToObject); - { - [_source, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToObject); - } forEach GVAR(actions); -}; - -[QGVAR(fuelSourceInitialized), [_source]] call CBA_fnc_localEvent; +[_source, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToObject); +{ + [_source, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToObject); +} forEach GVAR(actions); diff --git a/addons/refuel/functions/fnc_makeJerryCan.sqf b/addons/refuel/functions/fnc_makeJerryCan.sqf index c33c09960fe..b81aa8e234c 100644 --- a/addons/refuel/functions/fnc_makeJerryCan.sqf +++ b/addons/refuel/functions/fnc_makeJerryCan.sqf @@ -27,7 +27,7 @@ _target setVariable [QGVAR(source), _target]; _target setVariable [QGVAR(capacity), _fuelAmount]; if (isServer) then { - [_target, _fuelAmount] call FUNC(setFuel); // has global effects + [_target, _fuelAmount] call FUNC(setFuel); // has global effects [QVAR(jerryCanInitalized), [_target]] call CBA_fnc_globalevent; }; diff --git a/addons/refuel/functions/fnc_makeSource.sqf b/addons/refuel/functions/fnc_makeSource.sqf index 823b1526435..060d7177f58 100644 --- a/addons/refuel/functions/fnc_makeSource.sqf +++ b/addons/refuel/functions/fnc_makeSource.sqf @@ -56,9 +56,11 @@ if ( _source setVariable [QGVAR(hooks), _hooks, true]; }; -// check if menu already exists -if (_fuelCargoConfig != 0 || {!isNil {_source getVariable QGVAR(initSource_jipID)}}) exitWith {}; +// only add if menu doesn't already exist +if (!(_fuelCargoConfig != 0 && {!isNil {_source getVariable QGVAR(initSource_jipID)}})) then { + private _jipID = [QGVAR(initSource), [_source]] call CBA_fnc_globalEventJIP; + [_jipID, _source] call CBA_fnc_removeGlobalEventJIP; + _source setVariable [QGVAR(initSource_jipID), _jipID]; +}; -private _jipID = [QGVAR(initSource), [_source]] call CBA_fnc_globalEventJIP; -[_jipID, _source] call CBA_fnc_removeGlobalEventJIP; -_source setVariable [QGVAR(initSource_jipID), _jipID]; +[QGVAR(sourceInitialized), [_source]] call CBA_fnc_globalEvent; diff --git a/docs/wiki/framework/refuel-framework.md b/docs/wiki/framework/refuel-framework.md index 73a2ca08d60..6460ee2e765 100644 --- a/docs/wiki/framework/refuel-framework.md +++ b/docs/wiki/framework/refuel-framework.md @@ -130,5 +130,5 @@ The jerry can will now have a volume of 200 liters. | Name | Arguments | Global? | Added in | | ------------- | ------------- | ------------- | -| ace_refuel_fuelSourceInitialized | Fuel source (OBJECT), items (BOOL or ARRAY) | No | 3.16.0 | +| ace_refuel_sourceInitialized | Fuel source (OBJECT), items (BOOL or ARRAY) | Yes | 3.16.0 | | ace_refuel_jerryCanInitalized | Jerry can (OBJECT) | Yes | 3.16.0 | From f562515fee8b593251827634a1d2f449a4daece9 Mon Sep 17 00:00:00 2001 From: Cat Harsis <101965352+TACHarsis@users.noreply.github.com> Date: Fri, 17 Feb 2023 08:42:12 +0100 Subject: [PATCH 3/3] Rebase merging is weird --- addons/refuel/functions/fnc_makeJerryCan.sqf | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/refuel/functions/fnc_makeJerryCan.sqf b/addons/refuel/functions/fnc_makeJerryCan.sqf index b81aa8e234c..b49aa0748c6 100644 --- a/addons/refuel/functions/fnc_makeJerryCan.sqf +++ b/addons/refuel/functions/fnc_makeJerryCan.sqf @@ -31,9 +31,6 @@ if (isServer) then { [QVAR(jerryCanInitalized), [_target]] call CBA_fnc_globalevent; }; - -if (isServer) then { [_target, _fuelAmount] call FUNC(setFuel); }; - // Main Action private _action = [QGVAR(Refuel), localize LSTRING(Refuel),