[UPDATED] QBCore - How to add items correctly by Yorzen

Hey there,
Yorzen here with a quick & easy tutorial for adding items into your server. [QBCore framework]

Things you will need:

  • 100x100px .png file of your desired item.
  • Access to the FTP Server. (can be used locally)
  • Patience and a functioning brain :wink:
  • Copy & Paste skills (Itā€™s NOT a joke, while dealing with huge files such as items.lua be careful)

Now carefully follow these instructionsā€¦

    1. Open /resources/[qb]/qb-core/shared/items.lua (MAKE BACKUP BEFORE EDITING!)

items.lua: (Example Line of Code)

coffee = { name = 'coffee', label = 'Coffee', weight = 200, type = 'item', image = 'coffee.png', unique = false, useable = true, shouldClose = true, description = 'Buy me a cup of Caffeine.' },

Then,

    1. Add the correct line of code of a similar item (copy & paste similar line of code) edit the item details such as weight, description and so onā€¦ then save changes.
    1. Drag & Drop the filename.png into /resources/[qb]/qb-inventory/html/images folder.
      FILENAME SHOULD BE IDENTICAL TO THE NAME IN THE CODE!
    1. Add thirst and hunger values for drinks and food go to /resources/[qb]/qb-smallresources/config.lua MAKE BACKUP BEFORE EDITING!
    1. Go to /resources/[qb]/qb-smallresources/server/consumables.lua and copy and edit this

example code:

QBCore.Functions.CreateUseableItem("coffee", function(source, item)
    local Player = QBCore.Functions.GetPlayer(source)
	if Player.Functions.RemoveItem(item.name, 1, item.slot) then
        TriggerClientEvent("consumables:client:Eat", source, item.name)
    end
end)
    1. Rename ā€œcoffeeā€ to your desired item name If consumable and save changes.

Optional - Add an item to a Shop / Gas Station / Hardware Store etcā€¦:

    1. Make sure the item is properly added to the server both in items.lua file & images folder.
    1. Go to /resources/[qb]/qb-shops/config.lua and edit as shown below (example):
      (MAKE BACKUP BEFORE EDITING!)
        [69] = {             -- Represent the slot of the item in store, replace 69 with whatever you want..
            name = "coffee", -- This is Important, use **only** the same name across all scripts...
            price = 10,      -- The price of the item, is here change it to how much you want.
            amount = 420,    -- How MANY items are in stock of the store...
            info = {},       -- Description of the item
            type = "item",   -- guess what, It's an item type item... yea.. go figure what jbib is.. :D
            slot = 69,       -- Use actual number that makes sense, this is just an example
        },

Important notes: The Item Number [ ] in config.lua must be incremented by +1 *Last item on the list copy and paste and change both [x] and slot = x increase by +1 (Example: [14] turns to [15])
Important: .png file resolution must be 100 x 100px
Important: Edit values of Weight, Price, Description etcā€¦

Verify and save all config files and restart the server to see the changes.

If youā€™re still struggling let me know down in the comments Iā€™ll do my best to simplify it a little more.

P.S Iā€™ve tried to look for a tutorial and didnā€™t find any of this topic thought it could help some of you out there :slight_smile: good luck!

And if I helped you, Iā€™m glad

24 Likes

Nice tuto, it will become handy for beginner developers on qbcore.

4 Likes

Thank you sir :slight_smile:

How would i add a table to my database for my items

1 Like

Thanks, really helpful!

1 Like

Has there been an update at some point within the framework coding since you posted this?

Context: I had a server previously, running an older version of Qbus and everything worked perfectly after following these steps given by yourself <3

I have since updated Qbus to itā€™s latest framework, and now additional items I have added donā€™t seem to work.

I have added all the images to qb-inventory/html/images
Images added

I have added all the items to qb-core/shared/items.lua
Items added to qb-core

However, the problem I find, is when I add the items to qb-smallresources/config.lua (like I did before)
Seen here
The game then decides that I canā€™t use the items

Soā€¦ I checked out the qb-smallresources/server/consumables.lua and noticed a change in the way the script is presented to how I did it previously.
Consumables differences shown here

I tested out using a copy of the consumables.lua from my old server into my new server and then the characters were able to consume a product, emote eating a burger or drinking a bottle, but it would not replenish any hunger or thirst. It also started flagging up that ā€˜progressbarā€™ couldnā€™t detect the events required.

So now I have reverted back to the default qb-smallresources and will have to wait on some eye opening answer for my problem until I attempt it again.

1 Like

hello, I have some issues.

I created blackmoney as item, and when I tried the item (doing a robbery) my inventory just shows 100 (not the real amount that i robbed)

I edited the max amount on qb-inventory but itā€™s always showing just 100.

I donā€™t know if its an error of the item created or what, but with the cash its working perfectly.

New Format is Made On latest Nowadays looking like this aswell gonna throw up a tutorial for all thats been changed in the lastest ones later on aswell :smiley:

Config.Products = {
[ā€˜normalā€™] = {
{name = ā€˜tostiā€™, price = 20, amount = 100, info = {}, type = ā€˜itemā€™},
{name = ā€˜water_bottleā€™, price = 20, amount = 100, info = {}, type = ā€˜itemā€™},
{name = ā€˜kurkakolaā€™, price = 20, amount = 100, info = {}, type = ā€˜itemā€™},
{name = ā€˜twerks_candyā€™, price = 20, amount = 100, info = {}, type = ā€˜itemā€™},
{name = ā€˜snikkel_candyā€™, price = 20, amount = 100, info = {}, type = ā€˜itemā€™},
{name = ā€˜sandwichā€™, price = 20, amount = 100, info = {}, type = ā€˜itemā€™},
},

1 Like

Thanks for letting me know, I will update it to the new version of QB-Core Items.lua

1 Like

hello voici mon problem jā€™ai refait tout les Ć©tape mais ca change rien [ script:qb-inventory] AddItem: Invalid item

Thanks men

Any update to this ?

1 Like

Updated the tutorial to the latest version of QBCore :purple_heart: