[HELP] Open ox_shop without npc


Hello, I’m coding a police profession system from scratch. I’m trying to create a special ox_inventory-based store for police officers without using ox_inventory’s built-in NPC feature, but I haven’t been very successful. I’m using ox_inventory on a QBCore-based server. I tried opening it using the exports provided by ox_inventory but couldn’t make it work. I’m using ox_inventory version 2.41.0, and here’s the code I’ve written

function OpenPoliceMenu()
    lib.registerContext({
        id = 'antopd_police_menu',
        title = 'Police Inventory',
        options = {
            {
                title = 'Equipment Store',
                icon = 'fa-solid fa-gun',
                onSelect = function()
                    exports.ox_inventory:openInventory('shop', { type = 'PoliceArmoury', id = '2' })
                end
            }
        }
    })

    lib.showContext('antopd_police_menu')
end

RegisterCommand('testshop', function()
    exports.ox_inventory:openInventory('shop', { type = 'PoliceArmoury', id = 1 })
end, false)

This is the shop data I added to ox_inventory:

	PoliceArmoury = {
        name = 'Police Armoury',
        inventory = {
            { name = 'ammo-9', price = 5 },
            { name = 'ammo-rifle', price = 5 },
            { name = 'WEAPON_FLASHLIGHT', price = 200 },
            { name = 'WEAPON_NIGHTSTICK', price = 100 },
            { name = 'WEAPON_PISTOL', price = 500, metadata = { registered = true, serial = 'POL' }, license = 'weapon' },
            { name = 'WEAPON_CARBINERIFLE', price = 1000, metadata = { registered = true, serial = 'POL' }, license = 'weapon', grade = 3 },
            { name = 'WEAPON_STUNGUN', price = 500, metadata = { registered = true, serial = 'POL' } }
        },
        locations = {}, 
        targets = {}    
    },
3 Likes

+Up comment

3 Likes

need help

Your shop isn’t opening even though you’re calling openInventory correctly because ox_inventory only opens a shop if a few conditions are met.

First, the shop has to actually be registered. Just adding it into a file isn’t always enough if ox_inventory hasn’t loaded it. If the resource wasn’t restarted or if it wasn’t registered through a script, the shop won’t exist at runtime.

Second, your shop has no locations. Even if you don’t want an NPC or marker, ox_inventory still expects at least one location in the list because the id you pass refers to the position in that list. Right now, your locations table is empty, so passing id 1 or id 2 points to nothing.

Third, your item names must match items that actually exist in ox_inventory. Names like WEAPON_PISTOL usually don’t match. ox_inventory typically uses lowercase names like weapon_pistol or custom item keys listed in its items file.

Fourth, make sure type and id match exactly. The type should be the shop key, like PoliceArmoury. The id should be a number, not a string, and it has to match the index of an entry in the shop’s locations. Using id = ‘2’ won’t work if there’s no locations entry in position 2 (or any at all).

@PITTIK

2 Likes

Thank you so much for your help. But it’s been a really long time since I solved the issue <3 Still, I appreciate it

1 Like