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
falseincompatExports. compatStateBagslists extra statebags to fill with the level (qb-fuelby 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
| Export | Returns |
|---|---|
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
| Export | Returns |
|---|---|
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 |
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
| What | With | Without |
|---|---|---|
| Prompts at the pumps, chargers and delivery sites | HZ-TextUi 3D prompts | ox_lib text UI |
| NPC lines and choices | hz_lib dialogue box | ox_lib menus and notifications |
| Delivery shift steps | hz_lib on-screen objectives | Notifications |
| Dispatch tablet with the tours map | hz_lib | ox_lib menu |
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