NX CreativeNX CreativeDocs
Scriptsnx_mechanic

Exports

Public exports registered by nx_mechanic, split into server and client.

Server exports are called as exports.nx_mechanic:<Name>() from a server-side script. Client exports use the same pattern in a client-side script.

Every export that takes a plate normalises it first, so the raw plate text from GetVehicleNumberPlateText works as-is. Trailing spaces and case do not matter.

Server

Builds

exports.nx_mechanic:GetBuildserver

Read the saved build for a plate without opening a session. Useful for garages and job menus that want to know what a vehicle should look like.

Parameters

  • platestring— Vehicle plate.

Returns

table|nil — vehicle properties, or nil when the plate has no build
local props = exports.nx_mechanic:GetBuild('LSPD 001')
if props then
    print('Saved build has', props.modLivery, 'as its livery')
end
exports.nx_mechanic:GetDepartmentDefaultserver

Read a department's default build for one vehicle model.

Parameters

  • jobstring— Job name, as used in Config.Jobs.
  • modelstring— Vehicle model name. Case does not matter.

Returns

table|nil — the vehicle properties table, or nil when that job has no default for the model
local props = exports.nx_mechanic:GetDepartmentDefault('police', 'police3')

Vehicle records

exports.nx_mechanic:GetVehicleDataserver

Read everything nx_mechanic tracks for a plate: its captured base handling, the tuning, wear, stance and nitrous layered over it, and the odometer.

Parameters

  • platestring— Vehicle plate.

Returns

table|nil { plate, model, base, tuning, wear, stance, nitrous, mileageKm }
local rec = exports.nx_mechanic:GetVehicleData('47SGP921')
if rec then
    print(('%s has done %.0f km'):format(rec.model, rec.mileageKm))
    if rec.tuning and rec.tuning.engine then
        print('Engine swap:', rec.tuning.engine)
    end
end

tuning is a map of category to option id, for example { engine = 'v8', tyres = 'slick' }. wear is a map of part id to remaining health as a percentage. nitrous carries the kit, the fitted bottle, its capacity, the shots left and the purge colour.

exports.nx_mechanic:PlateChangedserver

Move a vehicle's record, build and history from one plate to another. Any resource that renames a plate must call this, or everything nx_mechanic knows stays behind on the old one.

Parameters

  • oldPlatestring— The plate as it was.
  • newPlatestring— The plate as it now is.

Returns

boolean — false when either plate is unreadable or the two are the same
exports.nx_mechanic:PlateChanged('OLD 123', 'NEW 456')

A record already sitting on the new plate wins, and the old one is dropped.

Servicing

exports.nx_mechanic:NeedsServiceserver

Whether any part on this vehicle has fallen to or below Config.Servicing.threshold.

Parameters

  • platestring— Vehicle plate.

Returns

boolean — false when the plate has no record
if exports.nx_mechanic:NeedsService(plate) then
    -- Flag it on your fleet screen
end
exports.nx_mechanic:GetVehicleWearserver

Read the wear table for a plate: part id to remaining health, as a percentage from 100 down to 0.

Parameters

  • platestring— Vehicle plate.

Returns

table|nil — nil when the plate has no record
local wear = exports.nx_mechanic:GetVehicleWear(plate)
if wear then
    print('Oil at', wear.oil or 100, 'percent')
end

A part with no entry has never been worn and counts as full.

exports.nx_mechanic:GetServiceHistoryserver

Every part replaced on this plate, newest first.

Parameters

  • platestring— Vehicle plate.
  • limit?number— Rows to return. Defaults to 50, capped at 200.

Returns

table — array of { part, shop, mechanic_name, mileage_km, created_at }. Empty when there is nothing to report
for _, row in ipairs(exports.nx_mechanic:GetServiceHistory(plate, 10)) do
    print(row.created_at, row.part, 'by', row.mechanic_name)
end

Inspection

exports.nx_mechanic:GetInspectionserver

