ox_inventory

if not GetResourceState('ox_inventory') == 'started' then return end

local stashName = 'drx_evidence'

local function getStashName(id)
  return stashName .. ':' .. id
end

Inventory = {
  ---@param id string
  ---@return boolean
  registerStash = function(id)
    local stash = getStashName(id)
    local success = exports.ox_inventory:RegisterStash(stash, stash, 50, 50000, nil)

    return success == true
  end,

  ---@param id string
  ---@return table
  getStashItems = function(id)
    local stash = getStashName(id)
    local exists = exports.ox_inventory:GetInventory(stash, false)
    
    if not exists then
      Inventory.registerStash(id)
    end
    
    return exports.ox_inventory:GetInventoryItems(stash, false)
  end,

  ---@param source number
  ---@param id number
  openStash = function(source, id)
    local stash = getStashName(id)
    local exists = exports.ox_inventory:GetInventory(stash, false)

    if not exists then
      Inventory.registerStash(id)
    end

    exports.ox_inventory:forceOpenInventory(source, 'stash', stash)
  end
}

Last updated

Was this helpful?