Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client.lua #125

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -1062,6 +1082,7 @@ CreateThread(function()
end
end)


-- Money HUD

RegisterNetEvent('hud:client:ShowAccounts', function(type, amount)
Expand Down
5 changes: 4 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down