Vehicle for starter item qbcore

Hello all , im in a bit of a pickle with something i would like to achieve but i cant find anything for this.
The title says it all but i will explain a bit more.

We have our standard starter items for any newly created character on the server and i would like to implement to give a car with the starter items…
Can anybody point me in the right direction to do this? i started looking into our multichar to write another function to create a vehicle with license in the player_vehicles but im sure if this is the correct way.

thanks for the help already and sorry if this is not the place to ask my question.

Hey!

You’re on the right track. You could insert a vehicle into the database simultaneously as the multicharacter script gives the starter items.

The function for starter items can be found here qb-multicharacter/server/main.lua:L6
A way to insert a vehicle can be found here qb-vehicleshop/server.lua:L201

What is left is to match the values to the player_vehicles table.
Follow a similar path as the vehicleshop script and customize the variables to your liking.

1 Like

have a example script?

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 !

1 Like

tysvm

1 Like