Exports

You can use the script exports to get and set a vehicle's fuel level easily. These exports allow developers to integrate LC Fuel into their custom scripts.

Available Exports

All exports are available only on the client side.

GetFuel

This export returns the current fuel level of the specified vehicle.

local fuelLevel = exports["lc_fuel"]:GetFuel(vehicle) -- Get the fuel level

Example Usage

In this example, when storing a vehicle in a garage, we retrieve its fuel level and send it to the server for persistence.

function StoreVehicleInGarage(vehicle)
    local plate = GetVehicleNumberPlateText(vehicle)
    local fuelLevel = exports["lc_fuel"]:GetFuel(vehicle)
 
    TriggerServerEvent('vehiclesStored', plate, fuelLevel)
end

SetFuel

This export sets the vehicle's fuel level to a specified value.

exports["lc_fuel"]:SetFuel(vehicle, 100) -- Set fuel to 100%

Example Usage

When spawning a vehicle, you can use this export to set its initial fuel level.

function SpawnVehicle(modelHash, fuel)
    local vehicle = CreateVehicle(modelHash, coords.x, coords.y, coords.z, true, false)
 
    exports["lc_fuel"]:SetFuel(vehicle, fuel)
end
โš ๏ธ

Ensure the vehicle entity is fully spawned before setting fuel to avoid unexpected behavior.


SetFuelType

This export sets the specified vehicle's fuel type.

exports["lc_fuel"]:SetFuelType(vehicle, fuelType) -- Set the vehicle's fuel type

Allowed types

The fuelType parameter can be:

  • nil - Resets the vehicle to its default fuel type.
  • "regular"
  • "plus"
  • "premium"
  • "diesel"

Example Usage

This example sets a vehicle's fuel type to "regular" (gasoline) during a repair. Passing nil resets it to default.

function RepairVehicle(vehicle)
    -- Restore the vehicle's engine health to full
    SetVehicleEngineHealth(vehicle, 1000.0)
 
    -- Set the vehicle's fuel type to "regular"
    exports["lc_fuel"]:SetFuelType(vehicle, "regular")
 
    -- Or reset to the default fuel type
    exports["lc_fuel"]:SetFuelType(vehicle, nil)
end