CodeM Inventory

Improve compatibility between our Meth Crafting & codem-inventory

Please follow all the instructions below carefully! The steps below are required in order to make codem-inventory work properly with our meth cooking script.

Part 1 - Add New Function

Step 1

The first part to making codem-inventory work smoothly with our meth script is by adding a new function to add items into a stash. To get started go to: codem-inventory/editable/serverexport.lua file line 982 and hit enter twice to create some blank space. It should look like this:

Step 2

Then, copy the code below and paste it where we created the blank space from above.

function AddStashItem(stashId, item, count, slot, metadata)
    if not stashId or not item then return end
    if not count then count = 1 end
    local stash = ServerStash[stashId]
    if not stash then return end
    local itemData = Config.Itemlist[item]
    if not itemData then return end
    if not slot then
        slot = FindFirstEmptySlot(stash.inventory, Config.MaxSlots)
        if not slot then return end
    end
    local added = false
    for k, v in pairs(stash.inventory) do
        k = tostring(k)
        if not v.unique or not itemData.unique then
            if v.name == itemData.name and k ~= slot then
                v.amount = v.amount + count
                added = true
                break
            end
        end
    end
    if not added then
        stash.inventory[slot] = {
            name = itemData.name,
            label = itemData.label or itemData.name,
            weight = itemData.weight or 0,
            type = itemData.type or 'item',
            amount = count,
            usable = itemData.usable or false,
            shouldClose = itemData.shouldClose or false,
            description = itemData.description or '',
            image = itemData.image or '',
            unique = itemData.unique or false,
            slot = slot,
            ammotype = itemData.ammotype or nil
        }
    end
    if metadata then
        if next(metadata) ~= nil then
            if not stash.inventory[slot].info then
                stash.inventory[slot].info = {}
            end
            stash.inventory[slot].info = {}
            stash.inventory[slot].info = metadata
        end
    end
    UpdateStashDatabase(stashId, stash.inventory)
end

Step 3

After pasting the code above from Step 2 into the serverexports.lua file then go down to line 1065. It should be the bottom of a list of exports. Hit enter to create a new line and add the following code:

exports('AddStashItem', AddStashItem)

After adding the line of code from above, it should now look like this:

Part 2 - Displaying Metadata

The last thing we must do is update the metadata.js file found in the config folder of codem-inventory that will allow the information attached to certain items display on hover in your inventory. Follow the steps below to get started!

Step 1

Navigate to codem-inventory/config/metadata.js & open this file in Visual Studio Code or a similar editor. Search for the item "lawyerpass" (at the time of this writing it is found on line 36). Then, place your cursor at the end of this code block, just like the image example below:

Step 2

Hit enter to create a new, empty line. And paste in the following code:

// Start of lation_meth items
} else if (item.name.match("ls_liquid_meth") || item.name.match("ls_meth") || item.name.match("ls_meth_tray") || item.name.match("ls_meth_box")) {
    let infoData = [
        { label: "Strain", value: iteminfo.strain || "Unknown" },
        { label: "Purity", value: iteminfo.purity || "Unknown" }
    ];
    returnString = infoData;
} else if (item.name.match("ls_ammonia") || item.name.match("ls_iodine") || item.name.match("ls_acetone")) {
    let infoData = [
        { label: "Remaining", value: iteminfo.quality || "Empty" }
    ];
    returnString = infoData;
// End of lation_meth items

You're code should now look similar to the example in the image below:

Save all the files we edited (serverexport.lua & metadata.js), restart your server & enjoy!

Are you stuck?

No worries! If you need any help or experience any issues after following these instructions feel free to reach out to us via Discord or email at support@lationscripts.com.

Last updated