This is how i made it work.
Create item in qbcore shared named (club)
in qb-mulitcharacter/server/main.lua put this on the botom and modify according your garage system tables :
QBCore.Functions.CreateUseableItem('club', function(source)
local src = source
--local newData = {}
local Player = QBCore.Functions.GetPlayer(src)
local cid = Player.PlayerData.citizenid
-- Add the vehicle data to the database
local vehicleData = {
model = "club", -- replace with the actual model name or ID
plate = "DRP" .. math.random(11111, 99999), -- replace with a proper plate generation logic
}
MySQL.Async.execute('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (@license, @citizenid, @vehicle, @hash, @mods, @plate, @garage, @state)', {
['@license'] = Player.PlayerData.license,
['@citizenid'] = cid,
['@vehicle'] = vehicleData.model,
['@hash'] = GetHashKey(vehicleData.model),
['@mods'] = '{}',
['@plate'] = vehicleData.plate,
['@garage'] = 'pillboxgarage',
['@state'] = 1
}, function(rowsChanged)
TriggerClientEvent("QBCore:Notify", src, "Voertuig staat nu in pillbox garage!", "success")
-- Remove the item from the player's inventory
Player.Functions.RemoveItem('club', 1)
TriggerClientEvent('inventory:client:ItemBox', 'club', "remove")
end)
end)
In qb-multicharacter/client/main.lua place this code to have the usable item:
RegisterNetEvent('your-resource-name:useClubItem')
AddEventHandler('your-resource-name:useClubItem', function()
TriggerServerEvent('QBCore:Server:UseableItem', 'club')
end)
and in your qbcore starter items add the item “club” to start with !
When the player is created they have the item in their inventory and upon use the vehicle is placed in databse for them to take out of pillboxgarage.
when used , the item is then removed from inventory!
Hope this helps someone !