diff --git a/addons/refuel/CfgVehicles.hpp b/addons/refuel/CfgVehicles.hpp index 7d8b7111c2..8e57bf1f63 100644 --- a/addons/refuel/CfgVehicles.hpp +++ b/addons/refuel/CfgVehicles.hpp @@ -74,7 +74,7 @@ class ACE_Actions { \ class ACE_MainActions { \ displayName = CSTRING(Refuel); \ - distance = 3; \ + distance = REFUEL_ACTION_DISTANCE; \ condition = "true"; \ statement = ""; \ showDisabled = 0; \ diff --git a/addons/refuel/XEH_preInit.sqf b/addons/refuel/XEH_preInit.sqf index 5250f09f11..691df0478d 100644 --- a/addons/refuel/XEH_preInit.sqf +++ b/addons/refuel/XEH_preInit.sqf @@ -22,6 +22,7 @@ PREP(moduleRefuelSettings); PREP(readFuelCounter); PREP(refuel); PREP(reset); +PREP(resetLocal); PREP(returnNozzle); PREP(setFuel); PREP(takeNozzle); diff --git a/addons/refuel/functions/fnc_refuel.sqf b/addons/refuel/functions/fnc_refuel.sqf index c69f3f84cf..ed6eb257cf 100644 --- a/addons/refuel/functions/fnc_refuel.sqf +++ b/addons/refuel/functions/fnc_refuel.sqf @@ -37,7 +37,7 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f _sink setVariable [QGVAR(nozzle), objNull, true]; [_pfID] call cba_fnc_removePerFrameHandler; }; - _tooFar = ((_sink modelToWorld _connectToPoint) distance (_source modelToWorld _connectFromPoint)) > 10; + _tooFar = ((_sink modelToWorld _connectToPoint) distance (_source modelToWorld _connectFromPoint)) > (REFUEL_HOSE_LENGTH - 2); if (_tooFar) exitWith { [LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured); diff --git a/addons/refuel/functions/fn_reset.sqf b/addons/refuel/functions/fnc_reset.sqf similarity index 67% rename from addons/refuel/functions/fn_reset.sqf rename to addons/refuel/functions/fnc_reset.sqf index f27e0e9613..f235180b0e 100644 --- a/addons/refuel/functions/fn_reset.sqf +++ b/addons/refuel/functions/fnc_reset.sqf @@ -15,17 +15,18 @@ */ #include "script_component.hpp" +private ["_nozzle", "_nozzleTarget", "_rope"]; params ["_target"]; -if !(local _target) then { - [[_target, ["HitEngine", _target getVariable [QGVAR(engineHit), 0]]], "{(_this select 0) setHitPointDamage (_this select 1)}", _sink] call EFUNC(common,execRemoteFnc); -} else { +if (local _target) then { _target setHitPointDamage ["HitEngine", _target getVariable [QGVAR(engineHit), 0]]; +} else { + [[_target, ["HitEngine", _target getVariable [QGVAR(engineHit), 0]]], "{(_this select 0) setHitPointDamage (_this select 1)}", _target] call EFUNC(common,execRemoteFnc); }; _target setVariable [QGVAR(engineHit), nil, true]; _target setVariable [QGVAR(isConnected), false, true]; -_nozzle = _target getVariable [QGVAR(nozzle), nil]; +_nozzle = _target getVariable [QGVAR(ownedNozzle), nil]; if !(isNil "_nozzle") then { _nozzleTarget = _nozzle getVariable [QGVAR(sink), nil]; if !(isNil "_nozzleTarget") then { @@ -38,14 +39,12 @@ if !(isNil "_nozzle") then { }; { - // FIXME needs to be done locally - _actionID = _x getVariable [QGVAR(ReleaseActionID), -1]; - if (_actionID != -1) then { - _x removeAction _actionID; - _x setVariable [QGVAR(isRefueling), false, true]; - _x setVariable [QGVAR(ReleaseActionID), nil]; + if (local _x) then { + [_x, _nozzle] call FUNC(resetLocal); + } else { + [[_x, _nozzle], "{_this call FUNC(resetLocal)}", _x] call EFUNC(common,execRemoteFnc); }; } count allPlayers; deleteVehicle _nozzle; }; -_target getVariable [QGVAR(nozzle), nil, true]; +_target setVariable [QGVAR(ownedNozzle), nil, true]; diff --git a/addons/refuel/functions/fnc_resetLocal.sqf b/addons/refuel/functions/fnc_resetLocal.sqf new file mode 100644 index 0000000000..a8b0c184cc --- /dev/null +++ b/addons/refuel/functions/fnc_resetLocal.sqf @@ -0,0 +1,37 @@ +/* + * Author: GitHawk + * Resets a player + * + * Arguments: + * 0: Fuel nozzle + * + * Return Value: + * None + * + * Example: + * [nozzle] call ace_refuel_fnc_resetLocal + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit", "_nozzle"]; + + +if (isNull _unit || + {isNull _nozzle} || + {!(_unit isKindOf "CAManBase")} || + {!local _unit}) exitWith {}; +private ["_attachedNozzle", "_actionID"]; +_attachedNozzle = _unit getVariable [QGVAR(nozzle), nil]; +if (isNil "_attachedNozzle") exitWith {}; + +if (_nozzle != _attachedNozzle) exitWith {}; + +_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; +if (_actionID != -1) then { + _unit removeAction _actionID; + _unit setVariable [QGVAR(isRefueling), false, true]; + _unit setVariable [QGVAR(ReleaseActionID), nil]; + _unit setVariable [QGVAR(nozzle), nil]; +}; diff --git a/addons/refuel/functions/fnc_returnNozzle.sqf b/addons/refuel/functions/fnc_returnNozzle.sqf index 6de80a8468..d3fca33021 100644 --- a/addons/refuel/functions/fnc_returnNozzle.sqf +++ b/addons/refuel/functions/fnc_returnNozzle.sqf @@ -43,7 +43,7 @@ if (isNull _nozzle || {_source != _target}) exitWith {false}; }; _target setVariable [QGVAR(isConnected), false, true]; - _target setVariable [QGVAR(nozzle), nil, true]; + _target setVariable [QGVAR(ownedNozzle), nil, true]; ropeDestroy (_nozzle getVariable QGVAR(rope)); deleteVehicle _nozzle; diff --git a/addons/refuel/functions/fnc_takeNozzle.sqf b/addons/refuel/functions/fnc_takeNozzle.sqf index 221984ba77..f6d953cecc 100644 --- a/addons/refuel/functions/fnc_takeNozzle.sqf +++ b/addons/refuel/functions/fnc_takeNozzle.sqf @@ -57,11 +57,11 @@ if (isNull _nozzle) then { // func is called on fuel truck _newNozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model _unit setVariable [QGVAR(nozzle), _newNozzle]; - _rope = ropeCreate [_target, _endPosOffset, _newNozzle, [0, 0, 0], 12]; + _rope = ropeCreate [_target, _endPosOffset, _newNozzle, [0, 0, 0], REFUEL_HOSE_LENGTH]; _newNozzle setVariable [QGVAR(attachPos), _endPosOffset, true]; _newNozzle setVariable [QGVAR(source), _target, true]; _newNozzle setVariable [QGVAR(rope), _rope, true]; - _target setVariable [QGVAR(nozzle), _newNozzle, true]; + _target setVariable [QGVAR(ownedNozzle), _newNozzle, true]; _unit setVariable [QGVAR(isRefueling), true]; _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; @@ -127,7 +127,7 @@ if (isNull _nozzle) then { // func is called on fuel truck params ["_args", "_pfID"]; _args params ["_unit", "_source", "_endPosOffset"]; - if (_unit distance (_source modelToWorld _endPosOffset) > 10) exitWith { + if (_unit distance (_source modelToWorld _endPosOffset) > (REFUEL_HOSE_LENGTH - 2)) exitWith { _nozzle = _unit getVariable [QGVAR(nozzle), objNull]; if !(isNull _nozzle) then { [_unit, _nozzle] call FUNC(dropNozzle); diff --git a/addons/refuel/script_component.hpp b/addons/refuel/script_component.hpp index 9027c22fae..28e6fb7931 100644 --- a/addons/refuel/script_component.hpp +++ b/addons/refuel/script_component.hpp @@ -12,7 +12,8 @@ #include "\z\ace\addons\main\script_macros.hpp" #define REFUEL_INFINITE_FUEL -1 -#define REFUEL_ACTION_DISTANCE 7 +#define REFUEL_ACTION_DISTANCE 37 +#define REFUEL_HOSE_LENGTH 12 #define REFUEL_HOLSTER_WEAPON \ _unit setVariable [QGVAR(selectedWeaponOnRefuel), currentWeapon _unit]; \