Examples

Frozen Inventory code examples

Ensure Ready

-- server side:
exports["fz-inventory"]:onReady(function()
  print("Inventory is ready to be used.")
end)

Get Inventory Data

-- server side:
local inv = exports["fz-inventory"]:getInventory(identifier)
  -- {
  --   identifier = "",
  --   weight = 0.0,
  --   maxWeight = 50.0,
  --   maxSlots = 40,
  --   items = {}
  -- }

Get Inventory Items

-- client side:
exports["fz-inventory"]:getInventoryItems(identifier,function(items)
  -- Do something with items here...
end)

-- server-side:
local inventory = exports["fz-inventory"]:getInventoryItems(identifier)

New Inventory

You can create and access a new inventory (e.g: housing) or a temporary (e.g: admin item dump) inventory through a few simple function calls, as shown below. If you have a pre-existing items table (general ESX inventory layout), you can convert the items to the format required by the inventory by calling the export "buildInventoryItems", E.G:

NOTE: This must be called AFTER the script has authorized.

New Vehicle Inventory

When a new vehicle is purchased, you should create an inventory for it by triggering the export, passing the vehicles plate, and optionally the vehicles class/category OR model hash.

Alternative net event:

Adding container item with content directly to player inventory:

Shops

You can create shops that allow both buying and selling for fixed values via the config. While the inventory logic is handled automatically, you will still need to implement a way to open these shops via the export:

To create a shop, check out the config.lua and read the example shop provided.

Crafting

You can create recipes sets which contain a list of recipes, directly craftable from the inventory via the config. Again, crafting logic is all handled internally but you will need to implement a method for opening the recipe set, e.g:

To create a recipe set, check out the config.lua and read the example recipe set provided.

Minigame

A small minigame is included. Press space to use. Example usage:

Forcing inventories to save

Inventories save to the database on a thread roughly every 5 minutes (only as required). To force inventories to save immediately, call the export:

Allow some time for sql operations before closing server after this function is called.

Forcing individual inventory to save

Deleting inventories

You can delete inventories that you've created from the server side by calling the export:

Register usable item

ESX.RegisterUsableItem is now passed a callback function to remove the item that was used. Optional param count of items to remove. The item being used is also passed.

Account money as inventory items

To have account money show up as an inventory item, you need to add the account name to the config.lua table Config.DisplayAccounts, and insert the account name as an item in the database. The default ESX 'money' and 'black_money' items have been provided by default in the database and in the config.

Last updated