We’re excited to release another free resource for the FiveM community, we released player owned stores as it was something I always wanted on my own servers many years ago, it’s a basic script that allows businesses to list items for sale and when sold deposits moneys into there society / business accounts, we’ve included webhooks as well as a way to edit listed items after they’ve been listed, increase / decreasing stock & price editing.
Features
Create unlimited stores, for each business / job
Set management perms based on job and grade
Add Items based on the items in a players inventory
Edit existing items, increase or decrease stock and prices
Added webhooks to stock & who is using / increase stock
So this script works perfectly for what i needed it for. Appreciate it. Only issue i see, is if you have an open slot in your inventory, it wont show past that open spot.
sounds good. loving it so far. last one i tried screwed with the actual job and their inventory. this one works perfectly. other than this little thing lol. amazing work.
attempt to index a nil value (local ‘input’) while canceling dialog box(fix)
RegisterNetEvent('vhs-stores:open')
AddEventHandler('vhs-stores:open', function(name, config, data, hasItems)
if hasItems then
local menuOptions = {}
for item, data in pairs(data.items) do
table.insert(menuOptions, {
title = ItemLabel(item) .. ' - $' .. data.price,
description = 'Stock Available - (' .. data.amount .. 'x)',
icon = InventoryImagePath .. item .. ".png",
args = { price = data.price, item = item, amount = data.amount },
onSelect = function()
local input = lib.inputDialog('Purchase ' .. ItemLabel(item), {
{type = 'number', description = 'Amount to purchase', icon = 'hashtag', min = 1, max = data.amount, required = true, default = 1} -- Set default value to 1
})
-- Check if input is nil (canceled) before proceeding
if input == nil then
--print('Input canceled or closed by user.')
return -- Stop further execution
end
-- Proceed only if input is valid and not empty
if input[1] then
local buy = lib.callback.await('vhs-store:buyItem', false, name, item, data.price, input[1])
else
print('No valid amount entered.')
end
end,
})
end
lib.registerContext({ id = 'store_'.. name, title = config.menu.title, options = menuOptions })
lib.showContext('store_'.. name)
else
lib.registerContext({ id = 'store_'.. name, title = config.menu.title, options = {{ title = 'No Items Available' }}})
lib.showContext('store_'.. name)
end
end)
Filter inventory items based on the store’s allowed items
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
Yeah we looked at doing that, it seems possible, only issues I had in trying to do it was with qb-inventory, as it has the ability to createshops, but no ability to edit them or update them, I mean we could do it directly through SQL assuming they store there shops in SQL, but we’d need the ability to update stores live based on stock options, honestly might just create a UI for the playerowned stores in the next couple days, I’m really not a fan of all these ox_lib context menus, I mean they’re not bad but it could be much nicer.