Skip to content

Behavior, attachments and local vehicles ​

The handler applies entity lifecycle on the server and native vehicle behavior on the current network owner. It does not change ownership or routing bucket from a client request. Behavior and attachment definitions are replicated with the vehicle record and retried when ownership moves.

Supported behavior fields ​

Use the behavior table in a server-owned definition or update it with updateVehicle.

Field Effect
doors Map door index to open (true) or shut (false). Supported indices are 0–5.
locked Lock state, applied through the vehicle door lock native.
engineOn Engine state.
engineDisabled Mark the vehicle undriveable.
handling Map handling field names to numeric values applied with the vehicle handling native.
suspensionHeight Set suspension height.
anchor Set the boat anchor and freeze-when-anchored state for boats.
gear Set current gear.
roof Raise (true) or lower (false) a convertible roof.
lua
exports.np_vehiclehandler:updateVehicle('np_fleet:boat-3', {
  behavior = {
    engineDisabled = true,
    anchor = true,
    doors = { [0] = false },
  },
})

These controls are native dependent. Validate vehicle models and chosen handling field names in your artifact. Keep gameplay permissions in the calling server resource.

Attachments and trailers ​

Use setAttachment(child, parent, offset, rotation, options) to attach one tracked vehicle to another. IDs may be resolved from the handler's supported aliases. The handler stores the parent stable ID, offset, rotation, collision and soft-pinning flags, trailer mode and optional group label. It aligns the child routing bucket with its parent. Cycles and self-attachments are rejected.

lua
local ok, reason = exports.np_vehiclehandler:setAttachment(
  'fuel:supply:job-48:trailer',
  'fuel:supply:job-48:truck',
  { x = 0.0, y = -6.0, z = 0.2 },
  { x = 0.0, y = 0.0, z = 0.0 },
  { trailer = true, group = 'fuel:supply:job-48' }
)

clearAttachment(vehicle) clears the relationship. This is stored relationship metadata; when target entities are not yet in scope, the client retries application as required. Do not rely on native attachment replication alone for consumer ownership rules.

Local previews and display vehicles ​

Client CreateLocal creates a non-networked local vehicle intended for previews or ghosts. Its options include model, coords, heading, props, timeout, collision, keepPhysics, alpha, invincible and ghost. Use DespawnLocal when finished; the handler also cleans up resource-owned local entities on resource stop.

The lower-case createLocal(model, coords, heading, props) form is available for older callers. SetLocalProps only applies to a local helper entity known to the handler. getProps / GetVehicleProps and setProps / SetVehicleProps collect or apply supported client properties on a vehicle.

Seats, NPC drivers and engine vetoes ​

GetSeats(vehicle) returns a driver handle and occupied passenger seats. GetSeatOf(ped?) returns the vehicle and seat for a ped; without an argument it uses the local player's ped.

SpawnNpcDriver(vehicle, opts) uses np_npchandler's ticketed networked NPC path when available and falls back to a local driver. The helper does not create a durable vehicle. DriveWaypoints(ped, vehicle, points, style, speed) drives through the supplied list in order, subject to per-point timeout and stop radius limits.

AddEngineVeto(fn) is a local client policy hook. A handled vehicle also checks server authorization when Config.Integrations.serverEngineCheck is enabled (the default). The current network owner requests a server check while seated as driver; engine authorization is denied while the first response is pending, and the cached result is refreshed periodically. CanStartEngine(vehicle) reports the combined local and server result, but GTA engine controls should still be enforced by the calling gameplay resource where appropriate.

The server canStartEngine(source, value) export checks registered server vetoes and, when np_vehiclekeys is running, calls CanAccess(source, plate, 'drive'). A stopped key resource means no provider is configured and allows by default; an active provider that denies or fails to resolve the vehicle denies. Resources can register registerEngineVeto(name, callback) with a server callback (source, id, plate, record) that returns false, reason to deny.