diff --git a/client.lua b/client.lua index d2417b4..975c5f2 100644 --- a/client.lua +++ b/client.lua @@ -865,17 +865,26 @@ local function updateVehicleHud(data) end local lastFuelUpdate = 0 -local lastFuelCheck = {} +local lastFuelCheck = 0 local function getFuelLevel(vehicle) local updateTick = GetGameTimer() + if (updateTick - lastFuelUpdate) > 2000 then lastFuelUpdate = updateTick - lastFuelCheck = math.floor(exports[Config.FuelScript]:GetFuel(vehicle)) + + if Config.FuelScript == "ox_fuel" then + lastFuelCheck = math.floor(Entity(vehicle).state.fuel or 0) -- Default to 0 if fuel state is not set + elseif Config.FuelScript == "ps-fuel" then + lastFuelCheck = math.floor(exports[Config.FuelScript]:GetFuel(vehicle) or 0) -- Default to 0 if GetFuel returns nil + end end + return lastFuelCheck end + + -- HUD Update loop CreateThread(function() @@ -1048,12 +1057,23 @@ CreateThread(function() while true do if LocalPlayer.state.isLoggedIn then local ped = PlayerPedId() - if IsPedInAnyVehicle(ped, false) and not IsThisModelABicycle(GetEntityModel(GetVehiclePedIsIn(ped, false))) and not isElectric(GetVehiclePedIsIn(ped, false)) then - if exports[Config.FuelScript]:GetFuel(GetVehiclePedIsIn(ped, false)) <= 20 then -- At 20% Fuel Left - if Menu.isLowFuelChecked then + local vehicle = GetVehiclePedIsIn(ped, false) + + if IsPedInAnyVehicle(ped, false) and vehicle ~= 0 then + local model = GetEntityModel(vehicle) + + if not IsThisModelABicycle(model) and not isElectric(vehicle) then + local fuelLevel + if Config.FuelScript == "ox_fuel" then + fuelLevel = Entity(vehicle).state.fuel + elseif Config.FuelScript == "ps-fuel" then + fuelLevel = exports[Config.FuelScript]:GetFuel(vehicle) + end + + if fuelLevel and fuelLevel <= 20 and Menu.isLowFuelChecked then TriggerServerEvent("InteractSound_SV:PlayOnSource", "pager", 0.10) QBCore.Functions.Notify(Lang:t("notify.low_fuel"), "error") - Wait(60000) -- repeats every 1 min until empty + Wait(60000) -- Wait 1 minute before re-checking end end end @@ -1062,6 +1082,7 @@ CreateThread(function() end end) + -- Money HUD RegisterNetEvent('hud:client:ShowAccounts', function(type, amount) diff --git a/config.lua b/config.lua index f3bdf89..cb6d12c 100644 --- a/config.lua +++ b/config.lua @@ -7,7 +7,10 @@ Config.MinimumStress = 50 -- Minimum Stress Level For Screen Shaking Config.MinimumSpeedUnbuckled = 50 -- Going Over This Speed Will Cause Stress Config.MinimumSpeed = 100 -- Going Over This Speed Will Cause Stress Config.DisablePoliceStress = false -- Default: false, If true will disable stress for people with the police job -Config.FuelScript = 'LegacyFuel' -- change to lj-fuel if you use lj-fuel or something else if you use any other LegcyFuel compatible script + + +-- Specify which fuel script to use: "ox_fuel", "ps-fuel", or "LegacyFuel" +Config.FuelScript = "ps-fuel" -- Admin only to change hud icons/shapes Config.AdminOnly = false