Skip to content

Interaction & availability ​

Availability ​

A streamed prop, a world entry or a door is available to a player when all of these hold:

  1. it is enabled,
  2. its routingBucket is unset or equals the player's bucket,
  3. its conditions match.

Only available props are spawned, and an available prop that stops being available is deleted at once. Networked props are the exception: who sees them is decided by entity scope, and conditions only gate their interact option.

The server pushes each player's routing bucket to them every server.bucketPollIntervalMs (2 s). After SetPlayerRoutingBucket, call refreshPlayer(source) for an instant switch.

Conditions are not security

Conditions decide what a player is shown. A modified client can show itself anything. Validate on the server whatever the prop leads to. Doors re-check jobs and gangs on the server before a toggle, see Doors.

Conditions ​

lua
jobs  = { police = 0, ambulance = 2 },   -- name → minimum grade
gangs = { 'ballas', 'vagos' },           -- a plain list means grade 0
hours = { from = 22, to = 6 },           -- in-game clock
Field Rules
jobs The player's job name is in the table and their grade is at least the minimum. Names: letters, digits and . _ : -, up to 32 characters. Grades 0 to 1000. At most definition.maxConditionEntries (32) names
gangs The same for the gang. When both jobs and gangs are set, matching either one is enough
hours from and to are whole hours 0 to 23. from is included, to is not. { from = 22, to = 6 } wraps past midnight. from == to means always. Applies on top of jobs / gangs

Job and gang come from the framework bridge: es_extended, then qbx_core, then qb-core. The client re-reads them every frameworkPollIntervalMs (5 s), and early after esx:playerLoaded, esx:setJob, QBCore:Client:OnPlayerLoaded, QBCore:Client:OnJobUpdate, QBCore:Client:OnGangUpdate and QBCore:Player:SetPlayerData. Without a framework, jobs and gangs never match.

Conditions apply to props and doors. World models have none.

The interact option ​

interact is one option, or a list of up to definition.maxInteractOptions (6) options. It is taken by registerProp(s), updateProp, addLocalProp and createLocal.

lua
-- one option
interact = { label = 'Open', icon = 'laptop', key = 'E', distance = 2.0, event = 'np_manufacturing:workshop:open' }

-- a list: one key per option
interact = {
  { label = 'Use', icon = 'credit-card', event = 'np_banking:atm:use' },
  { name = 'rob', label = 'Rob', icon = 'mask', event = 'np_banking:atm:rob', server = true, jobs = { 'thief' },
    minigame = { game = 'wires' } },
  { name = 'repair', label = 'Repair', event = 'np_banking:atm:repair', jobs = { mechanic = 1 }, distance = 1.5 },
}
Field Default Notes
name '1', or the list index Stable option name: letters, digits and . _ : -, up to 32 characters. Unique per prop. Sent with the event
event required for props resource:name form. It must start with the owner's resource name and a colon, unless it is listed in interaction.allowedEvents. Doors take no event
label 'Interact' Up to 64 characters. Doors: 'Lock' / 'Unlock'
icon 'hand' Font Awesome name without prefix. Doors: 'door-closed'
key 'E', or the first free key One of E G H K X Y Z. Used by the np_hud and built-in prompts. Unique per prop, see Keys
distance 2.0 0.5 to 10
server false Fire a server event instead of a client event
minigame none Server props and doors only. See Minigames
jobs, gangs, hours none Per option, the same shape as on the prop and checked on top of the prop's own conditions. Not on doors
canInteract none Client entries only (addLocalProp, createLocal): function(entity, id, name, data) returning true to show the option. See Client predicates

Validation reasons: 'invalid_interact', 'too_many_interact_options', 'invalid_interact_name', 'duplicate_interact_name', 'invalid_interact_key', 'duplicate_interact_key', 'invalid_interact_event', 'interact_event_not_allowed', 'can_interact_client_only', 'invalid_can_interact', 'minigame_server_only'.

Keys ​

Every option of a prop has its own key. List options without key get the first free key of E G H K X Y Z, in list order. Two options with the same key are refused with 'duplicate_interact_key', two with the same name with 'duplicate_interact_name'.

The event ​

When the player picks an option:

  • Client event (default): TriggerEvent(event, id, entity, data, receipt, option) on the player's client.
  • server = true: TriggerServerEvent(event, id, netId, data, receipt, option). An entity handle means nothing to the server, so networked props send their net id and everything else 0. Your server handler must validate the request itself: the player, the distance, the job. redeemInteraction does that for you.

receipt is the np_minigames receipt, nil without a game. option is the chosen option's name ('1' for a single unnamed option), so one event can serve several options. createLocal props send their handle as id.

lua
-- client, the default
AddEventHandler('np_manufacturing:workshop:open', function(id, entity, data, receipt, option)
  OpenWorkshop(data.workshop)
end)

-- server, with server = true
RegisterNetEvent('np_banking:atm:rob', function(id, netId, data, receipt, option)
  local src = source
  local result = exports.np_prophandler:redeemInteraction(src, id, receipt, option)
  if not result or not result.success then return end   -- not allowed, too far, or the game was lost
end)

Availability, the option's conditions and its predicates are checked again when the player interacts. Two interactions are at least interaction.cooldownMs (500 ms) apart.

How several options are shown ​

