Exports & compatibility

Replacing your fuel script

Your other resources keep calling the API they already use, with no edit:

exports['LegacyFuel']:GetFuel(vehicle)          -- answered by hz_fuel
exports['LegacyFuel']:SetFuel(vehicle, 75.0)
exports['qb-fuel']:GetFuel(vehicle)              -- also cdn-fuel, ps-fuel
exports.ox_fuel:setPaymentMethod(fn)             -- server, and setMoneyCheck client side
Entity(vehicle).state.fuel                       -- ox_fuel-compatible statebag
GetResourceState('LegacyFuel')                   -- 'started' (also qb-fuel, ox_fuel, cdn-fuel, ps-fuel)

  • Scripts that check whether their fuel resource runs before using it (cruise control, HUDs, garages) find it.
  • A script of one of these names that you keep running answers for itself. Set its line to false in compatExports.
  • compatStateBags lists extra statebags to fill with the level (qb-fuel by default).
  • After an update, restart the whole server: see Updating.

Fuel level

The level lives on the vehicle's fuel statebag, from 0 to 100. The grade it was filled with is in fuelType.

-- read
local fuel = Entity(vehicle).state.fuel

-- write (client)
exports.hz_fuel:SetFuel(vehicle, 50.0)

Fuel added by another script, a garage or a repair is picked up, not overwritten.


Client exports

ExportReturns
exports.hz_fuel:GetFuel(vehicle)Level, 0 to 100
exports.hz_fuel:SetFuel(vehicle, level)Sets the level, 0 to 100
exports.hz_fuel:GetFuelType(vehicle)Grade, e.g. 'regular'
exports.hz_fuel:setMoneyCheck(fn)Replaces the money check done before a fill. See below

Server exports

ExportReturns
GetVehicleFuelType(netId)Grade of the vehicle
SetVehicleFuelType(netId, fuelType)true when set. Refused for a grade the vehicle can't take
GetFuelPrice(fuelType)Price per litre
GetFuelTypes()The fuelTypes table
GetStations()The station list
IsElectricVehicle(netId)true for an electric model
GetChargePrice(chargeType)Price per 1 % at a charger
GetChargeTypes()The electric.chargeTypes table
GetStationStock(stationId)Litres left per fuel, e.g. { regular = 5200, diesel = 1800 }
SetStationStock(stationId, fuelType, litres)Sets a level, bounded by the tank
AddStationStock(stationId, fuelType, litres)Adds litres, returns what went in
IsOnDeliveryShift(playerId)true while the player is on a delivery shift
GetDeliveryCargo(playerId)Litres in the player's tanker per fuel, or nil
All are called as exports.hz_fuel:Name(...) on the server.

Payment hooks

By default HZ-Fuel charges through your framework's money, or an ox_inventory cash item. To use your own economy:

-- server: return true if the player paid, false/nil otherwise
exports.hz_fuel:setPaymentMethod(function(playerId, amount)
    return exports['my_bank']:Charge(playerId, amount)
end)

-- client: the money the player can spend, checked before a fill starts
exports.hz_fuel:setMoneyCheck(function()
    return exports['my_bank']:GetBalance()
end)

The server always recomputes the price from the fuel actually delivered; the client check only avoids starting a fill the player can't pay.


Prompts, dialogues and menus

WhatWithWithout
Prompts at the pumps, chargers and delivery sitesHZ-TextUi 3D promptsox_lib text UI
NPC lines and choiceshz_lib dialogue boxox_lib menus and notifications
Delivery shift stepshz_lib on-screen objectivesNotifications
Dispatch tablet with the tours maphz_libox_lib menu
No target script is needed. HZ-Fuel runs alongside ox_target or qb-target.

Vehicle keys

The delivery truck's keys go through qbx_vehiclekeys, qb-vehiclekeys, qs-vehiclekeys, wasabi_carlock, mono_carkeys, MrNewbVehicleKeys, cd_garage or vehicles_keys when one runs. ESX alone has no keys: the truck is left unlocked. Another key script:

-- config.lua > delivery
giveKeys = function(vehicle, plate) exports['my_keys']:GiveKey(plate) end,                -- client
giveKeysServer = function(source, vehicle, plate) exports['my_keys']:GiveKeys(source, plate) end, -- server