Skip to content

Commit

Permalink
Fix Issue with Config.NoFuelUsage & Add IsVehicleBlacklisted function.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnelyk authored May 28, 2023
2 parents 01fe459 + bca8012 commit 8dad29b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Codine Development Fuel Script Banner](https://i.imgur.com/qVOMMvW.png)

# _CDN-Fuel (2.1.3)_
# _CDN-Fuel (2.1.4)_

A highly in-depth fuel system for **FiveM** with support for the **QBCore Framework & QBox Remastered**.

Expand Down
75 changes: 42 additions & 33 deletions client/fuel_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ if Config.FuelDebug then
RegisterCommand('getCachedFuelPrice', function ()
print(CachedFuelPrice)
end, false)

RegisterCommand('getVehNameForBlacklist', function()
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
if veh ~= 0 then
print(string.lower(GetDisplayNameFromVehicleModel(GetEntityModel(veh))))
end
end, false)
end

-- Functions
Expand Down Expand Up @@ -104,7 +111,6 @@ local function HandleFuelConsumption(vehicle)
SetFuel(vehicle, math.random(200, 800) / 10)
elseif not fuelSynced then
SetFuel(vehicle, GetFuel(vehicle))

fuelSynced = true
end

Expand Down Expand Up @@ -252,13 +258,7 @@ CreateThread(function()
-- Blacklist Electric Vehicles, if you disables the Config.ElectricVehicleCharging or put the vehicle in Config.NoFuelUsage!
if IsPedInAnyVehicle(ped) then
local vehicle = GetVehiclePedIsIn(ped)
if Config.ElectricVehicles[GetEntityModel(vehicle)] and not Config.ElectricVehicleCharging then
inBlacklisted = true
elseif Config.NoFuelUsage[GetEntityModel(vehicle)] then
inBlacklisted = true
else
inBlacklisted = false
end
inBlacklisted = IsVehicleBlacklisted(vehicle)
if not inBlacklisted and GetPedInVehicleSeat(vehicle, -1) == ped then
HandleFuelConsumption(vehicle)
end
Expand Down Expand Up @@ -2620,38 +2620,43 @@ CreateThread(function()
while true do
Wait(3000)
local vehPedIsIn = GetVehiclePedIsIn(PlayerPedId(), false)
if not vehPedIsIn then
if not vehPedIsIn or vehPedIsIn == 0 then
Wait(2500)
if inBlacklisted then
inBlacklisted = false
end
else
local vehType = GetCurrentVehicleType(vehPedIsIn)
if not Config.ElectricVehicleCharging and vehType == 'electricvehicle' then
if Config.FuelDebug then
print("Vehicle Type is Electric, so we will not remove shut the engine off.")
end
else
local vehFuelLevel = GetFuel(vehPedIsIn)
local vehFuelShutoffLevel = Config.VehicleShutoffOnLowFuel['shutOffLevel'] or 1
if vehFuelLevel <= vehFuelShutoffLevel then
if GetIsVehicleEngineRunning(vehPedIsIn) then
if Config.FuelDebug then
print("Vehicle is running with zero fuel, shutting it down.")
if not IsVehicleBlacklisted(vehPedIsIn) then
local vehFuelLevel = GetFuel(vehPedIsIn)
local vehFuelShutoffLevel = Config.VehicleShutoffOnLowFuel['shutOffLevel'] or 1
if vehFuelLevel <= vehFuelShutoffLevel then
if GetIsVehicleEngineRunning(vehPedIsIn) then
if Config.FuelDebug then
print("Vehicle is running with zero fuel, shutting it down.")
end
-- If the vehicle is on, we shut the vehicle off:
SetVehicleEngineOn(vehPedIsIn, false, true, true)
-- Then alert the client with notify.
QBCore.Functions.Notify(Lang:t("no_fuel"), 'error', 3500)
-- Play Sound, if enabled in config.
if Config.VehicleShutoffOnLowFuel['sounds']['enabled'] then
RequestAmbientAudioBank("DLC_PILOT_ENGINE_FAILURE_SOUNDS", 0)
PlaySoundFromEntity(l_2613, "Landing_Tone", vehPedIsIn, "DLC_PILOT_ENGINE_FAILURE_SOUNDS", 0, 0)
Wait(1500)
StopSound(l_2613)
end
end
-- If the vehicle is on, we shut the vehicle off:
SetVehicleEngineOn(vehPedIsIn, false, true, true)
-- Then alert the client with notify.
QBCore.Functions.Notify(Lang:t("no_fuel"), 'error', 3500)
-- Play Sound, if enabled in config.
if Config.VehicleShutoffOnLowFuel['sounds']['enabled'] then
RequestAmbientAudioBank("DLC_PILOT_ENGINE_FAILURE_SOUNDS", 0)
PlaySoundFromEntity(l_2613, "Landing_Tone", vehPedIsIn, "DLC_PILOT_ENGINE_FAILURE_SOUNDS", 0, 0)
Wait(1500)
StopSound(l_2613)
else
if vehFuelLevel - 10 > vehFuelShutoffLevel then
Wait(7500)
end
end
else
if vehFuelLevel - 10 > vehFuelShutoffLevel then
Wait(7500)
end
end
end
end
Expand All @@ -2669,10 +2674,14 @@ CreateThread(function()
Wait(0)
local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)
if IsPedInVehicle(ped, veh, false) and (GetIsVehicleEngineRunning(veh) == false) or GetFuel(veh) < (Config.VehicleShutoffOnLowFuel['shutOffLevel'] or 1) then
DisableControlAction(0, 71, true)
elseif IsPedInVehicle(ped, veh, false) and (GetIsVehicleEngineRunning(veh) == true) and GetFuel(veh) > (Config.VehicleShutoffOnLowFuel['shutOffLevel'] or 1) then
EnableControlAction(0, 71, true)
if veh ~= 0 then
if not IsVehicleBlacklisted(veh) then
if IsPedInVehicle(ped, veh, false) and (GetIsVehicleEngineRunning(veh) == false) or GetFuel(veh) < (Config.VehicleShutoffOnLowFuel['shutOffLevel'] or 1) then
DisableControlAction(0, 71, true)
elseif IsPedInVehicle(ped, veh, false) and (GetIsVehicleEngineRunning(veh) == true) and GetFuel(veh) > (Config.VehicleShutoffOnLowFuel['shutOffLevel'] or 1) then
EnableControlAction(0, 71, true)
end
end
end
end
end)
35 changes: 35 additions & 0 deletions client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,39 @@ function IsPlayerNearVehicle()
return true
end
return false
end

function IsVehicleBlacklisted(veh)
if Config.FuelDebug then print("checking if vehicle is blacklisted") end
if veh and veh ~= 0 then
veh = string.lower(GetDisplayNameFromVehicleModel(GetEntityModel(veh)))
if Config.FuelDebug then print(veh) end
-- Puts Vehicles In Blacklist if you have electric charging on.
if not Config.ElectricVehicleCharging then
for i = 1, #Config.ElectricVehicles, 1 do
local cur = Config.ElectricVehicles[i]
if cur == veh then
print("Vehicle: "..cur.." is in the Blacklist.")
return true
end
end
end

for i = 1, #Config.NoFuelUsage, 1 do
local cur = Config.NoFuelUsage[i]
if cur == veh then
if Config.FuelDebug then
print("Vehicle: "..cur.." is in the Blacklist.")
end
-- If the veh equals a vehicle in the list then return true.
return true
end
end
-- Default False
if Config.FuelDebug then print("Vehicle is not blacklisted.") end
return false
else
if Config.FuelDebug then print("veh is nil!") end
return false
end
end
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version 'cerulean'
game 'gta5'
author 'https://www.github.com/CodineDev' -- Base Refueling System: (https://github.com/InZidiuZ/LegacyFuel), other code by Codine (https://www.github.com/CodineDev).
description 'cdn-fuel'
version '2.1.3'
version '2.1.4'

client_scripts {
'@PolyZone/client.lua',
Expand Down
5 changes: 2 additions & 3 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ Config.ElectricSprite = 620 -- This is for when the player is in an electric cha
Config.ElectricChargerModel = true -- If you wish, you can set this to false to add your own props, or use a ymap for the props instead.

-- Basic Configuration Settings
-- Turn on Config.FuelDebug and use this command to get the name for here: getVehNameForBlacklist
Config.NoFuelUsage = { -- This is for you to put vehicles that you don't want to use fuel.
"example",
"example",
"example",
"bmx",
}

Config.Classes = { -- Class multipliers. If you want SUVs to use less fuel, you can change it to anything under 1.0, and vise versa.
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
2.1.4

0 comments on commit 8dad29b

Please sign in to comment.