Skip to content

Exports & events

Cuxial Fuel public API: exports and state bag to read and set fuel, plus admin and screen tuner exports.

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:

lua
local level = Entity(vehicle).state.fuel

The 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.

lua
local level = exports.cuxial_fuel:GetFuel(vehicle)
ParameterTypeDescription
vehiclenumberVehicle entity.

Returns: number, from 0 to 100. 0 when the vehicle does not exist.

lua
if exports.cuxial_fuel:GetFuel(cache.vehicle) < 10 then
    lib.notify({ description = 'Low fuel' })
end

SetFuel ​

Sets the fuel level of a vehicle.

lua
exports.cuxial_fuel:SetFuel(vehicle, value)
ParameterTypeDescription
vehiclenumberVehicle entity.
valuenumberPercentage. Clamped to 0–100.
lua
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.

lua
exports.cuxial_fuel:SetFuelType(vehicle, fuel)
ParameterTypeDescription
vehiclenumberVehicle entity. It has to be networked.
fuelstring | 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.

lua
exports.cuxial_fuel:SetFuelType(vehicle, 'diesel')

Lowercase aliases ​

getFuel, setFuel and setFuelType are the same exports with a lowercase first letter.

lua
local level = exports.cuxial_fuel:getFuel(vehicle)

Server exports ​

GetFuel ​

Returns the fuel level of a vehicle.

lua
local level = exports.cuxial_fuel:GetFuel(vehicle)
ParameterTypeDescription
vehiclenumberVehicle entity on the server.

Returns: number from 0 to 100, or nil when the vehicle does not exist or has no level.

lua
local vehicle = NetworkGetEntityFromNetworkId(netId)
local level = exports.cuxial_fuel:GetFuel(vehicle) or 0

SetFuel ​

Sets the fuel level of a vehicle. The client that owns the vehicle applies it to the game.

lua
local ok = exports.cuxial_fuel:SetFuel(vehicle, value)
ParameterTypeDescription
vehiclenumberVehicle entity on the server.
valuenumberPercentage. Clamped to 0–100.

Returns: boolean. false when the vehicle does not exist or the value is not a number.

lua
-- 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:

SideExports answered under those names
ClientGetFuel, SetFuel, SetFuelType, and their lowercase aliases
ServerGetFuel, 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'.

ExportReturnsWhat 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, errLive and factory values of every section, and who changed it and when.
AdminSet(src, sectionId, values)true or false, errPartial change { [field] = value }. Validates all of it before saving, applies it live and sends it to players.
AdminReset(src, sectionId)true or false, errReturns the section to the values in shared/config.lua.
AdminPumps(src){ pumps } or nil, errPump and charger models with their factory profile and the one saved on the server.
AdminSetPump(src, { model, profile })true or false, errSaves 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.

lua
local ok, err = exports.cuxial_fuel:AdminSet(source, 'distances', { pump = 4.0 })
if not ok then
    lib.notify(source, { type = 'error', description = err })
end

Tuner 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.

ExportReturnsWhat 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 nilThe nearest loaded one of that model to origin (without it, to the player), within radius.
TunerStart(model, { camera? })profile or nil, errStarts 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)booleanPreview 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)booleanTurns the fixed camera on or off.
TunerState()table or nilTuning in progress: hash, model, profile, camera, remote.
TunerPending()numberOld profiles saved only in this player's game.
TunerMigrate(upload)number or nil, errWith 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.

lua
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)
end

Events ​

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.

lua
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.

© Cuxial