Provider Several options
np_hud One prompt for the nearest prop, with one key per usable option. Each key fires its option
builtin One [key] label line per usable option above the prop. Each key fires its option
ox_target One target option per interact option, each with its own distance and canInteract
qb-target One target option per interact option. Each checks its own distance. Labels should differ per prop: qb-target removes options by label

An option is shown when the prop is available, the player is within the option's distance, the option's jobs / gangs / hours match and every client predicate says yes. The np_hud and built-in prompts pick the nearest prop with at least one usable option.

Client predicates ​

client

A predicate hides an option per player, for example while the player is dead, cuffed or already has a menu open. Functions cannot be sent to clients, so a server registration with canInteract is refused ('can_interact_client_only'). Client entries take canInteract per option. For server props, and to gate options of any prop from another client script, attach one with setCanInteract:

lua
-- client
exports.np_prophandler:setCanInteract('np_banking:atm_3', 'rob', function(entity, id, option, data)
  return not exports.np_banking:isAtmBroken(id)
end)
exports.np_prophandler:setCanInteract('np_banking:atm_3', nil, fn)    -- nil option: every option of the prop
exports.np_prophandler:setCanInteract('np_banking:atm_3', 'rob', nil) -- remove

-- a door's toggle prompt
exports.np_prophandler:setDoorCanInteract('np_police:front', function(id, locked, data) return hasKey end)
  • Predicates are keyed by id. They may be set before the prop arrives and survive a re-registration.
  • They run before an option is shown and again before it fires.
  • They belong to the resource that set them. Only that resource can replace or remove one ('not_owner'), and they are dropped when it stops. At most interaction.maxPredicates (1024) per client.
  • A predicate that errors counts as false (counted in getDiagnostics().predicateErrors) and never breaks the interaction loop.

Predicates, like conditions, decide what is shown. They are not security.

Minigames (np_minigames) ​

interact.minigame puts a skill game from np_minigames in front of a prop interaction (one option of a list, or the only one) or a door. np_minigames judges it on the server; nothing the client says about the outcome is trusted. Client-local props (addLocalProp, createLocal) cannot have one (minigame_server_only).

Field Default Notes
game required np_minigames game id (lockpick, skillcheck, wires, … see Games & difficulty)
difficulty 'medium' easy, medium, hard, expert
opts none Game params ({ pins = 6 }), plus label / sub / icon / tint. A small plain table
item none 'lockpick' or { name, count, require, remove = 'never' | 'fail' | 'success' | 'always', chance, degrade } (np_minigames items)
cooldownMs 0 Props: Per-player time between two games
label interact label Text on the game card (doors: also the Pick lock prompt)
fireOnFail false Props: Fire the event after a lost game too (with its receipt), e.g. for an alarm
lock false Doors: locking needs the game too (default: only unlocking)
others false Doors: members of jobs / gangs toggle freely, everyone else may unlock it by winning the game (Pick lock)

np_prophandler registers an np_minigames profile per gated option: np_prophandler:prop:<id> for a single option, np_prophandler:prop:<id>:<n> for option n of a list. The client plays it and, on a win, fires your event with the receipt as the 4th argument: (id, entity, data, receipt, option) or, with server = true, (id, netId, data, receipt, option). Check it on your server:

lua
exports.np_prophandler:registerProp({
  id = 'np_drugs:crate_7', model = 'prop_box_wood02a', coords = vector3(...),
  interact = { label = 'Pry open', icon = 'box-open', event = 'np_drugs:crate:open', server = true,
    minigame = { game = 'lockpick', difficulty = 'hard', item = { name = 'lockpick', remove = 'fail', chance = 0.35 } } },
})

RegisterNetEvent('np_drugs:crate:open', function(id, netId, data, receipt, option)
  local src = source
  local result, err = exports.np_prophandler:redeemInteraction(src, id, receipt, option)
  if not result or not result.success then return end   -- forged, reused, expired, too far, or lost
  GiveCrateLoot(src, data)
end)

redeemInteraction(src, id, receipt, option?) (owner resource only) finds the option (nil: the only option, or the first one of a list with a minigame) and checks that option's jobs / gangs (always, also without a game), then the routing bucket and the distance (the option's distance + minigames.distanceTolerance). Then it spends the receipt with np_minigames' Redeem against that option's profile. It answers np_minigames' result (success may be false with fireOnFail), or { success = true, skipped = true } when no game was needed: no minigame on the option, np_minigames not running, minigames.enabled off, or the profile could not be registered (a warning is printed; the option then works without a game). Errors: unknown_prop, not_owner, unknown_option, not_allowed, wrong_bucket, too_far, no_ped, and np_minigames' no_receipt, used, expired, wrong_player, wrong_profile. Calling it in every server handler of a prop keeps the event safe whether np_minigames runs or not.

Providers ​

The prompt comes from the first provider that runs, with interaction.provider = 'auto':

Provider Props Doors
np_hud np_hud's interaction prompt (ShowPrompt / HidePrompt) for the nearest available entry in range, one key per option; np_prophandler reads the keys Same
ox_target addLocalEntity options on the entity addSphereZone at the door
qb-target AddTargetEntity options on the entity AddCircleZone at the door
builtin 3D text with the key, only with interaction.fallback = true Same
none No prompt. Used when nothing above runs and fallback is off Same

The provider is picked when an entry is added (a prop spawns, a door comes in range). Force one with interaction.provider. The proximity check runs every interaction.pollIntervalMs (250 ms); per-frame work only runs while a prompt is shown.