Profiles, items & progress ​
Three additions of 1.1 that let the np_* resources move their old minigames onto np_minigames without losing what they did around them.
Profiles + receipts ​
For flows that run on the client ("the client runs a skill check, then tells the server success"): prison jobs,
crafting, digging. The server registers what the player must play, the client starts it, and the server checks the
outcome with a one-time receipt. The client can't pick an easier game, difficulty or params, and it can't forge a
success.
-- server, once at start. The name is namespaced with the calling resource unless it already contains ':'.
local name = exports.np_minigames:RegisterProfile('dig', {
game = 'skillcheck', levels = { 'easy', 'medium', 'medium' }, -- any game opts: difficulty, params, label, sub,
-- icon, tint, item, maxMove, cancelable, onProgress
cooldownMs = 0, -- per-player time between two runs
}) -- -> 'np_prison:dig' | nil, err
exports.np_minigames:UnregisterProfile('dig') -- optional; profiles go away when you stop
-- client: blocks. A server-validated session on the profile's terms; the client can only add label / sub / title.
local ok, result = exports.np_minigames:PlayProfile('np_prison:dig', { sub = 'Tunnel' })
TriggerServerEvent('np_prison:dig:finish', result.receipt)
-- server
local result, err = exports.np_minigames:Redeem(src, receipt, 'dig') -- profile name: short or full, optional
if result and result.success then GiveLoot(src) end
| Export | Side | Returns | Errors |
|---|---|---|---|
RegisterProfile(name, profile) |
server | full name | invalid_name, invalid_profile, unknown_game, invalid_item, taken (another resource owns the name) |
UnregisterProfile(name) |
server | boolean |
|
PlayProfile(name, cosmetic?) |
client | ok, result |
unknown_profile, cooldown, busy, no_item (no receipt) |
Redeem(src, receipt, profile?) |
server | result | nil, err |
no_receipt (unknown or forged), used, expired, wrong_player, wrong_profile |
- Every profile session that ends gets a receipt, failures included (
result.success == false), so a fail can be punished on the server too. There is none fordroppedandapi(no outcome). - The receipt is in the submit reply and in the close event, so
PlayProfilegets it whichever way the session ends. Redeemworks once, only for the player who played, and only withinConfig.Security.receiptTtlMs(120 s). It returns the full result, withitem,profileandreceipt.- A player's receipts are dropped when they leave. A resource's profiles are removed when it stops, and its running
profile sessions end with
api. Register them again when np_minigames restarts (see Integrating → Profile + receipt).
Items ​
opts.item on Play, Start, Chain, Team, TeamAsync and profiles:
item = 'lockpick' -- short for { name = 'lockpick' }
item = {
name = 'lockpick',
count = 1, -- needed, and removed when the rule matches (default 1)
require = true, -- refuse with reason 'no_item' when the player has fewer (default true)
remove = 'fail', -- 'never' (default) | 'fail' | 'success' | 'always'
chance = 0.35, -- probability the removal happens when `remove` matches (default 1)
degrade = 20, -- durability points taken per use, on every outcome (np_inventory / ox_inventory / qb)
}
- The item is checked before the game starts. Nothing is used up when the session ends with
dropped,apiorreplaced. degradelowers the first stack's durability (np_inventory and ox_inventorymetadata.durability, qbinfo.quality), clamped at 0. It is skipped when the item was removed. With np_inventory it goes throughDegradeItem.- Chain: an
itemin the shared opts belongs to the whole chain. It is checked before the first step and used up once on the chain's outcome, reported on the last result. Aniteminside a step's opts applies to that step. - Team: every member needs the item; the round is refused before anyone starts. Each member's own item is used up by their own result.
- The inventory is detected at start: np_inventory, then ox_inventory, then qb-inventory (ps- / lj- forks), then the
framework (
es_extended,qbx_core,qb-coreplayer functions, no durability).Config.Inventoryforces one. Without any inventory,opts.itemis ignored and a warning is printed once per item.
The result reports what happened: result.item = { name, removed, degraded, durability }.
Resources that own their item
Several np_* resources keep their tool items to themselves (np_banking's thermite and laptop, np_passwords'
code breaker, np_inventory's lockpick) and don't pass opts.item: they check and use up the item around the game, as
before. opts.item is for resources that want np_minigames to do it.
Progress ​
Every game reports a cosmetic 0..100 progress (cells solved, pins set, rounds cleared, depth drilled). When the
caller asks for it (onProgress, progress = true, or a team game), the client forwards it in 5 % steps, at most
every 0.4 s; the server calls onProgress(p) and fires np_minigames:progress. Use it for things like an ATM
screen's trace bar (np_banking does exactly that). Never pay out on
progress: it comes from the client.
exports.np_minigames:Play(src, 'hexhack', { onProgress = function(p) SetAtmTrace(atm, p) end })
AddEventHandler('np_minigames:progress', function(src, p, gameId, invokingResource) end) -- server-local
The client Play / PlayAsync exports take onProgress too (called on the client).