Skip to content

Exports & hooks ​

What other resources may rely on. np_metal-scanner depends on none of them (only oxmysql, np_npchandler and np_prophandler).

All exports are server-side unless marked client, called as exports['np_metal-scanner']:<name>(...) (the resource name contains a hyphen, so use the bracket form). An export never throws: errors are logged and it answers nil. If the module behind an export is not installed it answers nil, 'unavailable'. Every table it returns is a plain copy.

Server ​

server

Export Returns
ScanPlayer(target, opts?) A gate pass or a plain reading. See below
GetMetalProfile(src) The player's metal profile, with names (server trusted). See below
GetReading(src, settings?) The reading of the player: { zones = { 7 numbers }, objects, side, class, alarm, alarmZones, massKg, threshold, sensitivity }. settings may set sensitivity, threshold, noise, drift, scanLoadout, scanInventory
IsVenueScreened(coords) screened, venueId: a venue is there, open, with a working gate, pole or X-ray belt
GetVenueAt(coords) The public venue whose area holds the coordinates, or nil
GetVenue(id) / GetVenues() One public venue / all of them
RegisterVenue(def) Creates or updates a venue (and its scanners). See below
SetScannerEnabled(id, bool) ok, error
SetScannerOffline(id, bool, reason?) ok, error. Takes a scanner offline (unplugged, sabotaged, maintenance) until set back; logged with the calling resource
IsOnDuty(src, venueId?) boolean: framework duty, or the clock-in of the shifts, for that venue
GetCase(id) The case, or nil. See below
CreateCase(def) The new case, or nil, error. See below
GetLocker(venue, owner) The owner's active locker at that venue (owner: a server id or an identifier), or nil
AddMetalSource(name, fn) boolean. See below
registerHook(name, fn, opts?) Hook id, or nil for an unknown name. See Hooks
removeHook(id) boolean

Item export (np_inventory and ox_inventory server.export = 'np_metal-scanner.useItem'): useItem. It exists for the inventory's use hook (the wand, the claim ticket, the ground detector); don't call it yourself.

Public venue ​

lua
{ id, label, icon, tint, coords = { x, y, z }, radius, blip = { sprite, color } | false, temporary, open,
  rules = { weapons, bannedClasses, permitDoc, lockers, lockerFee, chime, schedule } }

There is no staff list and no silent-alarm flag in it.

ScanPlayer ​

lua
-- a full pass at a gate: lamp, session, operator panel, log, events, hooks
local result, err = exports['np_metal-scanner']:ScanPlayer(target, { scanner = 'courthouse_gate_1' })
-- result = { status = 'clear' | 'alarm' | 'random' | 'bypass' | 'closed', alarm, session?, reading? }

-- a plain reading with the venue's detection settings (no lamp, no session)
local reading = exports['np_metal-scanner']:ScanPlayer(target, { venue = 'lsia' })

opts: scanner (an id; with a gate or pole this is a full pass), venue, settings (detection overrides), force (ignore the schedule), random (false skips the random secondary roll). A pass is refused with nil, error: no_player, unknown_scanner, disabled, offline, or a beforeScan veto. A plain reading carries status = 'alarm' | 'clear' and is logged as scan.

GetMetalProfile ​

lua
{ src, identifier, built, tamper, tamperKinds, clientReport, shields,
  items = { { key, label, source = 'loadout' | 'inventory' | 'body' | 'external', name, hash?, slot?, count, mass,
              class, zone, zoneIndex, side, shielded, ammo?, components?, serial?, ... } } }

It has names, so keep it on the server. It needs the player's client for a moment (the weapons report), so call it from a thread.

AddMetalSource ​

Makes something you track count as metal.

lua
exports['np_metal-scanner']:AddMetalSource('my_prosthetics', function(src)
  if not MyHasProsthetic(src) then return {} end
  return { { label = 'Steel prosthetic', name = 'prosthetic', count = 1, mass = 30, class = 'body', zone = 'knees', side = 'R' } }
end)

The function runs on every profile; items are { label, name, count, mass (0..100), class, zone | zones, side? }. They are marked source = 'external' and cannot be taken or seized. The source is removed when your resource stops.

RegisterVenue ​

lua
exports['np_metal-scanner']:RegisterVenue({
  id = 'city_gala', label = 'City gala',
  data = { coords = vector3(-1380.0, -600.0, 30.0), radius = 40.0, icon = 'champagne-glasses', tint = 'purple', blip = false,
           temporary = true },
  rules = { weapons = 'none', bannedClasses = { 'firearm', 'blade' }, lockers = true, threshold = 20, sensitivity = 50,
            operatorJobs = { 'security' } },
  scanners = { { id = 'gala_gate', type = 'gate', label = 'Entrance', coords = vector3(-1382.0, -602.0, 30.2), heading = 33.0 } },
})

Updates the venue when the id exists, otherwise creates it; scanners are created or updated by id. Rules and data are validated and merged under the defaults. A venue created this way is stored like any other; remove it with your own logic.

CreateCase and GetCase ​

lua
local case, err = exports['np_metal-scanner']:CreateCase({
  venue = 'courthouse', operator = source, target = targetSrc,   -- server ids or identifiers
  findings = {}, decisions = {}, items = {},                      -- optional snapshots
  status = 'open', mdt = 'MDT-1042',
})

A case is { id, ref, venue, scanner, session, operator = { identifier, name }, target = { identifier, name }, findings, decisions, items, status = 'open' | 'handed' | 'closed', mdt, handedTo, evidence, mode, created, updated }. Creating one fires caseCreated and tells the on-duty police.

Client ​

client

Export Returns
IsScanning() boolean, kind: a gate pass, wand sweep or ground detector of np_metal-scanner is running (kind 'gate', 'wand', 'ground', …)
GetNearestScanner(maxDistance?, types?) The nearest scanner (a copy) and its distance, or nil. types: a list such as { 'gate', 'pole' }
OpenConsole() boolean: opens the security console

Hooks ​

lua
local id = exports['np_metal-scanner']:registerHook('beforeLocker', function(ctx)
  if ctx.venue == 'courthouse' then return false, 'no lockers today' end
end)

Hooks run synchronously in registration order, each with its own copy of the payload. A hook that errors is logged and skipped. Hooks of a stopped resource are removed. A veto hook returns false, reason (the first one wins; the reason is an existing error code or your own text of up to 128 characters).

Hook Kind Payload
beforeScan veto { target, scanner, venue, kind = 'gate' | 'wand' | 'export', operator? }. Not asked for a bypass pass
beforeSeize veto { session, target, operator, venue, items = { item views } }
beforeReturn veto { session, target, operator, venue, items } for a findings return or a case release, { venue, target, locker, items } for a locker
beforeLocker veto { venue, owner, items = { { name, label, count, source } } }
beforeDeclare veto { target, venue, scanner, item = { key, class, name, … }, decision = 'keep' | 'locker' }
beforeFind veto { src, area, find = { item, coords, evidence } } (ground detector)
metalProfile mutate fn(src, profile) -> profile. Return the changed profile (add, remove or change items); the result is sanitised. Chains through the hooks
afterScan notify { target, scanner, venue, session?, alarm, zones, class?, kind }. Return value ignored
afterSeize notify { session, case, operator, target, venue, items = { { kind, name, label, count } } }. Return value ignored

The events are on Events, commands & keys.