STG ScriptsDocumentation
Advanced Fuel

Exports

Read and change vehicle fuel from your own scripts with the STG Advanced Fuel client exports, and connect garages and HUDs that used LegacyFuel.

Other resources, such as garages, HUDs and mechanic jobs, can read and change fuel through Advanced Fuel. Both exports are client side. Fuel is a percentage from 0 to 100.

Client exports

GetFuel

local fuel = exports['stg-fuel']:GetFuel(vehicle)

Returns the fuel level of the vehicle.

SetFuel

exports['stg-fuel']:SetFuel(vehicle, 25.0)

Adds the amount to the current fuel level, capped at 100. The example above adds 25 percent.

SetFuel adds to the tank instead of replacing the level. To set an exact level, pass the difference:

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

Fuel state bag

Every fuel change is also written to the vehicle state bag fuel and synced to all players, so scripts can read it without the export:

local fuel = Entity(vehicle).state.fuel

Scripts made for LegacyFuel

Advanced Fuel does not register itself as LegacyFuel. In scripts that call LegacyFuel, replace the resource name:

-- before
exports['LegacyFuel']:GetFuel(vehicle)

-- after
exports['stg-fuel']:GetFuel(vehicle)

GetFuel works the same way. For SetFuel, use the exact level example above, because LegacyFuel replaces the level and Advanced Fuel adds to it.

Still having trouble?

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

Get help on Discord

On this page