OPX//77
opx_infinityfuel

Server

Last updated on

The fuel contract on the server — read and write a tank, the stations, and the refuel and can sessions.

local fuel = OPX.Api.Get('fuel')

From server code inside opx_infinity. Other resources use the fuel exports. vehicleId is a live vehicle id, as an integer or its decimal text. A write with a reason is announced on opx:on:fuel:changed. Never yields.

Get

ox's state.fuel, read: one vehicle's tank.

fuel.Get(vehicleId)

Parameters

  • vehicleId: integer | string

Returns

  • Result — { litres?, capacity, percent?, usesFuel }; error fuel.noVehicle
    • litres, percent: nil when nobody has written the tank yet
    • usesFuel: false for a class with USAGE = 0
Example
local tank = fuel.Get(vehicleId)
if tank.ok and tank.value.percent and tank.value.percent < 10 then print('nearly empty') end

Set

ox's state:set('fuel', percent).

fuel.Set(vehicleId, percent, reason, source)

Parameters

  • vehicleId: integer | string
  • percent: number — 0..100
  • reason?: string — for the event; default 'staff', exports pass 'ext:<resource>'
  • source?: integer — the player it is about, for the event

Returns

  • Result — { litres, percent }; errors fuel.noVehicle, fuel.badAmount, fuel.busy (a pour holds the tank), fuel.refused

SetLitres

Set in litres, open77_fuel's unit. Clamped to the tank.

fuel.SetLitres(vehicleId, litres, reason, source)

Parameters

  • vehicleId: integer | string
  • litres: number — 0 or more
  • reason?: string — default 'staff'
  • source?: integer

Returns

  • Result — { litres }; errors as Set

Restore

Puts back the tank a stored car comes out with. Written, not announced. Used by vehicles.

fuel.Restore(vehicleId, litres)

Parameters

  • vehicleId: integer | string
  • litres: number

Returns

  • boolean — written

Capacity

Litres in a full tank: CAPACITY, or open77_fuel's capacity() while standing down.

fuel.Capacity()

Returns

  • number

StandingDown

Whether open77_fuel runs and this module has stopped burning for it. Re-asked every 10 s.

fuel.StandingDown()

Returns

  • boolean

Stations

Every open station, as the config built it. Placeholders and refused stations are not in it.

fuel.Stations()

Returns

  • table — key → { key, label, x, y, z, bucket, price, pumps }
    • pumps: { x, y, z }[]

Session

The session a player is in.

fuel.Session(player)

Parameters

  • player: integer

Returns

  • { kind, vehicleId?, station?, method? }? — kind: 'pump' | 'can' | 'buy' | 'refill'; nil when none

Refuel

ox's startFueling at a pump, as opx:net:fuel:refuel runs it. Every check of the refuel flow; the player gets the answer.

fuel.Refuel(player, payload)

Parameters

  • player: integer
  • payload: { method } — 'EDDIES' | 'BANK'

Returns

  • boolean ok, string code — 'refuelling' or a refusal code

CanBuy

Buys a can, or refills the emptiest one, at a pump: a bar, then the charge.

fuel.CanBuy(player, payload)

Parameters

  • player: integer
  • payload: { method, refill? }

Returns

  • boolean ok, string code — 'buy', 'refill' or a refusal code

CanPour

Pours a can into a vehicle. The vehicle is re-measured.

fuel.CanPour(player, vehicleId, slot)

Parameters

  • player: integer
  • vehicleId?: integer | string — a hint; nil takes the nearest within CAN.REACH
  • slot?: integer — the can; nil takes the fullest in the bag

Returns

  • boolean ok, string code — 'pouring' or a refusal code
Example
local ok, code = fuel.CanPour(source)
if not ok then print('no pour: ' .. code) end

On this page