Consumable item

Welcome to user guide to add items

If you want to create a new item which can be consumed, for example a new donut, or a new drink like a tea, remember to add this to your esx_basicneeds if you use ESX or, if you use QBCORE in your case you must add it to your qb-smallresources in config.lua

Remember that you can use the system that gives you our inventory, and also the resource that gives you ESX or QBCore natively, just be careful not to have consumable items with our system and in your resource of that either esx-basicneeds or qb-smallresources to avoid problems.

Step by step to create a usable item

This is an explanation for you to understand, it is not the example code, the example code will be up to the last thing for you to copy and use as an example, remember to change everything if you know what you are doing to your liking.

Please read carefully. In case of using qb-core, you must use your shared in qb-core, not this shared, this section is exclusive for esx!

qs-inventory/shared/items.lua
['example_item'] =  {
        ['name'] =  'example_item',
        ['label'] =  'Label item',
        ['weight'] =  200, -- Weight in kg
        ['type'] =  'item', -- 'item' or 'weapon'
        ['image'] =  'example_item.png', -- image name on html/images/example_item.png
        ['unique'] =  false, -- Can stack the item?
        ['useable'] =  true, -- true = You can use, false = You can't use
        ['shouldClose'] =  true, -- Close the inventory when use
        ['combinable'] =  nil,
        ['description'] =  'Nice to eat', -- Label on metadata (inventory)
        ["created"] = nil, -- Don't touch (Depenendy of decay)
        ["decay"] = 0.01,  -- The higher the number, the faster it breaks, the lower the opposite.
        ["delete"] = false -- true if you want it to be removed once broken, if it's false it stays broken in your inventory

Now proceed to make the consumable item, with this we will help the ['client'] that will give you the necessary functions with the values to enter in this configuration, where you can add a status, either hunger or thirst, the time of use, the animation, the prop, disable movements and if you want the item to be removed after use or not, is a nice and easy configuration that you can follow.

        ['client'] = {
            status = {
                thirst = 200000, -- or hunger
            },
            usetime = 2500, -- Progressbar timer
            anim = {
                animDict = 'mp_player_intdrink', -- Animations
                anim = 'loop_bottle' -- Animations
            },
            prop = {
                model = 'p_wine_glass_s', -- Animation prop
                coords = vec3(0.02, 0.02, -0.08), -- Prop coords
                rotation = vec3(0.0, 0.0, 0.0) -- Prop Rotation
            },
            disable = {
                disableMovement = true, -- Disable events
                disableCarMovement = true, -- Disable events
                disableMouse = false, -- Disable events
                disableCombat = true, -- Disable events
            },
            removeAfterUse = true -- Remove after use item?
        }
    },

Example code

Now you are clear of every part of how to make a usable item, remember not to have this usable item in your esx_basicneed or qb-smallresources, if you are creating it here too because it can cause you problems, the following code is an example of how the item would look like in your shared/items.lua of utility.

qs-inventory/shared/items.lua
['tosti']                        = {
    ['name'] = 'tosti',
    ['label'] = 'Grilled Cheese Sandwich',
    ['weight'] = 200,
    ['type'] = 'item',
    ['image'] = 'tosti.png',
    ['unique'] = false,
    ['useable'] = true,
    ['shouldClose'] = true,
    ['combinable'] = nil,
    ['description'] = 'Nice to eat',
    ['created'] = nil, 
    ['decay'] = 0.01,
    ['delete'] = false,
    ['client'] = { --integrated part to be consumable
        status = {
            hunger = 200000,
        },
        usetime = 2500,
        anim = {
            animDict = 'mp_player_inteat@burger',
            anim = 'mp_player_int_eat_burger_fp'
        },
        prop = {
            model = 'prop_cs_burger_01',
            coords = vec3(0.02, 0.02, -0.02),
            rotation = vec3(0.0, 0.0, 0.0)
        },
        disable = {
            disableMovement = true,
            disableCarMovement = true,
            disableMouse = false,
            disableCombat = true,
        },
        removeAfterUse = true
    } --End of integrated part
},

Last updated