Home / Documentation / Weigh Station trucking integration
Weigh Station trucking integration — developer guide
For developers of trucking and job scripts. How your resource tells Sal's Kewl Weigh Station what each truck and trailer is carrying, and how it hears back what the scale and the inspectors found: the cargo interface, the exports you can call, and the events you can listen for.
Overview
Sal's Kewl Weigh Station weighs commercial vehicles axle group by axle group, checks them against the limits each server sets, and writes the citations and out-of-service orders. Without a trucking script, a player's load is a believable weight the station makes up. With one, the scale weighs what your script says is really on board.
- Requires Sal's Kewl Weigh Station 0.6.0-beta or later.
- Everything here is server-side. There are no client exports and no client events.
- Weights are pounds, as whole numbers. Convert from
kilograms with
math.floor(kg * 2.20462 + 0.5). - The same file ships in the download as
CARGO-INTERFACE.md.
This interface is new in 0.6.0-beta, which is being tested with trucking developers now. The 0.5.0 beta has only the older push exports.
Who owns what
| Your resource | The weigh station |
|---|---|
| What is physically on each truck and trailer, and what it weighs | The empty weight of each truck and trailer |
| Contract IDs and load descriptions | Axle layout, and how the load spreads over the axles |
| The paperwork you actually track | The legal limits, which each server sets in /weighstation |
| What happens to the job after a citation or an out-of-service order | Gross weight, overweight, fines, inspections and out-of-service orders |
Don't send a gross weight, a maximum weight or an "overloaded" flag.
The scale works those out from your cargo weight and the server's own
rules. If your job screen needs the legal maximum, ask for it with
GetMaxLoad.
Registering as a cargo provider
The weigh station asks your resource what a vehicle carries at the moment it needs to know. You don't push updates, so there is nothing to clear and nothing to resend after a restart.
local WS = 'sals_kewlweighstation'
local function register()
if GetResourceState(WS) ~= 'started' then return end
pcall(function() exports[WS]:RegisterCargoProvider() end)
end
CreateThread(register) -- you started after the weigh station
AddEventHandler('sals_kewlweighstation:ready', register) -- the weigh station (re)started after you
- The weigh station records your resource name from the call. You pass no arguments.
- When your resource stops, it is dropped automatically. When it starts again, the code above registers it again.
- When the weigh station restarts, it fires
sals_kewlweighstation:readyonce it is ready, and you register again. It keeps no copy of your cargo, so nothing is lost.
Answering GetCommercialCargo
Define this export in your server code:
exports('GetCommercialCargo', function(vehicleNetId)
-- return nil, or the table below
end)
The weigh station calls it once for the truck and once for the trailer attached to it, each with that vehicle's own network ID. Report only what is physically on that vehicle right now:
- A tractor pulling a dry van: the truck answers with no items, and the trailer answers with the freight.
- A box truck: the truck answers with its freight.
- A truck-mounted forklift carried on the back of the trailer is an item on the trailer.
- After a partial delivery, report what is left on board, not the original contract weight.
Because each item is reported by exactly one vehicle, the scale adds the two answers and nothing is counted twice.
What to return
{
schema = 1,
items = {
{ label = 'Steel coil', lb = 42000, contractId = 'C-1042' },
{ label = 'Truck-mounted forklift', lb = 4800 },
},
papers = {
papersMatch = true, -- your load sheet matches what is on board
permit = nil, -- you don't track permits: leave it nil
hoursOk = nil, -- you don't track hours of service: leave it nil
},
hazmat = nil, -- true / false / nil
placards = nil, -- true / false / nil; only read when hazmat is true
}
| Field | Required | Notes |
|---|---|---|
schema | Yes | 1 |
items | Yes | May be empty: {} means this vehicle is empty |
items[].label | Yes | Up to 60 characters. Shown on the scale ticket and to the inspector |
items[].lb | Yes | 0 to 300,000 per vehicle in total |
items[].contractId | No | Sent back to you in the weigh station's events |
papers.* | No | See True, false or unknown |
hazmat, placards | No | See True, false or unknown |
nil vs. an empty table
- Return
nilwhen the vehicle isn't one of yours. If both the truck and the trailer return nil, the weigh station decides the load itself, the way it does with no trucking script. - Return
{ schema = 1, items = {} }for a vehicle of yours that is empty. It is weighed empty. - If one of the two answers with a table and the other returns nil, the nil one counts as empty.
True, false or unknown
Every paperwork and hazmat field takes one of three values. Leave a field out (nil) when you don't track it. It is never assumed valid.
| Value | Meaning | At an inspection |
|---|---|---|
true | You vouch for it | Never cited |
false | You know it's wrong | Always found and cited |
nil | You don't track it | The station's normal odds decide, the same as with no trucking script |
If the truck and the trailer give different answers for the same field:
- Paperwork and placards:
falsebeatstrue, andtruebeatsnil. One bad unit makes the rig bad. - Hazmat:
truebeatsfalse, andfalsebeatsnil. Hazmat on either unit makes the rig hazmat.
Rules for the export
- Answer from memory. Don't query the database or wait inside it. It is called while a truck is sitting on the scale.
- Forget a network ID when its vehicle is deleted. FiveM reuses network IDs.
- It is called a few times per pass through a station: when the truck is screened on the approach, when it stops on the scale, when an officer weighs it with portable scales, and when an inspection starts. It is never called every frame.
- If it errors, the weigh station treats the answer as nil and prints the error to the server console once.
Custom trucks and trailers
You don't send empty weights or axle counts. The server owner enters
custom models in game under /weighstation →
Rules → Custom vehicles, one row
per model:
| Column | What |
|---|---|
| Spawn name | The model name, such as skk_lowboy |
| Kind | Straight truck, tractor, or trailer |
| Empty lb | Empty weight in pounds |
| Rear axles | The rear axle group (a trailer's only group): single, tandem or tridem |
| Front % | The share of the empty weight on the steer axle, or on the kingpin for a trailer. The rest is on the rear group |
A row for a base-game model replaces the built-in figures. A custom truck or tractor must stop at an open station the same as the game's commercial class.
The base-game trucks and trailers are already built in. A truck nobody entered is weighed as a generic medium truck, or as a generic tractor when it is pulling a trailer. A trailer nobody entered is weighed as a dry van. The server console prints the model's hash once, so the owner knows to add it.
If your resource ships its own trucks or trailers, a table of suggested rows in your documentation saves your customers the guesswork.
Exports you can call
All server-side. Wrap each call in pcall in case the weigh
station isn't running.
| Export | Returns |
|---|---|
RegisterCargoProvider() | true |
GetMaxLoad(truckNetId, trailerNetId?) | The most cargo, in pounds, that combination can legally carry under this server's limits. nil if the truck doesn't exist |
IsVehicleOutOfService(plateOrNetId) | isOos, order |
IsDriverOutOfService(src) | isOos, order. src is a server ID, or the driver's license: identifier |
GetSafetyRecord(src) | { name, driver = record, carrier = record, carrierName } |
GetCitations(plate?) | Citation history, newest first; one plate's if given |
order is { reason, at, untilT, by }:
atanduntilTare Unix seconds (os.time()).untilTis nil when the order lasts until an officer lifts it.byis the officer's name, or the AI inspector.
A vehicle's order is held against the truck's license plate. Check the driver and the truck before you hand out a job:
local ok, oos = pcall(function() return exports[WS]:IsDriverOutOfService(src) end)
if ok and oos then --[[ refuse the job ]] end
A record is
{ score, inspections, clean, violations, oos, bypasses },
with score from 0 to 100. The carrier is the driver's job.
Events you can listen for
All are server events. Listen with
AddEventHandler, never
RegisterNetEvent. A net event can be faked by any client.
| Event | When | Data |
|---|---|---|
sals_kewlweighstation:ready | The weigh station has started | None |
sals_kewlweighstation:scaleTicket | A truck is weighed (scale or portable scales) | { src, plate, station, gross, legal, groups, over, contracts, at } |
sals_kewlweighstation:citation | Every citation | { src, plate, model, station, kind, violations, total, paid, oosMinutes, points, officer, name, contracts, at } |
sals_kewlweighstation:outOfService | A citation puts the vehicle out of service | Same as citation |
sals_kewlweighstation:outOfServiceLifted | An officer lifts an order | { order } |
sals_kewlweighstation:bypass | A player's truck bypasses an open station | { src, plate, model, station, coords, heading, by, at } |
srcis the driver's server ID, or nil for an AI truck.contractslists thecontractIds that were on board, taken from your answers.groupsis{ { name, kind, lb, limit } }.overlists the groups over their limit, as{ name, by, limit }.kindon a citation is one ofinspection,bypass,ignored_signal,skipped_inspectionordriving_oos.violationsis{ { id, label, fine, oos, oosMinutes, points } }.paidis whether the fine was taken from the driver.officeris a server ID, or'ai'.
The older push exports
SetCargo(vehicleNetId, lb, label) and
SetManifest(vehicleNetId, { cargo, hazmat, placards, permit, papersMatch, hoursOk })
still work, for scripts that would rather push. What they set is kept in
memory only: it is lost when the weigh station restarts, and it expires
after four hours. When a registered provider answers for a vehicle, that
answer wins. New integrations should use
GetCommercialCargo.
Changed in 0.6.0: a SetManifest field
left out now means "not tracked." Leaving out hazmat no
longer means "not hazmat." Send hazmat = false if that is
what you mean.
Versioning
schema is the version of this interface. New optional
fields can be added within schema 1, so ignore fields you don't
recognize. A change that would break an existing integration gets
schema = 2, and the weigh station keeps accepting 1.
Support
Integration questions land on Discord. The owner's side of the resource is in the Weigh Station owner's manual.
Didn’t find it? Ask Squawky, or open a ticket on Discord and tell us what you already tried.