Blue Byte Documentation
  • Home
  • Scripts
    • Advanced Inventory
      • Installation
      • Migration
      • Temporary Inventories
      • API
        • Client Exports
          • GetAPI
          • GetItems
          • GetItem
          • IsInventoryOpen
          • DisableInventory
          • IsInventoryDisabled
          • RefreshClothing
          • GetPlayerInventory
          • SetDrawAnimation
          • ResetDrawAnimation
          • GetPlayerItemCount
          • AccessInventory
          • GetCurrentWeapon
        • Server Exports
          • GetAPI
          • GetItems
          • GetItem
          • GetPlayerInventory
          • ClearPlayerInventory
          • ClearPlayerClothing
          • AddPlayerItem
          • SetPlayerClothing
          • SetPlayerClothingFromCurrentComponents
          • RemovePlayerItem
          • CanPlayerCarryItem
          • GetPlayerItemCount
          • AddPlayerWeapon
          • RegisterUsableItem
          • SetItemMetadata
          • GetPlayerClothingByIdentifier
          • RemoveInventoryItemById
          • RemoveInventoryItemBySlot
          • GetInventoryItemById
          • GetPlayerItemById
          • CreateInventory
          • LoadInventoryByIdentifier
          • RegisterTemporaryInventoryHandler
          • ClearInventoryById
          • SearchPlayer
    • Simple Garage
    • Simple Tattoostudio
Powered by GitBook
On this page
  1. Scripts
  2. Advanced Inventory

Temporary Inventories

On this page we dive into what "Temporary Inventories" are and what they can be used for.

PreviousMigrationNextAPI

Last updated 15 days ago

Temporary Inventories are Inventories that are loaded during runtime when needed, and unloaded when no player is accessing the Inventory. For example this can be used for stashes. In this example we are going to make a police storage.

In order to use this, you need to have some experience with coding.


First we need to register a temporary inventory handler using . Temporary inventory handler are the code that is called when the police locker is accessed, in this code you can add checks & load the specific inventory that is needed.

local api = exports["bb_inventory"]:GetAPI()

api.RegisterTemporaryInventoryHandler("police_storage",
    function(identifier, temporaryData, source)
        -- Add any checks you'd like,
        -- such as checking if the player has the right to access this storage
    end)

After registering the temporary inventory handler, we can load the inventory by the identifier(If it exists) using .

local api = exports["bb_inventory"]:GetAPI()

api.RegisterTemporaryInventoryHandler("police_storage",
    function(identifier, temporaryData, source)
        -- Add any checks you'd like,
        -- such as checking if the player has the right to access this storage

        local inventory = api.LoadInventoryByIdentifier(identifier)
        if (inventory) then
            return inventory
        end
    end)

The third parameter of CreateInventory is 'container', make sure the container is registered in your configs/container.shared.lua. For example:

["police_storage"] = {
    sizeX = 6,
    sizeY = 6,
    maxWeight = 40000 -- Also can be null
}
local api = exports["bb_inventory"]:GetAPI()

api.RegisterTemporaryInventoryHandler("police_storage",
    function(identifier, temporaryData, source)
        -- Add any checks you'd like,
        -- such as checking if the player has the right to access this storage

        local inventory = api.LoadInventoryByIdentifier(identifier)
        if (inventory) then
            return inventory
        end

        -- If the inventory does not exist, we create a new one
        return api.CreateInventory(identifier, "STASH", "police_storage", "police_storage", "police_storage",
            true)
    end)

local api = exports["bb_inventory"]:GetAPI()

-- Everything in front of the colon is the 'identifierHandle',
-- which is the one that is needed at RegisterTemporaryInventoryHandler

-- The second parameter is the temporaryData, which can be nil if you don't need it
-- It can be used to pass any data you want to the inventory handler
-- The third and fourth parameters are the title and icon of the inventory,
-- which are temporary until the title & icon is fetched from the database
-- which can also be nil if you don't need them
api.AccessInventory("police_storage:5", nil, "police_storage", "police_storage")

Now, if the inventory does not exist, we create a new one using .

Now, all the server-side part is done. We are now going to access the inventory on the client-side. Thats quite easy, we only need to make one API call, thats .

RegisterTemporaryInventoryHandler
LoadInventoryByIdentifier
CreateInventory
AccessInventory