diff --git a/README.md b/README.md index e1c62f0..36de8a8 100644 --- a/README.md +++ b/README.md @@ -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**. diff --git a/client/fuel_cl.lua b/client/fuel_cl.lua index 1e9b1bb..4d20072 100644 --- a/client/fuel_cl.lua +++ b/client/fuel_cl.lua @@ -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 @@ -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 @@ -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 @@ -2620,8 +2620,11 @@ 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 @@ -2629,29 +2632,31 @@ CreateThread(function() 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 @@ -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) \ No newline at end of file diff --git a/client/utils.lua b/client/utils.lua index bf19f97..9af547e 100644 --- a/client/utils.lua +++ b/client/utils.lua @@ -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 \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index e6c94f9..c72de11 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -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', diff --git a/shared/config.lua b/shared/config.lua index 07fb211..f7d1c6a 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -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. diff --git a/version b/version index ac2cdeb..7d2ed7c 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.1.3 +2.1.4