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.