Skip to content

Persistent parking ​

Persistent parking keeps a vehicle record across handler and server restarts. It is opt-in and uses oxmysql. A streamed record's database row remains while its world entity is absent; the entity is created again when a player in the matching routing bucket comes within the configured radius.

Register a parked vehicle ​

lua
local id = 'np_garage:owned:3812'
local ok, reason = exports.np_vehiclehandler:registerPersistent(id, {
  model = 'sultan',
  coords = vector4(215.2, -810.3, 30.7, 158.0),
  bucket = 0,
  streamed = true,
  props = { plate = 'NP3812' },
  owner = 'char:3812',
  metadata = { garage = 'legion', stored = false },
})

Use an ID that remains the same when the resource restarts. Registering with registerStreamed is equivalent to opting into persistent streamed mode. Set streamed = false for a persistent entity that should remain present independent of nearby players.

What gets saved ​

The schema stores ID, model, assigned and real plate, owner, routing bucket, transform, props, state, behavior, attachment, metadata, persistent/streamed flags and a revision. Server-owned fields come from the handler. Tuning properties are refreshed through a one-time capture request to the current network owner.

Snapshots are bounded by Config.Snapshot limits. A non-owner cannot submit a snapshot; expired, mismatched or reused tokens are rejected. The server does not accept client commands to spawn, delete or change ownership.

Remove versus stream out ​

Spatial streaming despawns only the entity and retains the record. Calling despawn(id) on a persistent record removes that record and saved row, so it will not return after restart. The internal stream-out path keeps the row. Do not use the public remove flow for temporary distance cleanup.

Likewise, deleting a record because a garage has stored or transferred the vehicle should be an explicit handler removal. Persisted records are world vehicles; a garage should own the transition and prevent the old record from being registered again.

Custody handoff ​

setCustody(id, { active = true, recordId = ..., status = ... }) is a guarded hook for calls originating from np_impound or np_garages. It persists custody state and despawns the active entity while retaining the vehicle record. Custodied records are excluded from streamed respawn and explicit spawn requests fail with vehicle_in_custody. Clearing custody removes that state; an always-live (streamed = false) record is spawned immediately, while a streamed record becomes eligible on the next spatial pass. The persisted authority field identifies np_impound as the custody subsystem. This export does not implement a full garage or impound workflow by itself.

Restart sequence ​

On resource start the handler loads valid SQL rows, adopts matching existing OneSync entities after a resource-only restart, rebuilds IDs and the spatial index, and announces np_vehiclehandler:started. After a full server restart, persistent streamed = false records create their server entities during recovery; streamed = true records wait for a nearby player in the matching bucket. Each consumer should register its definitions after started. Ensure the schema and oxmysql are ready before relying on persistent spawn behavior. If the initial query fails, the handler remains unready and does not accept registrations until the resource is restarted after correcting the database.

Live adoption requires a private resource KVP mapping of the stable ID to its network ID and the current server process epoch. Client state tags alone cannot authorize adoption. Durable state, custody and behavior remain authoritative; an adopted entity keeps its live tuning until an authenticated snapshot captures it. Full server restarts invalidate the previous process mappings.

Mutations hold a per-record guard through database writes. A competing operation returns busy; callers should retain their existing state and retry. A failed durable removal leaves the managed entity available for retry.