Skip to content

API & exports ​

Server exports ​

The server exports are bound in server/exports.lua. Keep authorization calls on the server, check that the host is started, and treat an unavailable/error response as a denial:

lua
local useLegacyAccess = GetResourceState('np_jobs') ~= 'started'
if not useLegacyAccess then
  local callOk, allowed, reason, info = pcall(function()
    return exports.np_jobs:hasFeature(src, 'police.citations', { duty = true })
  end)
  if not callOk or reason == 'unknown' or reason == 'pack_offline' then
    useLegacyAccess = true
  elseif allowed ~= true then
    -- A live feature denial is authoritative.
    return
  end
end
if useLegacyAccess and not legacyJobAndDutyCheck(src) then return end
-- Continue the server action only after host authorization or the documented legacy check succeeds.

hasFeature(src, featureId, opts?) returns true, nil, info when allowed or false, reason, info when denied. info includes the resolved job, faction, grade, duty state, config and source. A consuming resource may use its documented legacy fallback when the host/export is unavailable or the feature is unknown/offline. A denial from a registered feature is authoritative.

Authorization and pack registration ​

Export Signature and return
registerFeaturePack (def) -> true | false, code; pack ID is owned by the calling resource
registerFeature (def) -> true | false, code; feature ID must use its registered pack prefix
hasFeature (src, featureId, opts?) -> true, nil, info | false, reason, info
getFeatureConfig (src, featureId, opts?) -> config | nil, reason, info
getPlayersWithFeature / countWithFeature (featureId, opts?) -> { server IDs } / number
isOnDuty / getActiveJob (src) -> boolean / { kind, id, faction, grade, duty, shift? } | nil
openJobStash Server: (src, jobId, stashKey) -> boolean, code?; client: (jobId, stashKey) -> boolean (requests server authorization)
addHook / invalidate (name, fn) -> boolean / (src, reason?)
registerRequirementProvider / registerGrantProvider (kindOrName, fn) -> boolean, code?
hasFeatureLocal Client export: (featureId) -> boolean; reads replicated player state for presentation only, never for server authorization

opts accepted by hasFeature may include duty, place, and an admin-only grade override. duty = false suppresses the duty requirement for a query; do not use it to authorize an on-duty action. A place is checked against the feature's place-scoped schema field.

Job, shift and progression APIs ​

Export Signature
getJobDefinition / getJobDefinitions (id) / (filter?) -> copied definition / definition list
saveJobDefinition (src, definition) -> true | false, code; player saves require npjobs.editor
startShift / endShift / getShift (src, jobId, opts?) / (src, reason) / (src)
getJobCenterData (src) -> current jobs-panel data
addXp / getLevel (src, track, amount) / (src, track)
addSkillXp / getSkill (src, skill, amount) / (src, skill)
startRoute / routeArrive (src, jobId, routeId, stops) / (src, stopIndex, coords)

getJobCenterData(src) includes a featureCatalog whose rows provide the feature ID, owning pack, label, description, duty default, schema, defaults, requirements and whether its pack is attached. It also returns the player's available job cards. Saved definitions are included only when the caller has npjobs.editor.

Jobs panel editor actions ​

These are server-validated NUI actions, not exports. They require npjobs.editor:

Action Behavior
newDefinition Creates and saves a starter minijob definition with a generated ID and empty feature/config sections
saveDefinition Merges features, requirements, overrides, fleet, uniforms, stashes, pay and caps; validates feature IDs and schemas, then persists the definition
testDefinition Validates the draft, then resolves each selected feature against the editor's current player, active job, grade, and duty; returns per-feature allow/deny results. It does not simulate other grades.

Grants, providers, pay and shared services ​

Export Signature
grantFeature (src, featureId, opts?) -> grantId | false, code; opts can scope config, job, place, time, reason and reference
revokeFeature / revokeGrant / revokeGrants / getGrants (src, featureId) / (grantId) / (filter?) / (playerSrcOrFilter?)
registerPayTask / payTask (name, def) / (src, name, units?, ctx?) -> true, payout | false, code
registerLoadoutProvider / registerVehicleProvider (packId, fn)
registerItemGate (packId, { items = {}, check = fn })
registerJobProvider (id, { list = fn, start? = fn })
registerAppSection (packId, def)
registerNpcFallback (service, { feature, provider, minOnline?, place?, config? })
startGroupJob / setGroupProgress / getGroup (groupId, jobId, stages) / (groupId, memberSrc, units, stage?) / (src)
getJobForPlace / getJobAccount (placeId) / (jobOrDefinition, purpose?)
spawnJobVehicle / returnJobVehicle (src, fleetId, opts?) / (src, netId)

Vehicle spawn/return requires np_vehiclehandler; without it the host returns an unavailable error rather than creating an unmanaged entity. saveJobDefinition checks npjobs.editor when an actor source is supplied; omit the actor only for a trusted server-side operation.

Resource-owned registrations are cleaned up when the calling resource stops. Packs should use np_addon 'np_jobs' and the owner-aware npAddon.attach('np_jobs', fn, { api = 1 }) handshake to re-register after a host restart. See Integrations for capability ownership and pack mapping.