diff --git a/addons/refuel/XEH_PREP.hpp b/addons/refuel/XEH_PREP.hpp index 806d861a69..282b008fca 100644 --- a/addons/refuel/XEH_PREP.hpp +++ b/addons/refuel/XEH_PREP.hpp @@ -14,6 +14,7 @@ PREP(dropNozzle); PREP(getFuel); PREP(handleDisconnect); PREP(handleKilled); +PREP(handlePlayerWeaponChanged); PREP(handleUnconscious); PREP(makeJerryCan); PREP(maxDistanceDropNozzle); diff --git a/addons/refuel/XEH_postInit.sqf b/addons/refuel/XEH_postInit.sqf index 89a1f3dc45..f0fb928187 100644 --- a/addons/refuel/XEH_postInit.sqf +++ b/addons/refuel/XEH_postInit.sqf @@ -1,6 +1,7 @@ #include "script_component.hpp" ["ace_unconscious", {_this call FUNC(handleUnconscious)}] call CBA_fnc_addEventHandler; +["weapon", FUNC(handlePlayerWeaponChanged)] call CBA_fnc_addPlayerEventHandler; if (isServer) then { addMissionEventHandler ["HandleDisconnect", {_this call FUNC(handleDisconnect)}]; diff --git a/addons/refuel/functions/fnc_handlePlayerWeaponChanged.sqf b/addons/refuel/functions/fnc_handlePlayerWeaponChanged.sqf new file mode 100644 index 0000000000..57897aef89 --- /dev/null +++ b/addons/refuel/functions/fnc_handlePlayerWeaponChanged.sqf @@ -0,0 +1,29 @@ +/* + * Author: Jonpas + * Drops nozzle or jerry can when selecting a weapon. + * + * Arguments: + * 0: Unit + * 1: Weapon (unused) + * + * Return Value: + * None + * + * Example: + * [_unit, "gun"] call ace_refuel_fnc_handlePlayerWeaponChanged; + * + * Public: No +*/ +#include "script_component.hpp" + +params ["_unit"]; + +// Drop nozzle/jerry can when selecting a non-primary weapon +if (_unit getVariable [QGVAR(isRefueling), false]) then { + private _nozzle = _unit getVariable [QGVAR(nozzle), objNull]; + if !(isNull _nozzle) then { + [_unit, _nozzle] call FUNC(dropNozzle); + _unit setVariable [QGVAR(selectedWeaponOnRefuel), nil]; + [_unit, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set); + }; +}; diff --git a/addons/refuel/functions/fnc_maxDistanceDropNozzle.sqf b/addons/refuel/functions/fnc_maxDistanceDropNozzle.sqf index 90231a30f2..687af9e072 100644 --- a/addons/refuel/functions/fnc_maxDistanceDropNozzle.sqf +++ b/addons/refuel/functions/fnc_maxDistanceDropNozzle.sqf @@ -33,6 +33,10 @@ if (_nozzle getVariable [QGVAR(jerryCan), false]) exitWith {}; ["_nozzle", (_args select 0) getVariable [QGVAR(nozzle), objNull], [objNull]] ]; + if (_unit getVariable [QGVAR(isRefueling), false]) exitWith { + [_pfID] call CBA_fnc_removePerFrameHandler; + }; + if (isNull _source || {_unit distance (_source modelToWorld _endPosOffset) > (REFUEL_HOSE_LENGTH - 2)} || {!alive _source}) exitWith { if !(isNull _nozzle) then { [_unit, _nozzle] call FUNC(dropNozzle);