Skip to content

Exports & events

Public API of Cuxial Gas Stations: exports to connect a fuel script, read prices and reputation, and request a wash.

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.

lua
local stationId = exports.cuxial_gasstations:FindStation(coords)
ParameterTypeDescription
coordsvector3 | tablePosition with x, y and z, usually the pump.

Returns: string or nil when the position is outside every station.

lua
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.

lua
local data = exports.cuxial_gasstations:GetFuelPrices(stationId, countVisit)
ParameterTypeDescription
stationIdstringStation id.
countVisitbooleanAdds 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:

FieldTypeDescription
pricestablePrice per litre or kWh, keyed by fuel id. 0 means the owner has set no price.
stocktableLitres in the tank for petrol fuels; true or false for electric chargers (unlocked or not).
lua
local data = exports.cuxial_gasstations:GetFuelPrices('gas_station_1', false)
if data then
    print(data.prices.regular, data.stock.regular)
end

GetFuel ​

Short form for regular only.

lua
local stock, price = exports.cuxial_gasstations:GetFuel(stationId, countVisit)
ParameterTypeDescription
stationIdstringStation id.
countVisitbooleantrue 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.

lua
local sold = exports.cuxial_gasstations:SellFuel(stationId, fuel, paid, liters, kind, src)
ParameterTypeDescription
stationIdstringStation id.
fuelstringFuel id from fuels in the config.
paidnumberWhat the customer paid.
litersnumberLitres sold, or kWh for a charge.
kindstring'pump', 'can' (jerry can) or 'charge' (electric).
srcnumberServer 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.

lua
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
end

RefundFuel ​

Returns unused litres to the tank and takes the refund out of the cash box.

lua
local refunded = exports.cuxial_gasstations:RefundFuel(stationId, fuel, refund, liters, src)
ParameterTypeDescription
stationIdstringStation id.
fuelstringFuel id.
refundnumberAmount to give back to the customer.
litersnumberLitres that were paid and not delivered.
srcnumberServer 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.

lua
local promos = exports.cuxial_gasstations:GetPromos(stationId)

Returns: nil when the station does not exist. Otherwise a table:

FieldTypeDescription
labelstringDefault name of the station.
fuelPctnumberCurrent discount on fuel, in percent.
washPctnumberCurrent discount on washes, in percent.
livetable[]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.
nexttableNext happy hour, with pct, applies and startsIn (seconds). Absent when there is none today or tomorrow.

GetReputation ​

lua
local rep = exports.cuxial_gasstations:GetReputation(stationId)

Returns: nil when the station does not exist or the reputation module is off. Otherwise a table:

FieldTypeDescription
avgnumberRating from 1 to 5.
countnumberRecent ratings counted.
factornumberMultiplier applied to NPC customer traffic.
bonusPctnumberExtra supplier discount, in percent.

RequestMobileWash ​

Opens a mobile detailing request on behalf of a player, as /detailing does after the player confirms.

lua
local result = exports.cuxial_gasstations:RequestMobileWash(src, service, netId)
ParameterTypeDescription
srcnumberServer id of the customer.
servicestring'rinse', 'foam' or 'wax'.
netIdnumberNetwork 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.

lua
local result = exports.cuxial_gasstations:RequestMobileWash(source, 'foam', netId)
if not result.ok then print(result.error) end

RegisterNoticeProvider ​

Receives every owner notice in your own resource, for example to forward it to another messaging system.

lua
local ok = exports.cuxial_gasstations:RegisterNoticeProvider(name, fn)
ParameterTypeDescription
namestringUnique name, up to 40 characters.
fnfunctionCalled with one notice table for each notice sent.

Fields of notice:

FieldTypeDescription
citizenidstringIdentifier of the station owner.
stationstringStation id.
stationLabelstringName of the station.
kindstringlow_stock, mobile_wait, mobile_missed, npc_cap, rental, daily, reputation, abandon_risk or spill.
titlestringTitle, already translated.
textstringBody, already translated.
atnumberTime in milliseconds.

Returns: boolean. The provider is removed on its own when your resource stops.

lua
exports.cuxial_gasstations:RegisterNoticeProvider('my_mail', function(notice)
    print(notice.stationLabel, notice.kind, notice.text)
end)

UnregisterNoticeProvider ​

lua
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.

lua
local spilled = exports.cuxial_gasstations:Spill(stationId, coords, src, liters, fuel, netId)
ParameterTypeDescription
stationIdstringStation id.
coordsvector3Ground position under the nozzle.
srcnumberServer id of the player who was refuelling.
litersnumberLitres paid and not delivered.
fuelstringFuel id.
netIdnumberNetwork 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.

lua
local stationId = exports.cuxial_gasstations:FindStation(GetEntityCoords(cache.ped))

IsWaxed ​

Tells whether a vehicle has an active wax coat.

lua
local waxed = exports.cuxial_gasstations:IsWaxed(vehicle)
ParameterTypeDescription
vehiclenumberEntity 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.

© Cuxial