Skip to content

Conversation

@Skulrag
Copy link

@Skulrag Skulrag commented Jan 22, 2026

  • Add RegisterVehicleInventory server side function.
  • Remove useless variable line 94 : local GetVehicleNumberPlateText = GetVehicleNumberPlateText

Function is inspired from the automatic inventory creation when a player open a trunk or gloveboxe if it does not exists :

if data.type == 'trunk' or data.type == 'glovebox' then
local plate = data.id:sub(6)
if server.trimplate then
plate = string.strtrim(plate)
data.id = ('%s%s'):format(data.id:sub(1, 5), plate)
end
inventory = Inventories[data.id]
if not inventory then
local entity
if data.netid then
entity = NetworkGetEntityFromNetworkId(data.netid)
if not entity then
return shared.info('Failed to load vehicle inventory data (no entity exists with given netid).')
end
data.entityId = entity
else
local vehicles = GetAllVehicles()
for i = 1, #vehicles do
local vehicle = vehicles[i]
local _plate = GetVehicleNumberPlateText(vehicle)
if _plate:find(plate) then
entity = vehicle
data.entityId = entity
data.netid = NetworkGetNetworkIdFromEntity(entity)
break
end
end
if not entity then
return shared.info('Failed to load vehicle inventory data (no entity exists with given plate).')
end
end
if not source then
source = NetworkGetEntityOwner(entity)
if not source then
return shared.info('Failed to load vehicle inventory data (entity is unowned).')
end
end
local model, class = lib.callback.await('ox_inventory:getVehicleData', source, data.netid)
local storage = Vehicles[data.type].models[model] or Vehicles[data.type][class]
local dbId
if server.getOwnedVehicleId then
dbId = server.getOwnedVehicleId(entity)
else
dbId = data.id:sub(6)
end
inventory = Inventory.Create(data.id, plate, data.type, storage[1], 0, storage[2], false, nil, nil, dbId)
end

Every framework should be able to provide all required parameters.

Open to comments and improvements.

Introduces Inventory.RegisterVehicleInventory to allow registering a vehicle's trunk or glovebox inventory on the server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant