Skip to content
English

Inventory

Initiate Inventory API

lua
Feather = exports['feather-inventory'].initiate()
Feather = exports['feather-inventory'].initiate()

Create a custom Inventory

Register Foreign Key

Server Side Only

Registers a Inventory Foreign Key for your script to utilize custom inventories. (This must be run on server startup)

ParameterDescription
tableNameThis must be the exact name of your table where the inventory owner will be. (e.g. stables)
foreignKeyTypeThe data type used in your tables primary key. (e.g. BIGINT UNSIGNED, VARCHAR(255), INT)
primaryKeyNameThe name of your primary key. (e.g. id)

Example Usage:

lua
Feather.Inventory.RegisterForeignKey('stables', 'BIGINT UNSIGNED', 'id')
Feather.Inventory.RegisterForeignKey('stables', 'BIGINT UNSIGNED', 'id')

Register Inventory

Server Side Only

Registers a custom inventory for an entity.

ParameterDescription
tableNameThis must be the exact name of your table where the inventory owner will be. (e.g. stables)
idThe Owners ID from the database (e.g. the database ID of the horse)
maxWeightOverride the max weight for the inventory. (Pass nil to use config value)
restrictedItemsTable of item names from the DB that you'd like to be restricted (Pass nil to no restrict)
ignoreItemLimitstrue to ignore the max quantity of the item or false to adhear
displayNameA custom name for the inventory (shows on top of inventory)

Example Usage:

lua
-- Accept all defaults
Feather.Inventory.RegisterInventory('stables', 6)

-- Override defaults
Feather.Inventory.RegisterInventory('stables', 6, 2500, {'apple', 'haycube'}, true)

-- No Restrictions
Feather.Inventory.RegisterInventory('stables', 6, 2500, nil, true)

-- Adhear to item limits. And don't restrict items
Feather.Inventory.RegisterInventory('stables', 6, 2500, nil, false)
-- Accept all defaults
Feather.Inventory.RegisterInventory('stables', 6)

-- Override defaults
Feather.Inventory.RegisterInventory('stables', 6, 2500, {'apple', 'haycube'}, true)

-- No Restrictions
Feather.Inventory.RegisterInventory('stables', 6, 2500, nil, true)

-- Adhear to item limits. And don't restrict items
Feather.Inventory.RegisterInventory('stables', 6, 2500, nil, false)

Inventory Can Hold

Server Side Only

Verifies that the inventory you're attempting to put items in to can hold the specified items and quantity.

ParameterDescription
itemsTable of item names and quanity you're trying to add
inventoryIdUUID of the inventory you are trying to add to

Return Value:

This will return a table with the response from the API letting you know why it didn't work.

lua
-- Failed Example
local returnValue = {
  status = false,
  -- One of the following messages.
  reason = 'Item is restricted.' -- First check
  reason = 'Max quantity exceeded.' -- Second check
  reason = 'Max weight exceeded.' -- Third check
}

-- Successful Example
local returnValue = {
  status = true,
  reason = ''
}
-- Failed Example
local returnValue = {
  status = false,
  -- One of the following messages.
  reason = 'Item is restricted.' -- First check
  reason = 'Max quantity exceeded.' -- Second check
  reason = 'Max weight exceeded.' -- Third check
}

-- Successful Example
local returnValue = {
  status = true,
  reason = ''
}

Example Usage:

lua
local items = {
  {
    item = "fangs",
    quantity = 5
  },
  {
    item = "meat",
    quantity = 10
  }
}

Feather.Inventory.InventoryCanHold(items, 'c770bc77-3a77-11ee-b67f-18c04d04db03')
local items = {
  {
    item = "fangs",
    quantity = 5
  },
  {
    item = "meat",
    quantity = 10
  }
}

