Connect your fuel script to the station tanks, read prices, promotions and reputation, or send owner notices to another resource. Cuxial Fuel already uses these exports; you only need them for your own integrations.
Station ids are the keys of data/stations.lua, such as gas_station_1.
Server exports
FindStation
Returns the station a position belongs to. A position belongs to a station when it is inside its pumps sphere.
local stationId = exports.cuxial_gasstations:FindStation(coords)| Parameter | Type | Description |
|---|---|---|
coords | vector3 | table | Position with x, y and z, usually the pump. |
Returns: string or nil when the position is outside every station.
local stationId = exports.cuxial_gasstations:FindStation(GetEntityCoords(pump))GetFuelPrices
Prices and stock of every fuel at a station, with the admin limits and the current happy hour already applied.
local data = exports.cuxial_gasstations:GetFuelPrices(stationId, countVisit)| Parameter | Type | Description |
|---|---|---|
stationId | string | Station id. |
countVisit | boolean | Adds one visit to the station statistics. Defaults to true; pass false when you only re-read prices. |
Returns: nil when the station does not exist or has no owner. Otherwise a table:
| Field | Type | Description |
|---|---|---|
prices | table | Price per litre or kWh, keyed by fuel id. 0 means the owner has set no price. |
stock | table | Litres in the tank for petrol fuels; true or false for electric chargers (unlocked or not). |
local data = exports.cuxial_gasstations:GetFuelPrices('gas_station_1', false)
if data then
print(data.prices.regular, data.stock.regular)
endGetFuel
Short form for regular only.
local stock, price = exports.cuxial_gasstations:GetFuel(stationId, countVisit)| Parameter | Type | Description |
|---|---|---|
stationId | string | Station id. |
countVisit | boolean | true adds one visit. Defaults to not counting. |
Returns: stock (litres) and price (per litre), or nil when the station does not exist or has no owner.
SellFuel
Reports a sale. Takes the litres from the tank and adds the money to the cash box.
local sold = exports.cuxial_gasstations:SellFuel(stationId, fuel, paid, liters, kind, src)| Parameter | Type | Description |
|---|---|---|
stationId | string | Station id. |
fuel | string | Fuel id from fuels in the config. |
paid | number | What the customer paid. |
liters | number | Litres sold, or kWh for a charge. |
kind | string | 'pump', 'can' (jerry can) or 'charge' (electric). |
src | number | Server id of the buyer. Optional. With it, the buyer can earn a wash voucher and is asked for a rating. |
Returns: boolean. false when the station has an owner and lacks the stock or the charger, or the fuel id is unknown: refund the customer. true in every other case, including stations with no owner.
local stationId = exports.cuxial_gasstations:FindStation(pumpCoords)
if stationId and not exports.cuxial_gasstations:SellFuel(stationId, 'regular', 120, 40, 'pump', source) then
-- no stock: give the money back
endRefundFuel
Returns unused litres to the tank and takes the refund out of the cash box.
local refunded = exports.cuxial_gasstations:RefundFuel(stationId, fuel, refund, liters, src)| Parameter | Type | Description |
|---|---|---|
stationId | string | Station id. |
fuel | string | Fuel id. |
refund | number | Amount to give back to the customer. |
liters | number | Litres that were paid and not delivered. |
src | number | Server id of the buyer. Optional. Cancels a wash voucher that no longer reaches the minimum litres. |
Returns: number, the amount actually taken from the cash box. It can be lower than refund when the cash box is short, or 0. For a station with no owner it returns refund unchanged.
GetPromos
Promotions of a station, for public displays such as a price sign.
local promos = exports.cuxial_gasstations:GetPromos(stationId)Returns: nil when the station does not exist. Otherwise a table:
| Field | Type | Description |
|---|---|---|
label | string | Default name of the station. |
fuelPct | number | Current discount on fuel, in percent. |
washPct | number | Current discount on washes, in percent. |
live | table[] | Promotions active now. A happy hour has kind = 'happy_hour', pct, applies and endsIn (seconds). A voucher has kind = 'fuel_voucher', minLiters, service and validMinutes. |
next | table | Next happy hour, with pct, applies and startsIn (seconds). Absent when there is none today or tomorrow. |
GetReputation
local rep = exports.cuxial_gasstations:GetReputation(stationId)Returns: nil when the station does not exist or the reputation module is off. Otherwise a table:
| Field | Type | Description |
|---|---|---|
avg | number | Rating from 1 to 5. |
count | number | Recent ratings counted. |
factor | number | Multiplier applied to NPC customer traffic. |
bonusPct | number | Extra supplier discount, in percent. |
RequestMobileWash
Opens a mobile detailing request on behalf of a player, as /detailing does after the player confirms.
local result = exports.cuxial_gasstations:RequestMobileWash(src, service, netId)| Parameter | Type | Description |
|---|---|---|
src | number | Server id of the customer. |
service | string | 'rinse', 'foam' or 'wax'. |
netId | number | Network id of the customer's vehicle. |
Returns: a table with ok (boolean), id and quote on success, or error (a code such as module_disabled) on failure.
local result = exports.cuxial_gasstations:RequestMobileWash(source, 'foam', netId)
if not result.ok then print(result.error) endRegisterNoticeProvider
Receives every owner notice in your own resource, for example to forward it to another messaging system.
local ok = exports.cuxial_gasstations:RegisterNoticeProvider(name, fn)| Parameter | Type | Description |
|---|---|---|
name | string | Unique name, up to 40 characters. |
fn | function | Called with one notice table for each notice sent. |
Fields of notice:
| Field | Type | Description |
|---|---|---|
citizenid | string | Identifier of the station owner. |
station | string | Station id. |
stationLabel | string | Name of the station. |
kind | string | low_stock, mobile_wait, mobile_missed, npc_cap, rental, daily, reputation, abandon_risk or spill. |
title | string | Title, already translated. |
text | string | Body, already translated. |
at | number | Time in milliseconds. |
Returns: boolean. The provider is removed on its own when your resource stops.
exports.cuxial_gasstations:RegisterNoticeProvider('my_mail', function(notice)
print(notice.stationLabel, notice.kind, notice.text)
end)UnregisterNoticeProvider
exports.cuxial_gasstations:UnregisterNoticeProvider(name)Spill
For fuel scripts. Creates a fuel puddle when a vehicle drives off with the nozzle attached. The station decides whether the spill happens and how many litres it loses.
local spilled = exports.cuxial_gasstations:Spill(stationId, coords, src, liters, fuel, netId)| Parameter | Type | Description |
|---|---|---|
stationId | string | Station id. |
coords | vector3 | Ground position under the nozzle. |
src | number | Server id of the player who was refuelling. |
liters | number | Litres paid and not delivered. |
fuel | string | Fuel id. |
netId | number | Network id of the vehicle. |
Returns: number, the litres that do not go back to the tank. 0 means no puddle was created.
Client exports
FindStation
Same as the server export.
local stationId = exports.cuxial_gasstations:FindStation(GetEntityCoords(cache.ped))IsWaxed
Tells whether a vehicle has an active wax coat.
local waxed = exports.cuxial_gasstations:IsWaxed(vehicle)| Parameter | Type | Description |
|---|---|---|
vehicle | number | Entity handle of the vehicle. |
Returns: boolean.
Events
Cuxial Gas Stations exposes no events for other resources. Its internal events are validated on the server and are not meant to be triggered from outside.
