STG ScriptsDocumentation
Vanaheim Fuel

Exports

Client and server exports of STG Vanaheim Fuel, LegacyFuel compatibility, and how to connect HUDs and garage scripts.

LegacyFuel compatibility

Vanaheim Fuel registers itself as LegacyFuel. Scripts that already call these exports work without any change:

local fuel = exports['LegacyFuel']:GetFuel(vehicle)
exports['LegacyFuel']:SetFuel(vehicle, 50.0)

For new code, call the resource by its own name:

local fuel = exports['stg-vanaheimfuel']:GetFuel(vehicle)
exports['stg-vanaheimfuel']:SetFuel(vehicle, 50.0)

All fuel exports are client side. Fuel is a percentage from 0 to 100.

Client exports

ExportReturnsDescription
GetFuel(vehicle)numberFuel level of the vehicle. Without a vehicle, the vehicle the player sits in.
SetFuel(vehicle, level)Sets the fuel level, clamped to 0 to 100. SetFuel(level) sets the player's current vehicle.
GetVehicleFuelType(vehicle)stringFuel type in the tank: diesel, gasoline, premium or electric.
IsRefueling()booleantrue while the player is fueling at a pump or charger.
GetNearestStation()table{ key, config, distance } of the closest station from Config.Stations.
Notify(type, message, title)Shows a Vanaheim Fuel notification.
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local fuel = exports['stg-vanaheimfuel']:GetFuel(vehicle)

if fuel < 10.0 then
    exports['stg-vanaheimfuel']:Notify('error', 'You are almost out of fuel.')
end

Server exports

ExportReturnsDescription
GetStationOwner(stationKey)string or nilIdentifier of the owner (identifier on ESX, citizenid on QBCore and QBOX), or nil when unowned.
GetStationInfo(stationKey)table or nilThe station row from the stg_fuel table, for example business_name, owner_identifier and balance.
local owner = exports['stg-vanaheimfuel']:GetStationOwner('station_1')

stationKey is the key from Config.Stations, for example station_1.

HUDs

Read the fuel level with GetFuel, or the LegacyFuel export your HUD already uses.

Vanaheim Fuel keeps the game's own fuel level at full while there is fuel in the tank. A HUD that reads the native GetVehicleFuelLevel always shows a full tank. Switch it to the export.

Garages

The fuel level stays on a vehicle as long as it exists. A garage that despawns a vehicle and spawns a new one later has to save and restore the level, otherwise the new vehicle gets a random starting level from Config.InitialFuel.

If your garage has a fuel option that uses the LegacyFuel exports, pick LegacyFuel. Otherwise add these calls where it stores and spawns vehicles:

-- when the vehicle is stored
local fuel = exports['stg-vanaheimfuel']:GetFuel(vehicle)

-- after the vehicle is spawned
exports['stg-vanaheimfuel']:SetFuel(vehicle, savedFuel)

Turn off any fuel handling built into the garage itself, so only one script writes the fuel level.

Still having trouble?

Open a ticket on our Discord. Our team answers around 15 hours a day.

Get help on Discord

On this page