Skip to content

Networked props ​

A networked prop is one OneSync object that every player shares. Use it when physics or position must be the same for everyone, for example a crate players push around. Everything else should be a streamed prop: it costs no network entity.

lua
-- server
exports.np_prophandler:registerProp({
  id = 'np_drugs:crate_7',
  model = 'prop_box_wood02a',
  coords = vector3(1391.2, 3605.8, 38.9),
  networked = true,
  frozen = false,
  spawnDistance = 60.0,
})

Lifecycle ​

The server owns the entity. It runs a pass every server.networked.pollIntervalMs (1 s):

  1. Player positions are read into a grid (server.networked.cellSize, 128 m).
  2. A prop whose routing bucket has a player within spawnDistance gets its entity: CreateObjectNoOffset(model, x, y, z, true, true, false), then the rotation, FreezeEntityPosition, SetEntityRoutingBucket (bucket 0 when routingBucket is unset) and SetEntityOrphanMode(entity, 2). The entity carries the state bag np_prophandler:id with the prop id.
  3. An existing entity counts players up to spawnDistance + server.networked.despawnMargin (15 m). Once nobody has been in range for server.networked.despawnDelayMs (15 s), it is deleted. A disabled prop is deleted at once.
  4. An entity deleted by something else (entityRemoved) is created again after server.networked.recreateDelayMs (2 s) if a player is still near.
  5. A changed definition (updateProp) deletes the entity. The next pass creates the new one. A dynamic prop is followed instead: it is created again where it was left.

Net id changes go to every client on the sync channel, in one message per pass.

spawnProp(id) creates the entity right away instead of on the next pass (the maxActive cap still applies) and returns entity, netId, for when a client needs the net id at once.

Limits: server.networked.maxRegistered (256) networked props registered, server.networked.maxActive (64) entities at the same time, server.networked.maxCreatesPerTick (8) created per pass. At the maxActive cap, creation order is registry order, not nearest first.

Props that move (dynamic) ​

A plain networked prop is created at, and streamed around, the coords it was registered with. With dynamic = true (networked only) the server follows the entity instead: each pass reads its position and rotation, decides creation and deletion around that point, and when the entity is deleted (nobody near, or by something else) it is created again where it was left, with that rotation.

lua
-- server: an ATM players rip out and drag away
exports.np_prophandler:registerProp({
  id = 'np_banking:ripped_' .. id, model = 'prop_atm_01', coords = atm.coords,
  networked = true, dynamic = true, frozen = false, spawnDistance = 150.0,
})
local entity, netId = exports.np_prophandler:spawnProp('np_banking:ripped_' .. id)  -- now, not on the next pass
local coords, rotation = exports.np_prophandler:getPropCoords('np_banking:ripped_' .. id)
exports.np_prophandler:setPropCoords('np_banking:ripped_' .. id, vector3(...), vector3(0.0, 0.0, 90.0))  -- rotation optional
  • Moving it is up to you: physics (frozen = false), a client with network control (SetEntityCoords, AttachEntityToEntity, ropes), or the server with setPropCoords, which moves the entity and the stored position, also while it is despawned.
  • updateProp keeps a dynamic prop where it is unless the registered coords or rotation change.
  • The entity handle changes whenever the entity is created again. Look it up each time with getPropEntity / getPropNetId (server) or getPropEntity / np_prophandler:spawned (client) instead of keeping one.
  • getPropCoords(id) answers for every prop: the live entity of a networked prop, else where it will be created, else the registered coords.
  • setPropCoords works on every networked prop of your resource. A non-dynamic one keeps the new place until its next updateProp or setPropEnabled. Streamed props move with updateProp.
  • The position is read once per pass (1 s). An entity moved and deleted within one pass comes back where the previous pass saw it.

On the client ​

Clients get the entity through normal entity streaming. np_prophandler matches it to the prop by its net id and the entity state bag np_prophandler:id (net ids are reused, so the state bag decides). When it streams in for a client:

  • alpha, lodDistance, textureVariation and invisible are applied locally, and collision is turned off when collision = false.
  • The interact option is added.
  • np_prophandler:spawned fires with (id, entity, data). When it streams out, np_prophandler:despawned fires.

getPropEntity returns the entity on the client while it is streamed in. On the server, getPropEntity and getPropNetId return it while it exists.

Differences from streamed props ​

Streamed Networked
Who sees it Players for whom it is available Decided by entity scope and the routing bucket. jobs / gangs / hours only gate the interact option
routingBucket unset All buckets Bucket 0
placeOnGround Allowed Refused with 'networked_place_on_ground': the server has no ground probe
renderDistance, despawnDelayMs Per client Not used. The server's despawnMargin and despawnDelayMs apply
interact with server = true Sends net id 0 Sends the entity's net id
Missing model Detected on the client, never retried The server cannot check it. A bad model creates an entity clients cannot draw
Position Fixed Fixed, or follows the entity with dynamic = true
Who registers it The server, or a client with addLocalProp The server only. addLocalProp refuses it

When np_prophandler stops

It deletes every networked entity it created. Clients forget the props without deleting anything, because the server owns those entities.