Skip to content

Attached props ​

Props attached to a ped or another entity: a phone in the hand, a carried box, an ID card. No networked objects are involved. Every client that should see the prop renders its own local copy.

From the client ​

client

lua
local handle = exports.np_prophandler:attach({
  model = 'prop_npc_phone_02',
  bone = 28422,
  offset = vector3(0.0, 0.0, 0.0),
  rotation = vector3(0.0, 0.0, 0.0),
  synced = true,
  key = 'phone',
})

-- later
exports.np_prophandler:detach(handle)
  • The local copy is created on this client right away, once the model is loaded. attach does not wait: use getAttachedEntity(handle) to get the entity, 0 until it exists.
  • Without entity, the attachment follows the local player's ped. It is rebuilt when the ped is created again (model change, respawn).
  • With entity = someHandle, it is attached to that entity, on this client only. It is dropped when that entity is gone. entity and synced can't be combined ('synced_requires_local_player').
  • An attachment that keeps falling off is rebuilt with growing delays (1 s, 2 s, 4 s, …) and given up after attachments.maxRebuilds (5) attempts in a row.
  • At most attachments.maxLocal (32) per client. Attachments belong to the calling resource and are removed when it stops.

Synced attachments ​

With synced = true, other players see the prop too:

  1. The client sends the attachment to the server.
  2. The server validates it, forces collision off, checks the rate limit (server.attachments.maxUpdatesPerWindow, 20 per 5 s) and the optional server.attachments.clientModels allowlist.
  3. The server writes it into the player's state bag np_prophandler:attached.
  4. Every other client renders its own copy on that player's ped while the ped is in scope and within attachments.renderDistance (150 m), up to attachments.maxRemote (128) copies. Copies are rebuilt when the ped is created again and deleted when the player leaves scope or drops.

key names the slot. A new synced attach with the same key from the same resource replaces the old one. Without key, each handle gets its own slot.

Removals are never rate-limited, so detach always clears the prop. The client keeps the state it wants per key: adds over the server's budget are queued, and anything its own state bag does not show yet (a removal still present, an add still missing) is sent again, at most attachments.maxResends (5) times.

From the server ​

server

For a carry the server decides, for example a mission crate:

lua
-- server
exports.np_prophandler:setPlayerAttachments(source, 'crate', {
  {
    model = 'prop_cs_cardbox_01',
    bone = 60309,
    offset = vector3(0.025, 0.08, 0.255),
    rotation = vector3(-145.0, 290.0, 0.0),
  },
})

-- drop it
exports.np_prophandler:setPlayerAttachments(source, 'crate', nil)
  • The list may hold one or more attachments, or a single attachment table instead of a list.
  • The key is namespaced by the calling resource, so two resources can use the same key. The entries are removed when that resource stops.
  • All keys of one player, from the client and the server, share server.attachments.maxPerPlayer (8) entries. Over that, the call returns false, 'attachment_limit_reached'.
  • Server attachments may set collision = true. Client-sent ones never collide.
  • The player's own client renders server attachments on its ped as well.

getPlayerAttachments(source) returns everything in a player's bag.

Attachment fields ​

Field Default Notes
model required Model name or hash. Checked against allowedModels when set
bone 28422 on peds, 0 otherwise Ped bone id (GetPedBoneIndex). For other entities, the bone index
offset 0, 0, 0 At most definition.maxAttachOffset (5.0) per axis
rotation 0, 0, 0 Degrees
collision false Always false for client-sent synced attachments
alpha none 0 to 255
textureVariation none 0 to 63
entity local player Client only. Not with synced
synced false Client only. Publish through the player state bag
key per handle Client only. Letters, digits and . _ : -, up to 32 characters

entity, synced and key are refused in setPlayerAttachments ('invalid_attachment').

The state bag is written by the server only ​

Clients can write their own player state bag. np_prophandler does not trust it:

  • If a client writes np_prophandler:attached itself (LocalPlayer.state:set), the server puts its own table back on the next tick.
  • Other clients ignore a bag with more keys or entries than server.attachments.maxPerPlayer.
  • Client- and server-driven keys share one table and never overwrite each other.