🔵Setters and Getters

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

Getters

Client

Statebag: Entity(vehicleId).state.fuel

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

Useful to check if the vehicle is an electric car without storing additional useless information in other resoruce

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

Server

Statebag: Entity(vehicleId).state.fuel

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

Setters

Client

Export: exports['Renewed-Fuel']:SetFuel(vehicleId)

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

Server

Export: exports['Renewed-Fuel']:SetFuel(vehicleId)

local vehicle = GetVehiclePedIsIn(GetPlayerPed(source))
exports['Renewed-Fuel']:SetFuel(vehicle, amount, fuelType) 

Gas Station exports

Get the gas station tank storage

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 the gas station tank storage

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

Last updated