Don't forget to remove qb-inventory folder (if you use it) from your resource folder before restarting your server after these changes
If you used core_inventory version 1.4.1 or greater, please jump to 2. Framework functions
Add or Replace functions by these functions in qb-core/server/player.lua
Note : All of these functions should be placed inside the CreatePlayer function
function self.Functions.AddItem(item, amount, slot, metadata, inventory)
inventory = inventory or 'content-' .. self.PlayerData.citizenid
amount = amount or 1
return exports['core_inventory']:addItem(inventory, item, tonumber(amount), metadata)
end
function self.Functions.RemoveItem(item, amount, slot, inventory)
inventory = inventory or 'content-' .. self.PlayerData.citizenid
amount = amount or 1
return exports['core_inventory']:removeItem(inventory, item, tonumber(amount))
end
function self.Functions.ClearInventory(inventory)
inventory = 'content-' .. self.PlayerData.citizenid
return exports['core_inventory']:clearInventory(inventory)
end
function self.Functions.GetItemByName(item, inventory)
inventory = inventory or 'content-' .. self.PlayerData.citizenid
return exports['core_inventory']:getItem(inventory, item)
end
function self.Functions.GetItemsByName(item, inventory)
inventory = inventory or 'content-' .. self.PlayerData.citizenid
return exports['core_inventory']:getItems(inventory, item)
end
-- NOTE : This is a deprecated function, only work with qb-inventory by default
function self.Functions.GetItemBySlot(slot)
slot = tonumber(slot)
return self.PlayerData.items[slot]
end
If using new qb add the last function as well
Note : This function should be placed inside the CreatePlayer function
Replace QBCore.Functions.HasItem in qb-core/server/functions.lua
function QBCore.Functions.HasItem(source, items, amount)
local xPlayer = QBCore.Functions.GetPlayer(source)
local item = xPlayer.Functions.GetItemByName(items)
if item ~= nil and item.amount >= amount then
hasItem = true
else
hasItem = false
end
return hasItem
end
Replace QBCore.Functions.HasItem in qb-core/client/functions.lua
function QBCore.Functions.HasItem(items, amount)
local isTable = type(items) == 'table'
local isArray = isTable and table.type(items) == 'array' or false
local totalItems = #items
local count = 0
local kvIndex = 2
if isTable and not isArray then totalItems = 0
for _ in pairs(items) do totalItems += 1 end
kvIndex = 1
end
for _, itemData in pairs(QBCore.Functions.GetPlayerData().items) do
if isTable then
for k, v in pairs(items) do
local itemKV = {k, v}
if itemData and itemData.name == itemKV[kvIndex] and ((amount and itemData.amount >= amount) and (not isArray and itemData.amount >=v) or (not amount and isArray)) then
count += 1
end
end
if count == totalItems then
return true
end
else -- Single Items as String
if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then
return true
end
end
end
end
In qb-core/shared/main.lua, in QBShared.StarterItems remove all item
3. Global configuration
Add the image of your items in core_inventory/html/img folder.
All your images should have the same name as your items. For example, if you have an item called sandwich_bacon, the image name should be sandwich_bacon.png.
Only .png image are include in the FXManifest so be sure to use this extension for your images
Add default items that are included in ITEMS.txt file in your qbcore/server/shared/items.lua file or use the file with default qb-core item in it. Categories for weapon items are already set and the size of the weapon too.
For all your weapons items in your items.lua file, addcategory='weapons'(don't forget the s at the end of weapons). Or if you have a fresh server, you can use the items.lua we provide in [items] folder. All weapons have a size and the right category already set on it.
Please make sure you set weaponswith the s at the end
Open config_weapon.lua and choose your attachment component mode, then add the attachments in your items.lua related to the mode you choose.
for each items, configure the category, if you don't set category, the default apply by the script is misc
the stack property come from the category apply to the item. The default one apply is misc and the stack value is 2. If you want to increase / decrease this number, open core_inventory/config.lua and search for ItemCategories section. You can create a new category and then apply this category in your item.lua file with category = 'yourCategoryName'.
You can configure the ['x'] and ['y'] value for each item, x is the number column take by the item, y the number of row. The default value apply by the script is 1x1
For backpack item, you need to set the backpackModel (list can be find here) and the backpackTexture (default is 0 for each backpack model)
4. Money as item
in qbcore/config.lua, please make to modify moneytypes and dontAllowminus like this :
In core_inventory/config.lua make sure to enable the money as item option and set the right account name in the option, for example :
MoneyAsItem = true, -- enable / disable money as item
AccountMoneyAsItem = 'cash', -- account name
ItemMoneyAsItem = 'money', -- item name
DirtyMoneyAsItem = true, -- enable / disable balck money as item
AccountDirtyMoneyAsItem = 'black_money', -- account name
ItemDirtyMoneyAsItem = 'markedbills', -- item name
Make sure to have the item money and the item markedbills in your items.lua and for each one make sure to have the right category (money for moneyitem and markedbill for markedbills item) :