Read and set the fuel of a vehicle from your own resources, on the client or on the server. Fuel is always a percentage of the tank, from 0 to 100.
State bag
The fuel level of every vehicle is published in its state bag fuel (number, 0 to 100). It is replicated, so it can be read anywhere:
local level = Entity(vehicle).state.fuelThe value is nil until someone has driven the vehicle or a resource has set it. To write it, use the exports below.
Client exports
GetFuel
Returns the fuel level of a vehicle.
local level = exports.cuxial_fuel:GetFuel(vehicle)| Parameter | Type | Description |
|---|---|---|
vehicle | number | Vehicle entity. |
Returns: number, from 0 to 100. 0 when the vehicle does not exist.
if exports.cuxial_fuel:GetFuel(cache.vehicle) < 10 then
lib.notify({ description = 'Low fuel' })
endSetFuel
Sets the fuel level of a vehicle.
exports.cuxial_fuel:SetFuel(vehicle, value)| Parameter | Type | Description |
|---|---|---|
vehicle | number | Vehicle entity. |
value | number | Percentage. Clamped to 0–100. |
exports.cuxial_fuel:SetFuel(vehicle, 100.0)The level only reaches the other players when the client that calls the export owns the vehicle on the network, usually its driver. From any other client, use the server export.
SetFuelType
Sets the fuel type saved for a vehicle. It does not empty the tank.
exports.cuxial_fuel:SetFuelType(vehicle, fuel)| Parameter | Type | Description |
|---|---|---|
vehicle | number | Vehicle entity. It has to be networked. |
fuel | string | nil | 'regular', 'plus', 'premium', 'diesel', 'electric_fast' or 'electric_normal'. nil, '' or 'default' clears the saved type, and the vehicle goes back to the one of its model. |
The player has to be inside the vehicle or within distances.fuelType metres of it. The server accepts 5 changes every 10 seconds per player.
exports.cuxial_fuel:SetFuelType(vehicle, 'diesel')Lowercase aliases
getFuel, setFuel and setFuelType are the same exports with a lowercase first letter.
local level = exports.cuxial_fuel:getFuel(vehicle)Server exports
GetFuel
Returns the fuel level of a vehicle.
local level = exports.cuxial_fuel:GetFuel(vehicle)| Parameter | Type | Description |
|---|---|---|
vehicle | number | Vehicle entity on the server. |
Returns: number from 0 to 100, or nil when the vehicle does not exist or has no level.
local vehicle = NetworkGetEntityFromNetworkId(netId)
local level = exports.cuxial_fuel:GetFuel(vehicle) or 0SetFuel
Sets the fuel level of a vehicle. The client that owns the vehicle applies it to the game.
local ok = exports.cuxial_fuel:SetFuel(vehicle, value)| Parameter | Type | Description |
|---|---|---|
vehicle | number | Vehicle entity on the server. |
value | number | Percentage. Clamped to 0–100. |
Returns: boolean. false when the vehicle does not exist or the value is not a number.
-- Full tank for a vehicle taken out of a garage
exports.cuxial_fuel:SetFuel(vehicle, 100)Compatibility with other fuel scripts
Cuxial Fuel declares, with provide, the resource names of the most common fuel scripts. They are listed at the top of its fxmanifest.lua. A resource that calls the fuel exports through one of those names keeps working without changes:
| Side | Exports answered under those names |
|---|---|
| Client | GetFuel, SetFuel, SetFuelType, and their lowercase aliases |
| Server | GetFuel, SetFuel |
Admin exports (server)
To manage Cuxial Fuel settings from a panel of your own. Cuxial Gas Stations uses them in /gasadmin: if you use that panel, you do not need to call them.
They all take the src of the acting player, check their admin.permission through Cuxial Bridge and rate-limit per player. Errors are strings: 'no_access', 'busy', 'not_ready', 'unknown_section', 'unknown_model', 'invalid', 'invalid:<field>', 'db' and 'size'.
| Export | Returns | What it does |
|---|---|---|
AdminSchema(src?) | { sections } | Editable sections and fields, with type, limits and translated name. Without src it does not check the permission. |
AdminGet(src) | { values, factory, meta } or nil, err | Live and factory values of every section, and who changed it and when. |
AdminSet(src, sectionId, values) | true or false, err | Partial change { [field] = value }. Validates all of it before saving, applies it live and sends it to players. |
AdminReset(src, sectionId) | true or false, err | Returns the section to the values in shared/config.lua. |
AdminPumps(src) | { pumps } or nil, err | Pump and charger models with their factory profile and the one saved on the server. |
AdminSetPump(src, { model, profile }) | true or false, err | Saves a model's screen profile for everyone. profile = false goes back to the factory one. |
A profile is { offset = { x, y, z }, yaw, width, height, sides }: offset within ±5 m, size from 0.05 to 5 m and sides 1 or 2. Models that carry the screen in their mesh ignore the saved profile.
local ok, err = exports.cuxial_fuel:AdminSet(source, 'distances', { pump = 4.0 })
if not ok then
lib.notify(source, { type = 'error', description = err })
endTuner exports (client)
They move a pump's real screen from an interface of your own, the way the /gasadmin Pumps tab does. Nothing is saved until you call AdminSetPump on the server.
| Export | Returns | What it does |
|---|---|---|
TunerNearby() | { [hash] = metres } | Distance to the nearest loaded one of every model with a screen. |
TunerFind(model, origin?, radius?) | { x, y, z, heading, distance, hash } or nil | The nearest loaded one of that model to origin (without it, to the player), within radius. |
TunerStart(model, { camera? }) | profile or nil, err | Starts tuning the nearest one of that model and, if it is more than 4 m away, brings the player in front of it. Fixed camera unless camera = false. Errors: 'disabled', 'busy', 'unknown_model', 'mesh', 'far'. |
TunerSet(profile) | boolean | Preview on the real screen, with the same limits as AdminSetPump. |
TunerStop(save?) | — | Ends tuning. With true it keeps the preview until the saved profile arrives; without it, it goes back to the current profile. |
TunerCamera(on) | boolean | Turns the fixed camera on or off. |
TunerState() | table or nil | Tuning in progress: hash, model, profile, camera, remote. |
TunerPending() | number | Old profiles saved only in this player's game. |
TunerMigrate(upload) | number or nil, err | With true uploads them to the server; with false marks them so they are not offered again. |
While tuning, the local client event cuxial_fuel:tuner (action, profile?, hash?) reports change (keyboard changes), accept, cancel and end.
local profile = exports.cuxial_fuel:TunerStart('my_custom_pump', { camera = true })
if profile then
profile.width = profile.width + 0.05
exports.cuxial_fuel:TunerSet(profile)
endEvents
cuxial_fuel:settingsApplied is a local event, on the server and the client, that arrives with the section id every time a live settings change is applied. Use it if your resource caches any value from Cuxial Fuel's config.
AddEventHandler('cuxial_fuel:settingsApplied', function(sectionId)
if sectionId == 'prices' then
-- read the prices again
end
end)Integration with Cuxial Gas Stations
The link with cuxial_gasstations is automatic: when that resource is running, Cuxial Fuel asks it for prices, stock and promotions and reports each sale, refund and spill to it. There is nothing to configure and nothing to call from your own resources.
