β›½ Exports

Exports

This page is for developers who want to implement Renewed-Fuel within their resources.

Client Side

Getters

These are used to get information from the script.

Statebag

  • Entity(vehicleId).state.fuel (Recommended)
local vehicle = cache.vehicle -- Ox Lib example
local fuel = Entity(vehicle).state.fuel
 
-- Optimized statebags method (not recommended in loops)
lib.onCache('vehicle', function(vehicle)
    if not vehicle then
        return
    end
 
    local state = Entity(cache.vehicle).state
    print(state.fuel)
end)
 
-- Best way
lib.onCache('vehicle', function(vehicle)
    if not vehicle then
        return
    end
 
    SetTimeout(0, function()
        while cache.vehicle do
            print(GetVehicleFuelLevel(cache.vehicle))
            Wait(100)
        end
    end)
end)

Export

  • exports['Renewed-Fuel']:GetFuel(vehicleId) -- (Not recommended)
local fuel, fuelType = exports['Renewed-Fuel']:GetFuel(cache.vehicle) -- ox lib example
 
local fuel = GetVehicleFuelLevel(vehicle) -- Recommended for huds etc.

isElectric

This is used to check if the vehicle is an electric vehicle (defined in config) without storing additional useless information in other resoruces

local isElectric = exports['Renewed-Fuel']:isElectric(cache.vehicle)

Setters

These are used to provide values to the script such as setting vehicle fuel level.

Export

  • exports['Renewed-Fuel']:SetFuel(vehicleId, amount, fuelType)
exports['Renewed-Fuel']:SetFuel(cache.vehicle, amount, fuelType) 
-- fueltype defaults to current fuelType or 86 if nil

Gas Station Exports

Get Gas Station Tank Info

local Storage = exports['Renewed-Fuel']:GetStorage(StationId, tankId) 
-- Station ID is the ID in the db, the tankId, is 1-4 depending on how many tanks the station have 

Set Gas Station Tank Info

exports['Renewed-Fuel']:SetStorage(StationId, tankId, amount, fuelType)
-- Station ID is the ID in the db, tankId is 1-4 depending how many tanks the station have

Server Side

Getters

Statebag

  • Entity(vehicleId).state.fuel
local vehicle = GetVehiclePedIsIn(GetPlayerPed(source))
local fuel = Entity(vehicle).state.fuel
local fuelType = Entity(vehicle).state.fuelType

Setters

Export

  • exports['Renewed-Fuel']:SetFuel(vehicleId)
local vehicle = GetVehiclePedIsIn(GetPlayerPed(source))
exports['Renewed-Fuel']:SetFuel(vehicle, amount, fuelType)
-- fueltype defaults to current fuelType or 86 if nil