Skip to content
Open
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
18 changes: 16 additions & 2 deletions client/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
local config = require 'config'
local vehicles = require 'data.vehicles'

if not config then return end

SetFuelConsumptionState(true)
SetFuelConsumptionRateMultiplier(config.globalFuelConsumptionRate)
if config.globalFuelConsumptionRate then
SetFuelConsumptionRateMultiplier(config.globalFuelConsumptionRate)
end

AddTextEntry('fuelHelpText', locale('fuel_help'))
AddTextEntry('petrolcanHelpText', locale('petrolcan_help'))
Expand All @@ -18,6 +21,7 @@ require 'client.stations'

local function startDrivingVehicle()
local vehicle = cache.vehicle
local vehicleModel = GetEntityModel(vehicle)

if not DoesVehicleUseFuel(vehicle) then return end

Expand All @@ -28,14 +32,24 @@ local function startDrivingVehicle()
while not vehState.fuel do Wait(0) end
end

-- Create locallized value for the thread to define the consumptionRate
local consumptionRate = config.globalFuelConsumptionRate
if type(vehicles.models[vehicleModel]) == 'number' then
consumptionRate = vehicles.models[vehicleModel]
else
local class = GetVehicleClass(vehicle)

consumptionRate = vehicles[class]
end

SetVehicleFuelLevel(vehicle, vehState.fuel)

local fuelTick = 0

while cache.seat == -1 do
if GetIsVehicleEngineRunning(vehicle) then
if not DoesEntityExist(vehicle) then return end
SetFuelConsumptionRateMultiplier(config.globalFuelConsumptionRate)
SetFuelConsumptionRateMultiplier(consumptionRate)

local fuelAmount = tonumber(vehState.fuel)
local newFuel = GetVehicleFuelLevel(vehicle)
Expand Down
3 changes: 2 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ return {
refillPrice = 800,
},

---Modifies the fuel consumption rate of all vehicles - see [`SET_FUEL_CONSUMPTION_RATE_MULTIPLIER`](https://docs.fivem.net/natives/?_0x845F3E5C).
-- Setting this to a number, will use a global rate for all vehicles, setting it to false will use the data in `data/vehicles.lua`
-- Modifies the fuel consumption rate of all vehicles - see [`SET_FUEL_CONSUMPTION_RATE_MULTIPLIER`](https://docs.fivem.net/natives/?_0x845F3E5C).
globalFuelConsumptionRate = 10.0,

-- Gas pump models
Expand Down
31 changes: 31 additions & 0 deletions data/vehicles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
return {
-- Modifies the fuel consumption rate of all vehicles
-- see [`SET_FUEL_CONSUMPTION_RATE_MULTIPLIER`](https://docs.fivem.net/natives/?_0x845F3E5C).
[0] = 9.0, -- Compact
[1] = 10.0, -- Sedan
[2] = 11.0, -- SUV
[3] = 10.0, -- Coupe
[4] = 12.0, -- Muscle
[5] = 11.5, -- Sports Classic
[6] = 12.5, -- Sports
[7] = 14.0, -- Super
[8] = 7.0, -- Motorcycle
[9] = 11.5, -- Offroad
[10] = 13.0, -- Industrial
[11] = 11.0, -- Utility
[12] = 10.5, -- Van
[14] = 6.0, -- Boat
[15] = 15.0, -- Helicopter
[16] = 16.0, -- Plane
[17] = 10.5, -- Service
[18] = 9.0, -- Emergency
[19] = 13.5, -- Military
[20] = 14.5, -- Commercial (trucks)
models = {
[GetHashKey('tug')] = 14.0,
[GetHashKey('kosatka')] = 16.0,
[GetHashKey('seashark')] = 3.0,
[GetHashKey('seashark2')] = 3.0,
[GetHashKey('seashark3')] = 3.0,
},
}
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ client_script 'client/init.lua'

files {
'locales/*.json',
'data/stations.lua',
'data/*.lua',
'client/*.lua',
}

Expand Down