Installation ​
Requirements ​
- A current FiveM server artifact with Lua 5.4 and OneSync enabled.
- oxmysql is required by this resource's manifest, including when using transient lifecycle exports.
- The SQL table in
sql/install.sqlfor persistent parking.
Persistent storage is opt-in, but oxmysql must be installed and started because the manifest declares it as a dependency. Framework, fuel, tuning and key integrations are optional and detected at runtime. See Integrations.
Install ​
- Place the folder in your resources directory as
np_vehiclehandler. - Run
sql/install.sqlagainst the server database if you will use persistent records. - Ensure oxmysql before the handler when persistence is enabled.
- Ensure
np_vehiclehandlerbefore resources that call its exports.
set onesync on
ensure oxmysql # required by the resource manifest
ensure np_vehiclehandler
ensure np_mechanic # optional tuning integration
ensure np_fuel # optional fuel integration
ensure np_vehiclekeys # optional keys bridge
No build step or NUI is required.
Register after ready ​
The in-memory registry is rebuilt when the handler restarts. Persistent records load from SQL; np_vehiclehandler:started fires after database loading completes. On each start, reconcile each stable ID: update a record already loaded from SQL, or register it if it does not exist. Non-persistent definitions need registration again after a handler restart.
local function registerFleet()
local id = 'np_fleet:unit-12'
local definition = {
model = 'police',
coords = vector4(452.1, -980.0, 25.7, 90.0),
bucket = 0,
props = { plate = 'UNIT12' },
metadata = { fleet = 'lspd', unit = 12 },
}
local existing = exports.np_vehiclehandler:getVehicle(id)
local ok, reason
if existing then
ok, reason = exports.np_vehiclehandler:updateVehicle(id, definition)
else
ok, reason = exports.np_vehiclehandler:registerStreamed(id, definition)
end
if not ok then print(('Fleet registration failed: %s'):format(reason)) end
end
AddEventHandler('np_vehiclehandler:started', registerFleet)
if GetResourceState('np_vehiclehandler') == 'started' and exports.np_vehiclehandler:isReady() then registerFleet() end
The started handler covers handler restarts. The immediate check covers a consumer started after the handler finished loading. Persistent rows are already loaded at that point, so reconcile with getVehicle instead of blindly registering the same ID again. Never create a second entity yourself for the same ID.
Database behavior ​
The handler uses the configured table name, np_vehiclehandler_vehicles by default. The table stores the stable ID, model, plate values, owner metadata, routing bucket, transform, properties and optional state/behavior/attachment/metadata JSON. Keep regular database backups. Transient registrations do not write rows; persistent registrations do.
Check startup ​
Watch the server console for the handler started message and SQL errors. Confirm the configured table exists before registering persistent vehicles. If the initial database load fails, the handler stays unready (isReady() is false) and registrations fail with not_ready; it does not switch to an unsaved memory-only mode. Fix the database/schema issue and restart the resource. Use getVehicle and the other lookup exports for tracked records; see Exports.