Feather.Inventory.InventoryCanHold(items, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

Add Item

Server Side Only

Add an item to a given inventory.

ParameterDescription
itemNameThe name of the item from the database.
quantityThe quantity of the item you'd like to add.
metadataAny metadata you'd like to add to the item. Can be nil
inventoryIdThe UUID of the inventory you are adding the item to. If adding to the active player, give this field src

Example Usage:

lua
-- Add 6 apples to my inventory
Feather.Inventory.AddItem('item_apple', 6, nil, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

local metadata = { quality = 'poor', durability = 50, maxDurability = 100 }
Feather.Inventory.AddItem('item_apple', 6, metadata, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

-- This adds to the active players inventory
Feather.Inventory.AddItem('item_apple', 6, nil, src)
-- Add 6 apples to my inventory
Feather.Inventory.AddItem('item_apple', 6, nil, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

local metadata = { quality = 'poor', durability = 50, maxDurability = 100 }
Feather.Inventory.AddItem('item_apple', 6, metadata, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

-- This adds to the active players inventory
Feather.Inventory.AddItem('item_apple', 6, nil, src)

Remove Item By Name

Server Side Only

Remove an item from a given inventory by name.

ParameterDescription
itemNameThe name of the item from the database.
quantityThe quantity of the item you'd like to remove.
inventoryIdThe UUID of the inventory you are removing the item to. If removing from the active player, give this field src or nil

Example Usage:

lua
Feather.Inventory.RemoveItemByName('item_apple', 6)
Feather.Inventory.RemoveItemByName('item_apple', 6)

Remove Item By ID

Server Side Only

Remove an item by its inventory ID. Only supports a single item as its targeting the primary key of the table. If you need to remove multiple items use RemoveItemByName.

ParameterDescription
idThe ID of the item from the players inventory

Example Usage:

lua
Feather.Inventory.RemoveItemById(6)
Feather.Inventory.RemoveItemById(6)

Set Metadata

Server Side Only

Sets the metadata for a given item.

ParameterDescription
idThe ID of the item from the players inventory.
metadataTable of key/value pairs to set

Example Usage:

lua
local metadata = { 
  display = 'Something to display under the item description',
  quality = 'poor',
  durability = 50,
  maxDurability = 100
}
Feather.Inventory.SetMetadata(6, metadata)
local metadata = { 
  display = 'Something to display under the item description',
  quality = 'poor',
  durability = 50,
  maxDurability = 100
}
Feather.Inventory.SetMetadata(6, metadata)

Get Item

Server Side Only

Gets an item from the Inventory Items Table

ParameterDescription
idThe ID of the item from the players inventory.

Example Usage:

lua
Feather.Inventory.GetItem(6)
Feather.Inventory.GetItem(6)

GetItemCount

Server Side Only

Retrieves the amount of a specific item a player has. Returns the quantity.

ParameterDescription
itemNameThe name of the item you are looking for.
inventoryIdID of the inventory, you can also feed in the src of a player instead of inventoryID

Example Usage:

lua
Feather.Inventory.GetItemCount('item_train_ticket', 'c770bc77-3a77-11ee-b67f-18c04d04db03')
Feather.Inventory.GetItemCount('item_train_ticket', 'c770bc77-3a77-11ee-b67f-18c04d04db03')

Item Exists

Server Side Only

Checks if an item exists in the DB.

ParameterDescription
itemNameThe name of the item you are looking for.

Example Usage:

lua
Feather.Inventory.ItemExists('item_train_ticket')
Feather.Inventory.ItemExists('item_train_ticket')

Inventory Has Item

Server Side Only

Checks to see if a player has a specific item or items.

ParameterDescription
itemsA table of items you wish to check for. See below for an example of a properly formatted item table.
inventoryThe inventory ID you're checking to see if it has items against. You can also feed in the src of a player instead of inventoryID

Example Usage:

lua
local itemsToCheckFor = {
  {
    name = 'apple',
    quantity = 5
  },
  {
    name = 'jars',
    quantity = 2
  }
}

Feather.Inventory.PlayerHasItems(itemsToCheckFor, 'c770bc77-3a77-11ee-b67f-18c04d04db03')
local itemsToCheckFor = {
  {
    name = 'apple',
    quantity = 5
  },
  {
    name = 'jars',
    quantity = 2
  }
}

Feather.Inventory.PlayerHasItems(itemsToCheckFor, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

Register Usable Item

Server Side Only

Registers a usable item with Feather Inventory

ParameterDescription
itemNameThe name of the item you are registering a call back for.
callbackA closure with the logic you will be using upon use of the item

Example Usage:

lua
Feather.Inventory.RegisterUsableItem('item_apple', function (item)
  print('You ate an apple!')
end)
Feather.Inventory.RegisterUsableItem('item_apple', function (item)
  print('You ate an apple!')
end)

Can Hold/Store Item

Server Side Only

Check to see if a player can store an item

ParameterDescription
itemsTable of items and their quantity. e.g. { {item="apple", quantity=5}, {item="matches", quantity=10} }
inventoryIdPlayer Source or Inventory UUID
lua
local canHold = Feather.Inventory.InventoryCanHold({ {item="apple", quantity=5}, {item="matches", quantity=10} }, src)

-- Success response { status = true, message = '' }

-- Failed response { status = false, message = 'Max Quantity Exceeded.' }
local canHold = Feather.Inventory.InventoryCanHold({ {item="apple", quantity=5}, {item="matches", quantity=10} }, src)

-- Success response { status = true, message = '' }

-- Failed response { status = false, message = 'Max Quantity Exceeded.' }

Open Inventory ServerSide

Server Side Only

Open an inventory (This is built into inventory with keypress, but if you would like to do so programatically)

lua
-- Open player inventory
Feather.Inventory.OpenInventory(src, nil, 'player')

-- Open secondary/custom inventory
Feather.Inventory.OpenInventory(src, 'c770bc77-3a77-11ee-b67f-18c04d04db03')
-- Open player inventory
Feather.Inventory.OpenInventory(src, nil, 'player')

-- Open secondary/custom inventory
Feather.Inventory.OpenInventory(src, 'c770bc77-3a77-11ee-b67f-18c04d04db03')

Close Inventory ServerSide

Server Side Only

Close an inventory (This is built into inventory with keypress, but if you would like to do so programatically)

lua
Feather.Inventory.CloseInventory(src)
Feather.Inventory.CloseInventory(src)

Open Inventory ClientSide

Client Side Only

Open an inventory (This is built into inventory with keypress, but if you would like to do so programatically)

lua
Feather.Inventory.Open(nil, "player")

-- or 

Feather.Inventory.Open('5ab95e93-c590-11ee-a5cf-40b07640984b')
Feather.Inventory.Open(nil, "player")

-- or 

Feather.Inventory.Open('5ab95e93-c590-11ee-a5cf-40b07640984b')

Close Inventory ClientSide

Client Side Only

Close an inventory (This is built into inventory with keypress, but if you would like to do so programatically)

lua
Feather.Inventory.Close()
Feather.Inventory.Close()

Get Player Inventory

Server Side Only

Get contents of a a players inventory

ParameterDescription
keythe key used when registering the inventory
inventoryIdPlayer Source or Inventory UUID

Returns: id, uuid, max_weight, ignore_item_limit

lua
local _, groundInventoryID = InventoryAPI.GetInventory(src)
local _, groundInventoryID = InventoryAPI.GetInventory(src)

Get Custom Inventory

Server Side Only

Get contents of a secondary/custom inventory

ParameterDescription
keythe key used when registering the inventory
inventoryIdInventory UUID

Returns: id, uuid, max_weight, ignore_item_limit

lua
local _, groundInventoryID = InventoryAPI.GetCustomInventory('stables', 'c770bc77-3a77-11ee-b67f-18c04d04db03')
local _, groundInventoryID = InventoryAPI.GetCustomInventory('stables', 'c770bc77-3a77-11ee-b67f-18c04d04db03')

Get Items of Inventory

Gets the items from a specified inventory

ParameterDescription
inventoryIdPlayer Source or Inventory UUID
lua
InventoryAPI.GetInventoryItems('stables', 'c770bc77-3a77-11ee-b67f-18c04d04db03')
InventoryAPI.GetInventoryItems('stables', 'c770bc77-3a77-11ee-b67f-18c04d04db03')