Exports ​
lua
local props = exports.np_prophandler
local ok, reason = props:registerProp({
id = 'my_resource:crate', model = 'prop_box_wood02a', coords = coords,
})
- Everything you register belongs to your resource (
GetInvokingResource()). Only your resource can change or remove it, and it is removed when your resource stops. - Exports that can fail return
false, reason. The reasons are strings such as'invalid_coords'; the prop definition lists the validation reasons. - Exports from a resource that isn't running throw. If np_prophandler is optional for you, check
GetResourceState('np_prophandler') == 'started'or wrap the call inpcall. - Register again on
np_prophandler:ready: a restart of np_prophandler drops everything.
Server ​
server
Props ​
| Export | Returns | Description |
|---|---|---|
registerProp(def) |
true or false, reason |
Register a prop. networked = true makes it a networked prop |
registerProps(defs) |
count, failures |
Register a list in one state message. Valid entries are registered even when others fail. failures maps the list index to the reason |
updateProp(id, def) |
true or false, reason |
Replace your prop with a full new definition. def.id must equal id ('id_mismatch') |
setPropEnabled(id, enabled) |
true or false, reason |
Enable or disable your prop. A disabled prop stays registered but is not spawned |
removeProp(id) |
true or false, reason |
Remove your prop |
redeemInteraction(src, id, receipt, option?) |
result or nil, reason |
Check an interaction on your prop: the option's jobs / gangs, the bucket, the distance, and spend the np_minigames receipt of an interact.minigame. option is the event's 5th argument |
removeProps(ids) |
count, failures |
Remove a list in one state message. failures maps the list index to the reason |
removeAllProps() |
count |
Remove every prop your resource registered |
getProp(id) |
table or nil |
The normalized definition with owner (the registering resource) |
getPropEntity(id) |
entity or 0 |
The server entity of a networked prop while it exists. 0 for streamed props |
getPropNetId(id) |
netId or nil |
The net id of a networked prop while it exists |
getPropCoords(id) |
coords, rotation or nil |
vector3s: the live entity of a networked prop, else where it will be created, else the registered coords |
setPropCoords(id, coords, rotation?) |
true or false, reason |
Move your networked prop and its stored position, also while despawned. See Props that move. Reasons: 'not_networked', 'not_owner', 'invalid_coords', 'invalid_rotation' |
spawnProp(id) |
entity, netId or false, reason |
Create your networked prop's entity now instead of on the next pass. Reasons: 'not_networked', 'disabled', 'networked_limit_reached', 'create_failed' |
Reasons besides validation: 'resource_disabled', 'id_in_use', 'definition_limit_reached',
'networked_disabled', 'networked_limit_reached', 'unknown_prop', 'not_owner'. redeemInteraction adds
'unknown_option', 'not_allowed', 'wrong_bucket', 'too_far', 'no_ped' and np_minigames' reasons.
lua
-- a crate only police (grade 2 and up) see, at night
local ok, reason = exports.np_prophandler:registerProp({
id = 'np_police:armory_crate',
model = 'prop_box_ammo04a',
coords = vector3(452.1, -980.0, 30.7),
jobs = { police = 2 }, -- name -> minimum grade, or { 'police' }
hours = { from = 22, to = 6 }, -- optional
routingBucket = 0, -- optional
})
exports.np_prophandler:setPropEnabled('np_police:armory_crate', false)
Attachments ​
| Export | Returns | Description |
|---|---|---|
setPlayerAttachments(source, key, list) |
true or false, reason |
Set the attachments of a player under key. list is a list of attachments or a single one. nil removes the key. The key is namespaced by your resource |
getPlayerAttachments(source) |
{ [fullKey] = list } |
Everything in the player's state bag. Full keys are s:<resource>:<key> (server) and c:<resource>:<key> (client) |
Reasons: 'invalid_key', 'unknown_player', 'invalid_attachment', 'attachment_limit_reached', and the model and
field reasons of attachments.
World models ​
| Export | Returns | Description |
|---|---|---|
hideWorldModel(def) |
id or false, reason |
Hide a map model around a point. keepScriptObjects = true hides map objects only. See World models |
swapWorldModel(def) |
id or false, reason |
Swap a map model for another around a point |
removeWorldModel(id) |
true or false, reason |
Remove your entry. Reasons: 'unknown_entry', 'not_owner' |
Doors ​
| Export | Returns | Description |
|---|---|---|
registerDoor(def) |
true or false, reason |
Register a door: one part, or up to 8 as one door |
registerDoors(defs) |
count, failures |
Register a list in one state message |
removeDoor(id) |
true or false, reason |
Remove your door. Reasons: 'unknown_door', 'not_owner' |
setDoorLocked(id, locked) |
true or false, reason |
Lock or unlock a door. Any server resource may call it; check your own authorization first. Fires np_prophandler:doorChanged with playerSource 0 when the state changed. Reasons: 'unknown_door', 'invalid_flag' |
isDoorLocked(id) |
boolean or nil |
nil for an unknown door |
getDoor(id) |
table or nil |
The normalized door with owner |
Players and diagnostics ​
lua
SetPlayerRoutingBucket(source, 7)
exports.np_prophandler:refreshPlayer(source)
getDiagnostics() on the server returns:
| Field | Description |
|---|---|
epoch, revision |
Sync position (see Sync) |
enabled, framework |
Config.PropHandler.enabled and the detected framework |
definitions, maxDefinitions |
Registered props and the limit |
byOwner |
{ [resource] = count } |
counters |
registered, updated, removed, rejected |
networked |
registered, active, maxActive, counters (created, deleted, lost, failed) |
attachments |
players, entries, counters (published, rejected, reverted) |
world |
entries, counters |
doors |
registered, counters |
Client ​
client
Props ​
| Export | Returns | Description |
|---|---|---|
getPropEntity(id) |
entity or 0 |
Streamed or networked prop entity. 0 while not spawned or still loading |
isPropSpawned(id) |
boolean |
The entity exists, also while hidden by the render tier or waiting for its delayed delete |
isPropVisible(id) |
boolean |
The entity exists and is not hidden |
getProp(id) |
table or nil |
The definition with entity, spawned and available |
getSpawnedProps() |
{ [id] = entity } |
Every spawned streamed and networked prop, hidden ones included |
setCanInteract(id, option, fn) |
true or false, reason |
Attach a client predicate fn(entity, id, option, data) to a prop's option. option = nil: every option of the prop. fn = nil removes it. Works for server and local props, also before the prop arrives. Reasons: 'invalid_id', 'invalid_interact_name', 'invalid_can_interact', 'not_owner', 'predicate_limit_reached' |
When a server prop and a client-only prop share an id, these return the server prop.
lua
-- client: draw a marker over a drop while it is spawned
local entity = exports.np_prophandler:getPropEntity('np_inventory:drop_42')
if entity ~= 0 then
local c = GetEntityCoords(entity)
DrawMarker(2, c.x, c.y, c.z + 0.5, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.2, 0.2, 0.2, 255, 255, 255, 160,
false, true, 2, false, nil, nil, false)
end
Local props ​
| Export | Returns | Description |
|---|---|---|
addLocalProp(def) |
true or false, reason |
A client-only streamed prop. Same definition, no networked. Reasons besides validation: 'resource_disabled', 'id_in_use' |
removeLocalProp(id) |
true or false, reason |
Reasons: 'unknown_prop', 'not_owner' |
removeAllLocalProps() |
count |
Remove every client-only prop of your resource |
createLocal(def, callback?) |
handle, entity or false, reason |
An immediate local prop. entity is 0 while the model loads; callback(handle, entity) runs once it exists (0 = failed). def.interact fires with the handle as id. Reasons: 'resource_disabled', 'local_limit_reached', 'invalid_callback', 'model_missing' and validation reasons |
deleteLocal(handle) |
true or false, reason |
Reasons: 'unknown_handle', 'not_owner' |
getLocalEntity(handle) |
entity or 0 |
Placement ​
| Export | Returns | Description |
|---|---|---|
startPlacement(options) |
handle or false, reason |
Start the placement ghost and gizmo. One runs at a time per client; a new one cancels the running one ('replaced'). Reasons: 'resource_disabled', 'model_missing', 'unknown_field', 'invalid_<option>' |
updatePlacement(handle, patch) |
true or false, reason |
Change options of your running placement, e.g. swap the model. {} runs validate again. Reasons: 'unknown_handle', 'not_owner', 'fixed_field' (frame, aim), 'model_missing' and the option reasons |
setPlacementValid(handle, valid, reason?) |
true or false, reason |
Push your own result, e.g. after a server check. Checked last, see Validity. nil clears it |
checkPlacement(handle) |
valid, reason, pose |
Validity right now, validate included. Nothing ends |
confirmPlacement(handle) |
true, pose or false, reason |
Confirm from your own key or form. Refused while invalid |
cancelPlacement(handle, reason?) |
true or false, reason |
onCancel runs with reason (default 'cancelled') |
stopPlacement(handle) |
true or false, reason |
End it silently, no callbacks |
getPlacement(handle?) |
pose or nil |
Without a handle: the running placement |
isPlacing() |
placing, handle, owner |
Attachments ​
| Export | Returns | Description |
|---|---|---|
attach(def) |
handle or false, reason |
Attach a prop to the local player's ped or def.entity. Reasons: 'resource_disabled', 'attachment_limit_reached', 'model_missing', 'invalid_owner', 'synced_requires_local_player' and the field reasons |
detach(handle) |
true or false, reason |
Reasons: 'unknown_handle', 'not_owner' |
getAttachedEntity(handle) |
entity or 0 |
0 until the model has loaded |
Doors ​
| Export | Returns | Description |
|---|---|---|
getDoor(id) |
table or nil |
The door as this client holds it, with applied (true while it is in the door system) |
isDoorLocked(id) |
boolean or nil |
nil for an unknown door |
setDoorCanInteract(id, fn) |
true or false, reason |
Attach a client predicate fn(id, locked, data) to a door's toggle prompt. fn = nil removes it. The server's checks stay the same. Reasons as for setCanInteract |
requestDoorToggle(id) |
boolean |
Send a toggle request. The server re-checks it. false when this client does not know the door |
Diagnostics ​
| Export | Returns | Description |
|---|---|---|
getDiagnostics() |
table |
epoch, revision, bucket, framework, interaction (provider), registered, available, spawned, hidden, loading, failed, active, maxActive, networked, locals, attachments, remoteAttachments, remotePlayers, world, worldRegistered, doors, doorsRegistered, interactables, predicates, predicateErrors, models, streamer (counters) |