Skip to content

Filter inventory items based on the store's allowed items #1

@MG-Alpha

Description

@MG-Alpha
function addStock(name)
    local storeConfig = Stores[name]
    if not storeConfig or not storeConfig.allowedItems.useAllowed then
        return
    end
    local inv = lib.callback.await('vhs-stores:getInv', false)
    if inv then
        local menuOptions = {}
        -- Filter inventory items based on the store's allowed items
        for _, item in ipairs(inv) do
            if table.contains(storeConfig.allowedItems.list, string.lower(item.name)) then
                table.insert(menuOptions, { 
                    title = item.label .. ' - (' .. item.count .. 'x)', 
                    icon = InventoryImagePath .. string.lower(item.name) .. ".png",  
                    args = { store = name, item = string.lower(item.name), label = item.name, amount = item.count },
                    onSelect = function()
                        local input = lib.inputDialog('Add ' .. item.label .. ' as Product', { 
                            {type = 'number', label = 'Price', description = 'Set the price of stock', required = true, min = 1}, 
                            {type = 'slider', label = 'Stock Amount', description = 'Set the amount of stock', icon = 'hashtag', min = 1, max = item.count, required = true,} 
                        })
                        local setup = lib.callback.await('vhs-store:setItem', false, input[1], input[2], string.lower(item.name), name)
                    end
                })
            end
        end
        lib.registerContext({ id = 'sstore_' .. name, title = '➕ Select Item to Setup', options = menuOptions })
        lib.showContext('sstore_' .. name)
    end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions