mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-13 19:52:38 +03:00
Fix infinite refueling with the fuel pump
This commit is contained in:
@@ -1,79 +1,120 @@
|
|||||||
if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
|
if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
|
||||||
dayz_actionInProgress = true;
|
dayz_actionInProgress = true;
|
||||||
|
|
||||||
private ["_isFuelTruck","_fuelTruckCapacity","_finished","_newFuel","_abort","_newFuelSrc","_canSize","_vehicle","_configVeh","_capacity","_nameText","_fuelTruck","_findNearestVehicle"];
|
local _isFuelTruck = [false,true] select ((_this select 3 select 0) == 2);
|
||||||
|
local _fuelSource = _this select 3 select 1;
|
||||||
|
if (isNull _fuelSource) exitWith {dayz_actionInProgress = false; systemChat localize "str_cursorTargetNotFound";};
|
||||||
|
|
||||||
_fuelTruck = _this select 3;
|
local _typeFuelSource = typeOf _fuelSource;
|
||||||
_abort = false;
|
local _abort = false;
|
||||||
|
local _fuelSourceCapacity = 0;
|
||||||
|
local _pos = [_fuelSource] call fnc_getPos;
|
||||||
|
local _fuelSourceFound = true;
|
||||||
|
|
||||||
if (!isNull _fuelTruck) then {
|
if (_isFuelTruck) then {
|
||||||
_isFuelTruck = true;
|
_fuelSourceCapacity = getNumber (configFile >> "cfgVehicles" >> _typeFuelSource >> "fuelCapacity");
|
||||||
// If fuel source is vehicle get actual capacity
|
} else {
|
||||||
_fuelTruckCapacity = getNumber (configFile >> "cfgVehicles" >> typeOf _fuelTruck >> "fuelCapacity");
|
if (_typeFuelSource == "FuelPump_DZ") then {
|
||||||
} else {
|
local _findNearestFuel = [];
|
||||||
_isFuelTruck = false;
|
|
||||||
|
{
|
||||||
|
if (_x != _fuelSource && {!(_x isKindOf "StaticWeapon") && {!(typeOf _x in DZE_StaticWeapons)}}) exitWith {
|
||||||
|
_findNearestFuel set [count _findNearestFuel,_x];
|
||||||
|
};
|
||||||
|
} foreach nearestObjects [_pos,DayZ_fuelSources,10];
|
||||||
|
|
||||||
|
if (count _findNearestFuel > 0) then {
|
||||||
|
_fuelSource = _findNearestFuel select 0;
|
||||||
|
} else {
|
||||||
|
_fuelSourceFound = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
_fuelSourceCapacity = _fuelSource getVariable "FuelAmount";
|
||||||
|
|
||||||
|
if (isNil "_fuelSourceCapacity" && _fuelSourceFound) then {
|
||||||
|
_fuelSourceCapacity = floor(random dayz_randomMaxFuelAmount) max (dayz_randomMaxFuelAmount * 0.10);
|
||||||
|
_fuelSource setVariable ["FuelAmount",_fuelSourceCapacity, true];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
_findNearestVehicle = [];
|
if !(_fuelSourceFound) exitwith {dayz_actionInProgress = false;localize "str_epoch_player_131_1" call dayz_rollingMessages;};
|
||||||
{
|
|
||||||
if (_x != _fuelTruck) exitWith {
|
|
||||||
_findNearestVehicle set [(count _findNearestVehicle),_x];
|
|
||||||
};
|
|
||||||
} count (([player] call fnc_getPos) nearEntities [["Air","LandVehicle","Ship"],30]);
|
|
||||||
|
|
||||||
if (count _findNearestVehicle >= 1) then {
|
local _findNearestVehicle = [];
|
||||||
|
|
||||||
|
{
|
||||||
|
if (_x != _fuelSource && {!(_x isKindOf "StaticWeapon") && {!(typeOf _x in DZE_StaticWeapons)}}) exitWith {
|
||||||
|
_findNearestVehicle set [count _findNearestVehicle,_x];
|
||||||
|
};
|
||||||
|
} foreach nearestObjects [_pos,["Air","LandVehicle","Ship"],30]; // Using nearestObjects, because it is sorted by distance
|
||||||
|
|
||||||
|
if (count _findNearestVehicle > 0) then {
|
||||||
// select the nearest one
|
// select the nearest one
|
||||||
_vehicle = _findNearestVehicle select 0;
|
local _vehicle = _findNearestVehicle select 0;
|
||||||
|
|
||||||
// Static vehicle fuel information
|
// Static vehicle fuel information
|
||||||
_configVeh = configFile >> "cfgVehicles" >> TypeOf(_vehicle);
|
local _configVeh = configFile >> "cfgVehicles" >> typeOf(_vehicle);
|
||||||
_capacity = getNumber(_configVeh >> "fuelCapacity");
|
local _capacity = getNumber(_configVeh >> "fuelCapacity");
|
||||||
_nameText = getText(_configVeh >> "displayName");
|
local _canSize = (_capacity / 10);
|
||||||
|
local _nameText = getText(_configVeh >> "displayName");
|
||||||
|
local _newFuel = 0;
|
||||||
|
local _newFuelSrc = 0;
|
||||||
|
local _availableFuel = 0;
|
||||||
|
|
||||||
// perform fuel up
|
if (_isFuelTruck) then {
|
||||||
while {true} do {
|
_availableFuel = ((fuel _fuelSource) * _fuelSourceCapacity) - _canSize;
|
||||||
// qty to add per loop
|
} else {
|
||||||
_canSize = (_capacity / 10);
|
_availableFuel = _fuelSourceCapacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_availableFuel < 0) then {_availableFuel = (fuel _fuelSource) * _fuelSourceCapacity;};
|
||||||
|
|
||||||
|
if (_availableFuel < _canSize) exitwith {
|
||||||
|
format[localize "STR_EPOCH_PLAYER_131_2",_availableFuel,_canSize] call dayz_rollingMessages;
|
||||||
|
};
|
||||||
|
|
||||||
|
while {1==1} do {
|
||||||
format[localize "str_epoch_player_131",_nameText] call dayz_rollingMessages;
|
format[localize "str_epoch_player_131",_nameText] call dayz_rollingMessages;
|
||||||
[player,(getPosATL player),20,"refuel"] spawn fnc_alertZombies;
|
[player,(getPosATL player),20,"refuel"] spawn fnc_alertZombies;
|
||||||
_finished = ["Medic",1] call fn_loopAction;
|
|
||||||
|
local _finished = ["Medic",1] call fn_loopAction;
|
||||||
|
|
||||||
if (!_finished) then {
|
if (!_finished) then {
|
||||||
_abort = true;
|
_abort = true;
|
||||||
} else {
|
} else {
|
||||||
_newFuel = (((fuel _vehicle) * _capacity) + _canSize);
|
|
||||||
if (_isFuelTruck) then {
|
if (_isFuelTruck) then {
|
||||||
_newFuelSrc = ((((fuel _fuelTruck) * _fuelTruckCapacity) - _canSize) / _fuelTruckCapacity);
|
_newFuelSrc = ((((fuel _fuelSource) * _fuelSourceCapacity) - _canSize) / _fuelSourceCapacity);
|
||||||
if (_newFuelSrc > 0) then {
|
|
||||||
if (local _fuelTruck) then {
|
|
||||||
[_fuelTruck,_newFuelSrc] call local_setFuel;
|
|
||||||
} else {
|
|
||||||
PVDZ_send = [_fuelTruck,"SetFuel",[_fuelTruck,_newFuelSrc]];
|
|
||||||
publicVariableServer "PVDZ_send";
|
|
||||||
};
|
|
||||||
if (_newFuel >= _capacity) then {_newFuel = 1; _abort = true;} else {_newFuel = (_newFuel / _capacity);};
|
|
||||||
if (local _vehicle) then {
|
|
||||||
[_vehicle,_newFuel] call local_setFuel;
|
|
||||||
} else {
|
|
||||||
PVDZ_send = [_vehicle,"SetFuel",[_vehicle,_newFuel]];
|
|
||||||
publicVariableServer "PVDZ_send";
|
|
||||||
};
|
|
||||||
format[localize "str_epoch_player_132",_nameText,round(_newFuel*100)] call dayz_rollingMessages;
|
|
||||||
} else {
|
|
||||||
_abort = true;
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
//Filling near vehicle at gas station with generator
|
|
||||||
if (_newFuel >= _capacity) then {_newFuel = 1; _abort = true;} else {_newFuel = (_newFuel / _capacity);};
|
|
||||||
|
|
||||||
if (local _vehicle) then {
|
if (_newFuelSrc >= 0) then {
|
||||||
[_vehicle,_newFuel] call local_setFuel;
|
if (local _fuelSource) then {
|
||||||
} else {
|
[_fuelSource,_newFuelSrc] call local_setFuel;
|
||||||
PVDZ_send = [_vehicle,"SetFuel",[_vehicle,_newFuel]];
|
} else {
|
||||||
publicVariableServer "PVDZ_send";
|
PVDZ_send = [_fuelSource,"SetFuel",[_fuelSource,_newFuelSrc]];
|
||||||
};
|
publicVariableServer "PVDZ_send";
|
||||||
|
};
|
||||||
|
} else {_abort = true;};
|
||||||
|
} else {
|
||||||
|
local _fuelSourceCapacity = _fuelSource getVariable "FuelAmount";
|
||||||
|
_newFuelSrc = _fuelSourceCapacity - _canSize;
|
||||||
|
|
||||||
|
if (_newFuelSrc < 1) then {_newFuelSrc = 0;_abort = true;};
|
||||||
|
_fuelSource setVariable ["FuelAmount",_newFuelSrc, true];
|
||||||
|
};
|
||||||
|
|
||||||
|
_newFuel = (((fuel _vehicle) * _capacity) + _canSize);
|
||||||
|
|
||||||
|
if (_newFuel >= _capacity) then {_newFuel = 1; _abort = true;} else {_newFuel = (_newFuel / _capacity);};
|
||||||
|
|
||||||
|
if (local _vehicle) then {
|
||||||
|
[_vehicle,_newFuel] call local_setFuel;
|
||||||
|
} else {
|
||||||
|
PVDZ_send = [_vehicle,"SetFuel",[_vehicle,_newFuel]];
|
||||||
|
publicVariableServer "PVDZ_send";
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_isFuelTruck) then {
|
||||||
format[localize "str_epoch_player_132",_nameText,round(_newFuel*100)] call dayz_rollingMessages;
|
format[localize "str_epoch_player_132",_nameText,round(_newFuel*100)] call dayz_rollingMessages;
|
||||||
|
} else {
|
||||||
|
format[localize "STR_EPOCH_PLAYER_132_1",_nameText,round(_newFuel*100),_newFuelSrc] call dayz_rollingMessages;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,4 +126,5 @@ if (count _findNearestVehicle >= 1) then {
|
|||||||
} else {
|
} else {
|
||||||
localize "str_epoch_player_27" call dayz_rollingMessages;
|
localize "str_epoch_player_27" call dayz_rollingMessages;
|
||||||
};
|
};
|
||||||
dayz_actionInProgress = false;
|
|
||||||
|
dayz_actionInProgress = false;
|
||||||
@@ -716,7 +716,7 @@ if (!isNull _cursorTarget && _noChange && !_inVehicle && !_isPZombie && _canDo &
|
|||||||
if (s_player_fuelauto < 0) then {
|
if (s_player_fuelauto < 0) then {
|
||||||
local _findNearestGen = {((alive _x) && (_x getVariable ["GeneratorRunning",false]))} count (([player] call FNC_getPos) nearObjects ["Generator_DZ",30]);
|
local _findNearestGen = {((alive _x) && (_x getVariable ["GeneratorRunning",false]))} count (([player] call FNC_getPos) nearObjects ["Generator_DZ",30]);
|
||||||
if (_findNearestGen > 0) then {
|
if (_findNearestGen > 0) then {
|
||||||
s_player_fuelauto = player addAction [localize "STR_EPOCH_ACTIONS_FILLVEH", "\z\addons\dayz_code\actions\fill_nearestVehicle.sqf",objNull, 0, false, true];
|
s_player_fuelauto = player addAction [localize "STR_EPOCH_ACTIONS_FILLVEH", "\z\addons\dayz_code\actions\fill_nearestVehicle.sqf",[1,_cursorTarget], 0, false, true];
|
||||||
} else {
|
} else {
|
||||||
s_player_fuelauto = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_NEEDPOWER"], "",[], 0, false, true];
|
s_player_fuelauto = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_NEEDPOWER"], "",[], 0, false, true];
|
||||||
};
|
};
|
||||||
@@ -730,7 +730,7 @@ if (!isNull _cursorTarget && _noChange && !_inVehicle && !_isPZombie && _canDo &
|
|||||||
if (_isAlive && {_typeOfCursorTarget in DZE_fueltruckarray}) then {
|
if (_isAlive && {_typeOfCursorTarget in DZE_fueltruckarray}) then {
|
||||||
if (s_player_fuelauto2 < 0) then {
|
if (s_player_fuelauto2 < 0) then {
|
||||||
if (isEngineOn _cursorTarget) then {
|
if (isEngineOn _cursorTarget) then {
|
||||||
s_player_fuelauto2 = player addAction [localize "STR_EPOCH_ACTIONS_FILLVEH", "\z\addons\dayz_code\actions\fill_nearestVehicle.sqf",_cursorTarget, 0, false, true];
|
s_player_fuelauto2 = player addAction [localize "STR_EPOCH_ACTIONS_FILLVEH", "\z\addons\dayz_code\actions\fill_nearestVehicle.sqf",[2,_cursorTarget ], 0, false, true];
|
||||||
} else {
|
} else {
|
||||||
s_player_fuelauto2 = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_NEEDPOWER"], "",[], 0, false, true];
|
s_player_fuelauto2 = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_NEEDPOWER"], "",[], 0, false, true];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23864,6 +23864,14 @@
|
|||||||
<French>Remplissage de %1, déplacez vous pour annuler.</French>
|
<French>Remplissage de %1, déplacez vous pour annuler.</French>
|
||||||
<Czech>Plnění %1, pohněte se pro zrušení.</Czech>
|
<Czech>Plnění %1, pohněte se pro zrušení.</Czech>
|
||||||
</Key>
|
</Key>
|
||||||
|
<Key ID="STR_EPOCH_PLAYER_131_1">
|
||||||
|
<English>Abort refueling, no fuel source.</English>
|
||||||
|
<German>Betanken abgebrochen, es konnte keine Treibstoffquelle gefunden werden.</German>
|
||||||
|
</Key>
|
||||||
|
<Key ID="STR_EPOCH_PLAYER_131_2">
|
||||||
|
<English>Abort refueling, the fuel source has only %1 liters left. You need at least %2 liters of fuel.</English>
|
||||||
|
<German>Betanken abgebrochen, die Treibstoffquelle hat nur noch %1 Liter übrig. Benötigt werden %2 Liter Treibstoff.</German>
|
||||||
|
</Key>
|
||||||
<Key ID="STR_EPOCH_PLAYER_132">
|
<Key ID="STR_EPOCH_PLAYER_132">
|
||||||
<English>%1 filled to %2 percent capacity.</English>
|
<English>%1 filled to %2 percent capacity.</English>
|
||||||
<German>%1 wurde zu %2 Prozent betankt.</German>
|
<German>%1 wurde zu %2 Prozent betankt.</German>
|
||||||
@@ -23872,6 +23880,10 @@
|
|||||||
<French>%1 est rempli(e) à %2 pourcents de sa capacité.</French>
|
<French>%1 est rempli(e) à %2 pourcents de sa capacité.</French>
|
||||||
<Czech>%1 je naplněno do %2 procent kapacity.</Czech>
|
<Czech>%1 je naplněno do %2 procent kapacity.</Czech>
|
||||||
</Key>
|
</Key>
|
||||||
|
<Key ID="STR_EPOCH_PLAYER_132_1">
|
||||||
|
<English>%1 filled to %2 percent capacity. It is about %3 litres of fuel left in the fuel source.</English>
|
||||||
|
<German>%1 wurde zu %2 Prozent betankt. Es sind noch ca. %3 Liter Treibstoff in der Treibstoffquelle übrig.</German>
|
||||||
|
</Key>
|
||||||
<Key ID="STR_EPOCH_PLAYER_133">
|
<Key ID="STR_EPOCH_PLAYER_133">
|
||||||
<English>You can only own %1 plot pole(s)</English>
|
<English>You can only own %1 plot pole(s)</English>
|
||||||
<German>Du kannst nur %1 Grundstück(e) besitzen.</German>
|
<German>Du kannst nur %1 Grundstück(e) besitzen.</German>
|
||||||
|
|||||||
Reference in New Issue
Block a user