Temporary Inventories

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

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.

circle-exclamation

First we need to register a temporary inventory handler using RegisterTemporaryInventoryHandler. 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 LoadInventoryByIdentifier.

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)

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

circle-exclamation

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 AccessInventory.

Last updated