Exports ​
All exports are called as exports.np_passwords:<name>(...). Bad input returns false / nil instead of throwing.
Exports marked yields wait for the player, so call them from a thread (event handlers and commands already run in
one). For walkthroughs, see Using it from your resource.
Server ​
server
| Export | Returns | Description |
|---|---|---|
RegisterLock(def) |
ok, err |
Register or update a lock. Idempotent, persisted unless def.persist = false. Fields |
RemoveLock(id) |
boolean |
Remove a lock (and its door) |
GetLock(id) |
LockInfo | nil |
Public info, never the hash. See below |
SetCode(id, secret, bySrc?) |
ok, err |
Set or rotate the code. Vault items of the lock get the new code, other keychains go stale. bySrc is logged |
Grant(id, who) |
boolean |
Give the code (or, without a known code, a key) to who |
Revoke(id, who) |
boolean |
Remove the lock's keychain entries / vault items of who |
GuestCode(id, opts?) |
code | nil |
A guest code. opts = { uses = 1, ttl = 7200, label? } |
OfferSave(src, id, secret?) |
boolean |
Show the player a Save this code? toast. Without secret, np_passwords uses the code it knows |
Prompt(src, idOrOpts) |
ok, err? |
Yields. Opens the prompt on that client and waits (up to Config.Prompt.timeout). err only when it could not open |
IsUnlocked(src, id, maxAge?) |
boolean |
src unlocked id within maxAge seconds (default Config.Prompt.unlockTtl, 10) |
ConsumeUnlock(src, id) |
boolean |
Same check, then clears the record (one-shot) |
Knows(src, id) |
boolean |
The player has a keychain entry or a visible vault item for the lock |
Crack(src, id, opts?) |
ok, err? |
Yields. Runs the cracking minigame. opts = { speed = 1.0, item? } (item = false: no item needed) |
RequireCode(src, app, opts?) |
boolean |
Yields. Asks for a 2FA code. opts = { reason? } |
RegisterOtpApp(def) |
boolean |
Add a 2FA app. def = { id, label, icon?, tint?, sms? } |
RegisterVerifier(name, fn) |
boolean |
Accounts your resource keeps: fn(src, username, secret) -> boolean. See Verifier |
SetDoorState(id, locked) |
boolean |
Lock or open the door of a lock for everyone. false when the lock has no door |
itemUse(event, item, inventory, slot) |
– | Item callback for np_inventory / ox_inventory (server = { export = 'np_passwords.itemUse' }). Not for scripts |
who for Grant / Revoke:
| Value | Means |
|---|---|
3 (number) |
Server id: that player's current character |
'ABC12345' |
Character id (citizenid / identifier). Works offline |
'job:police' |
The job vault of police |
'gang:3' |
The gang vault of np_gangs gang 3 |
'vault:v:7' |
Any vault by id |
idOrOpts for the server Prompt is the same as for the client export: a lock id or an options table.
IDs of the records IsUnlocked / ConsumeUnlock read:
| Prompt | Record id |
|---|---|
| Lock | The lock id |
Verifier login (verify = 'mdt') |
'verify:mdt' |
2FA (RequireCode, <np-otp>) |
'otp:<app>' |
-- grey out "Open safe" in your menu when the player can't autofill it
local knows = exports.np_passwords:Knows(src, 'apt12:safe')
-- give the new tenant the code and a single-use code for the mover
exports.np_passwords:Grant('apt12:front', tenantCid)
local code = exports.np_passwords:GuestCode('apt12:front', { uses = 1, ttl = 3600, label = 'Movers' })
LockInfo ​
GetLock(id) returns:
{
id = 'apt12:safe', label = 'Bedroom safe', icon = 'vault', type = 'pin', length = 6,
coords = { x = -1150.2, y = -1520.4, z = 10.6 }, radius = 2.0,
hasCode = true, hasDoor = false, locked = true, door = nil,
owner = { type = 'char', id = 'ABC12345' },
tries = 3, lockout = 45, fails = 0, lockedUntil = nil, -- unix seconds while locked out
strength = { seconds = 500000, level = 'strong' }, -- time to crack
leaked = false, codeSetAt = 1791234567,
rules = { min = 6 }, meta = { sub = 'Integrity Way' }, resource = 'my_apartments',
}
Client ​
client
| Export | Returns | Description |
|---|---|---|
Prompt(idOrOpts) |
ok, reason |
Yields. Open a prompt. See below |
Create(lockId, opts?) |
boolean |
Yields. Open the generator to set a new code. Owners, managers and staff only (server-checked) |
Knows(lockId) |
boolean |
The player has an entry for the lock (from the list the server pushes) |
Crack(lockId) |
boolean |
Yields. Start the cracking minigame at a lock (server checks item, distance, crackable) |
IsOpen() |
boolean |
A prompt, generator, crack or warrant sheet is open |
Close() |
– | Cancel whatever is open. Waiting exports return false, 'cancelled' |
Prompt, Create and Crack refuse with false (reason busy) while another panel is open.
Prompt options ​
idOrOpts is a lock id or a table:
| Field | Description |
|---|---|
id / lockId |
A registered lock |
verify |
A verifier name instead of a lock |
type |
Verifier prompts: 'login' (default), 'password', 'pin', 'phrase', 'pattern'. 'otp' with app |
app, reason |
2FA prompt: app id and the second line |
label (or title), sub, icon, tint |
Header. Locks use their own label and icon; sub and tint override the lock's meta |
username |
Verifier logins: pre-filled username |
length |
Verifier PIN length (1–12) |
reason when ok is false:
| Reason | Means |
|---|---|
cancelled |
ESC, Close(), or the character unloaded |
closed |
The server closed the prompt (timeout, another prompt replaced it) |
tries |
A verifier or 2FA prompt used up its tries |
dead |
The player died with the prompt open |
busy |
Another np_passwords panel is open |
not_found, no_code, too_far, no_character, rate_limited, invalid |
The prompt did not open |
A lock locked out by wrong tries keeps the prompt open with the countdown; the player closes it with ESC
(cancelled).
Item callback ​
-- ox_inventory/data/items.lua
['code_breaker'] = { label = 'Code breaker', weight = 400, stack = true, close = true,
server = { export = 'np_passwords.itemUse' } },
np_inventory gets the items with this callback at runtime. See Installation and Bridges → Inventory.