The most recent roadworthiness certificate for a plate.

Parameters

  • platestring— Vehicle plate.

Returns

table|nil { plate, passed, checks, shop, mechanic, mileageKm, createdAt, expiresAt, expired, valid }
local cert = exports.nx_mechanic:GetInspection(plate)
if not cert then
    print('Never inspected')
elseif cert.valid then
    print('Valid until', cert.expiresAt)
else
    print(cert.expired and 'Expired' or 'Failed')
end

valid is the one field most callers want: it is true only when the inspection passed and has not expired. checks is the list of individual checks, each { id, ok, detail }. createdAt and expiresAt are milliseconds since the epoch.

Work orders

exports.nx_mechanic:GetOrderserver

Read one work order by its id.

Parameters

  • idnumber|string— Order id.

Returns

table|nil { id, shop, plate, model, customer, customerName, status, claimedBy, claimedName, total, lines, request, note, createdAt, updatedAt }
local order = exports.nx_mechanic:GetOrder(42)
if order and order.status == 'open' then
    print(order.customerName, 'is waiting on', order.plate)
end

status is one of open, claimed, done or cancelled. lines is the priced work; request is everything the customer had configured when they placed the order.

exports.nx_mechanic:GetShopOrdersserver

List a shop's work orders, newest first.

Parameters

  • shopIdstring— The shop's id from Config.Shops.
  • status?string— One of 'open', 'claimed', 'done', 'cancelled'. Defaults to 'open'.

Returns

table — array of order rows in the same shape as GetOrder. Empty when there are none
local waiting = exports.nx_mechanic:GetShopOrders('bennys')
print(#waiting, 'orders waiting')

Up to 50 rows are returned.

Shops

exports.nx_mechanic:GetShopserver

Read a shop's live state, including anything an owner has changed in game.

Parameters

  • idstring— The shop's id.

Returns

table|nil { id, label, type, access, install, job, owned, price }
local shop = exports.nx_mechanic:GetShop('bennys')
if shop and shop.owned then
    print(shop.label, 'has an owner')
end
exports.nx_mechanic:IsShopEmployeeserver

Whether a player counts as staff of a shop. Covers the owner, the managers they named, the built-in roster and, unless Config.Business.employees is 'builtin', anyone holding the shop's framework job.

Parameters

  • srcnumber— Player server id.
  • shopIdstring— The shop's id.

Returns

boolean
if exports.nx_mechanic:IsShopEmployee(source, 'bennys') then
    -- Show them the staff entrance
end

Client

exports.nx_mechanic:OpenWorkshopclient

Open the workshop on a vehicle. Applies the same gates as the target option: the vehicle must sit in a bay of a shop this player may use, and no session may already be open.

Parameters

  • vehicle?number— Vehicle entity. Omit to use the vehicle the player is in, or the nearest one within 6 metres.

Returns

boolean — false when it could not open
-- From a phone app, a job menu, or your own interaction
if not exports.nx_mechanic:OpenWorkshop() then
    print('Not in a workshop bay')
end

TriggerEvent('nx_mechanic:client:open', vehicle) does the same thing without a return value.

exports.nx_mechanic:IsWorkshopOpenclient

Whether a workshop session is running on this client. Use it to suppress your own interface while the panel is up.

Returns

boolean
if exports.nx_mechanic:IsWorkshopOpen() then return end
exports.nx_mechanic:OpenTabletclient

Open the tablet. With no argument, or false, it opens the staff view for the nearest shop this player staffs. With true it opens the customer view: their own invoices and work orders, and nothing else.

Parameters

  • customer?boolean— True for the customer view. Anything else opens the staff view.

Returns

nil
-- Staff view, same as /tablet
exports.nx_mechanic:OpenTablet()

-- Customer view, same as /invoices
exports.nx_mechanic:OpenTablet(true)

The staff view refuses and notifies when the player staffs no commercial shop. It also refuses while a workshop session is open.

NX Docs