For developers
Eleven Combustible exports for FiveM: SetFuel, GetFuel, prices per station, the fuel statebag for HUDs and garages, and the sale event for businesses.
Eleven Combustible ships exports and an event so your business, economy or mechanic scripts can work with it. The resource name is eleven-combustible. To install it, see Installation; the script is in the store.
Prices
Prices are resolved in this order, and the first one that returns a value wins:
- The handlers registered with
RegisterPriceHandler. - The price set with
SetPricefor that station (or for all of them). - The
priceinConfig.FuelTypestimes the station'smultiplier(Config.Stations).
Every price is per litre. stationId is the id of a Config.Stations zone; outside every zone it's nil.
SetPrice
Server. Sets a fuel's price per litre at a station. With stationId set to nil, it applies to every station that doesn't have its own.
-- Premium at 2.10 at Grove Street
exports['eleven-combustible']:SetPrice('grove', 'premium', 2.10)
-- Diesel at 1.75 at every station
exports['eleven-combustible']:SetPrice(nil, 'diesel', 1.75)
To remove it and go back to the config price, use ClearPrice(stationId, fuelType):
exports['eleven-combustible']:ClearPrice('grove', 'premium')
RegisterPriceHandler
Server. Registers a function that decides the price on every lookup. It gets a table with stationId, fuelType, coords (of the pump) and source (the player). Return a number to set the price, or nil to let the next step decide.
exports['eleven-combustible']:RegisterPriceHandler(function(data)
-- The Grove station is run by a player business
if data.stationId == 'grove' then
return MyBusiness.priceOf(data.fuelType) -- nil = normal price
end
end)
Note
The handler runs every time the pump screen opens or someone pays. Keep it fast: no slow database queries inside.
GetPrice
Server. Returns a fuel's price per litre at a position, with all the rules above.
local price = exports['eleven-combustible']:GetPrice('regular', vec3(-70.2, -1761.8, 29.5))
Fuel level
The level goes from 0 to 100 (percentage of the tank).
SetFuel and GetFuel
On the server they take the vehicle's server entity handle:
local veh = NetworkGetEntityFromNetworkId(netId)
exports['eleven-combustible']:SetFuel(veh, 100.0)
local level = exports['eleven-combustible']:GetFuel(veh) -- may be nil if it has no level yet
On the client they take the local vehicle:
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
exports['eleven-combustible']:SetFuel(veh, 50.0)
local level = exports['eleven-combustible']:GetFuel(veh)
With Config.FuelSystem in a bridge mode, the level is also read from and written to the fuel system you use.
The fuel and fuelWrong statebags
Every vehicle carries two statebags you can read from any script, on the client or the server:
| Statebag | What it is |
|---|---|
fuel | Level from 0 to 100. Empty if the vehicle has no level yet |
fuelWrong | Share of the tank with the wrong fuel, from 0 to 1. Empty if there's no mix |
local level = Entity(vehicle).state.fuel
With the built-in system ('builtin') and with ox_fuel, the resource keeps GetVehicleFuelLevel in line with the statebag on every client. So HUDs that read the game's level work with no changes.
Warning
Eleven Combustible doesn't provide other systems' exports. If you remove LegacyFuel and a HUD or garage calls exports['LegacyFuel']:GetFuel, you'll get No such export GetFuel in resource LegacyFuel. Replace that call with exports['eleven-combustible']:GetFuel (see Installation).
ClearWrongFuel
Server. Clears a vehicle's wrong-fuel mix straight away (for example, when a mechanic drains the tank).
exports['eleven-combustible']:ClearWrongFuel(veh)
Refuels in progress
GetActiveRefuels
Server. Returns the refuels in progress, one per pump:
for pumpKey, r in pairs(exports['eleven-combustible']:GetActiveRefuels()) do
print(pumpKey, r.owner, r.fuelLabel, r.phase, r.paid)
end
| Field | What it is |
|---|---|
netId | Vehicle network id |
ident / owner | Identifier and name of whoever paid |
phase | 'waiting' (waiting for the hose) or 'running' (filling) |
kind | 'road' or 'air' |
fuelType / fuelLabel | Chosen fuel |
startFuel / target | Level at the start and level it will reach (in %) |
rate | Fill speed (% per second) |
price / paid | Price per litre and amount paid |
capacity | Tank litres |
x, y, z | Pump position |
Sale event
eleven-combustible:sale
Server. Fires every time a refuel ends with some fuel pumped, with the amount for what was pumped (refunds already taken off). Use it to pay the station, keep stats or charge taxes.
AddEventHandler('eleven-combustible:sale', function(sale)
if sale.stationId == 'grove' then
MyBusiness.deposit('grove', sale.amount)
end
print(('%s L of %s for %s (%s)'):format(sale.liters, sale.fuelType, sale.amount, sale.account))
end)
| Field | What it is |
|---|---|
source | Player who paid (nil if no longer online) |
identifier | Identifier of the character who paid |
stationId | Station id (nil outside the Config.Stations zones) |
coords | Pump position |
kind | 'road' or 'air' |
fuelType | Fuel key ('regular', 'jeta1'…) |
liters | Litres pumped |
amount | Amount charged for those litres |
account | 'cash' or 'bank' |
Note
It's a local server event (AddEventHandler), not a network one. It doesn't fire if the refuel is cancelled without pumping anything, nor when the resource stops.