# Backpack Management

Before using the backpack API, please create backpack management objects. Methods are as follow:

local Backpack = class.Backpack.new()

The specific function name and description are as follows:

Serial number Function name Description
1 getBackpackBarIDRange(...) Get the range of backpack bar's ID(Start ID~End ID)
2 getBackpackBarSize(...) Get the size of backpack bar
3 setGridItem(...) Set the backpack
4 removeGridItem(...) Remove some items in backpack bar. Removed by item slots. All removed by default
5 removeGridItemByItemID(...) Remove some items in backpack bar. Removed by item ID. All removed by default
6 clearPack(...) Clear designate backpack bar
7 clearAllPack(...) Clear all the backpack(including backpack bar, shortcut bar, equip bar)
8 moveGridItem(...) Remove items in backpack. All transferred by default
9 swapGridItem(...) Exchange item backpack
10 enoughSpaceForItem(...) If there is enough space in backpack(including backpack bar, shortcut bar) to store items
11 calcSpaceNumForItem(...) Calculate the total number of remaining items that the backpack(including backpack bar, shortcut bar) can store
12 getBackpackBarValidList(...) Get valid list of items' ID which are already in backpack bar. Item ID
13 getBackpackBarItemList(...) Get items already in backpack bar. Item ID
14 hasItemByBackpackBar(...) Detect if there is any designated item in backpack
15 getItemNumByBackpackBar(...) Get the total number of items in backpack. Return to backpacks with items
16 getGridItemID(...) Obtain ID of items in backpack slots(Return to itemid, num)
17 getGridItemName(...) Get item name in backpack
18 getGridStack(...) Obtain the number of stacks in backpack slot(Back to curstack, maxstack)
19 getGridDurability(...) Obtain the durability of backpack slot(Back to durcur, durmax)
20 getGridEnchantList(...) Get enchantment of items in backpack. Return to enchantment ID.
21 getGridToolType(...) Get the item tool type in backpack (<0 means non-tool)
22 addItem(...) Add the item to backpack
23 discardItem(...) Discard an item in backpack slot
24 getGridNum(...) Get the number of items in one slot of backpack

# getBackpackBarIDRange

  • Parameters and types:
    • bartype:number backpack type, shortcut bar, saving bar,equipment bar
  • Return value and types:
  • The main role of this method: Get the range of backpack bar's ID(Start ID~End ID)
  • The specific use cases are as follows:
--Get the item id of the shortcut bar,the parameter is the backpack bar type:1 shortcut bar 2 storage bar 3 equipment bar
local result,begid,endid=Backpack:getBackpackBarIDRange(1)
--Show in chat box
Chat:sendSystemMsg("The item id of the shortcut bar is:"..begid.."to"..endid)
--Get the item id of the backpack
result,begid,endid=Backpack:getBackpackBarIDRange(2)
--Show in chat box
Chat:sendSystemMsg("The item id of the storage column is:"..begid.."to"..endid)
--The item id of the equipment bar
result,begid,endid=Backpack:getBackpackBarIDRange(3)
--Show in chat box
Chat:sendSystemMsg("The item id of the equipment bar is:"..begid.."to"..endid)

# getBackpackBarSize

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the size of backpack bar
  • The specific use cases are as follows:
--Get the total number of backpack bars,the parameter is the backpack type:1 shortcut bar 2 storage bar 3 equipment bar
local result,size=Backpack:getBackpackBarSize(1)
--Show in chat box
Chat:sendSystemMsg("shortcut bar has a total of"..size.."Grid")

# setGridItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set the backpack
  • The specific use cases are as follows:
--Add items to the designated backpack bar of the designated player
--The first parameter 1000 is the player's mini number
--The second parameter 0 is the id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
--The third parameter is the item id to be added,12005 is the diamond sword
--The fourth parameter is the number of items to be added
--The last parameter is the durability of the item to be added,nil is the default full
Backpack:setGridItem(1000,0,12005,10,nil)
--Show in chat box
Chat:sendSystemMsg("Add 10 diamond swords to the first cell of the player's storage bar with a mini number of 1000,the durability is full")

# removeGridItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove some items in backpack bar. Removed by item slots. All removed by default
  • The specific use cases are as follows:
--Remove items from the designated backpack bar of the designated player
--The first parameter is the player mini number
--The second parameter 0 is the id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
--The third parameter is the number of removals
Backpack:removeGridItem(1000,0,10)
--Show in chat box
Chat:sendSystemMsg("Removed the first 10 items in the backpack bar of player 1000")

# removeGridItemByItemID

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove some items in backpack bar. Removed by item ID. All removed by default
  • The specific use cases are as follows:
--Remove specified items from the specified player's backpack
--The first parameter is the player mini number
--The second parameter is the item id to be removed,101 is the soil block
--The third parameter is the number of items to be removed
local result,num=Backpack:removeGridItemByItemID(1000,101,50)
--Show in chat box
Chat:sendSystemMsg("Try to remove 50 soil blocks in player 1000 backpack,actually removed "..num)

# clearPack

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Clear designate backpack bar
  • The specific use cases are as follows:
--Empty the designated player's backpack items
--The first parameter is the player mini number
--The second parameter is the type of backpack:1 shortcut bar 2 storage bar 3 equipment bar
Backpack:clearPack(1000,1)
--Show in chat box
Chat:sendSystemMsg("Empty the player's 1000 quick bar items")

# clearAllPack

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Clear all the backpack(including backpack bar, shortcut bar, equip bar)
  • The specific use cases are as follows:
--Empty all the items of the specified player,including the shortcut bar,storage bar and equipment bar,the parameter is the player mini number
Backpack:clearAllPack(1000)
--Show in chat box
Chat:sendSystemMsg("Empty all items of player 1000,including shortcut bar,storage bar and equipment bar")

# moveGridItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove items in backpack. All transferred by default
  • The specific use cases are as follows:
--Move player backpack items to the designated inventory
--The first parameter is the player mini number
--The second parameter 0 is the id of the backpack bar to be moved,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
--The third parameter 1000 is the id of the backpack bar moved to,0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
--The fourth parameter is the number of moves
local result=Backpack:moveGridItem(1000,0,1000,10)
if result==0 then--If the move is successful
	--Show in chat box
	Chat:sendSystemMsg("Move the first item in the storage column of player 1000 by 10 to the first cell in the shortcut bar")
else--If the move fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently in the archive or cannot be moved")
end

# swapGridItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Exchange item backpack
  • The specific use cases are as follows:
--Swap items from the player's two inventory
--The first parameter is the player mini number
--The last two parameters are the id of the backpack bar to be exchanged:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result=Backpack:moveGridItem(1000,0,1000)
if result==0 then--If the exchange is successful
	--Show in chat box
	Chat:sendSystemMsg("Swap the first column of the storage column and the first column of the shortcut column of player 1000")
else--If the exchange fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived,or cannot be exchanged")
end

# enoughSpaceForItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: If there is enough space in backpack(including backpack bar, shortcut bar) to store items
  • The specific use cases are as follows:
--Determine whether the player's backpack (including the shortcut bar and storage bar) can continue to accommodate the specified number of items
--The first parameter is the player mini number
--The second parameter is the item id to be judged,101 is the soil block
--The third parameter is the number of items
local result=Backpack:enoughSpaceForItem(1000,101,999)
if result==0 then--if you can
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 player can continue to hold 999 clods")
else--If it is not possible or the judgment fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000's backpack cannot continue to hold 999 soil blocks,or Player 1000 is not currently in the archive")
end

# calcSpaceNumForItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Calculate the total number of remaining items that the backpack(including backpack bar, shortcut bar) can store
  • The specific use cases are as follows:
--Get how many specified items can be added to the backpack of the specified player (including shortcut bar and storage bar)
--The first parameter is the player mini number
--The second parameter is the item to get the remaining capacity,101 is the soil block
local result,num=Backpack:calcSpaceNumForItem(1000,101)
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("player 1000 backpack can also add"..num.."earth")
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getBackpackBarValidList

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get valid list of items' ID which are already in backpack bar. Item ID
  • The specific use cases are as follows:
--Get the grid id of the items already in the backpack of the specified player
--The first parameter is the player mini number
--The second parameter is the type of backpack bar:1 shortcut bar 2 storage bar 3 equipment bar
local result,num,array=Backpack:getBackpackBarValidList(1000,2)
if result==0 then--If the acquisition is successful
	--Display the number of existing items in the chat box
	Chat:sendSystemMsg("Total storage for player 1000"..num.."The item has been placed")
	for i,a in ipairs(array) do
		--Display grid id list in chat box
		Chat:sendSystemMsg("No."..i.." Item id with items:"..a)
	end
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getBackpackBarItemList

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get items already in backpack bar. Item ID
  • The specific use cases are as follows:
--Get the item list of the specified player's backpack
--The first parameter is the player mini number
--The second parameter is the type of backpack bar:1 shortcut bar 2 storage bar 3 equipment bar
local result,num,arr=Backpack:getBackpackBarItemList(1000,1)
if result==0 then--If the acquisition is successful
	--Show the number of categories in the chat box
	Chat:sendSystemMsg("A total of 1000 player shortcuts"..num.."items")
	for i,a in ipairs(arr) do
		--Display the list of item ids in the chat box
		Chat:sendSystemMsg("No."..i.."Item ID:"..a)
	end
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# hasItemByBackpackBar

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Detect if there is any designated item in backpack
  • The specific use cases are as follows:
--Determine whether the player's backpack contains an item
--The first parameter is the player mini number
--The second parameter is the type of backpack bar:1 shortcut bar 2 storage bar 3 equipment bar
--The third parameter is the item id to be judged,and 1 is the foundation stone
local result=Backpack:hasItemByBackpackBar(1000,1,1)
if result==0 then--if there is
	--Show in chat box
	Chat:sendSystemMsg("There is a cornerstone in the shortcut bar of player 1000")
else--if there is none or the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("There is no geocentric cornerstone in the shortcut bar of player 1000 or player 1000 is not in the current archive")
end

# getItemNumByBackpackBar

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the total number of items in backpack. Return to backpacks with items
  • The specific use cases are as follows:
--Get how many designated items the designated player's backpack has
--The first parameter is the player mini number
--The second parameter is the type of backpack bar:1 shortcut bar 2 storage bar 3 equipment bar
--The third parameter is the item id to be obtained,101 is the soil block
local result,num,arr=Backpack:getItemNumByBackpackBar(1000,2,101)
if result==0 then--If the acquisition is successful
	--Display the number of items in the chat box
	Chat:sendSystemMsg("Player 1000 has "..num.."cube in the storage column")
	for i,a in ipairs(arr) do
		--Display the list of items in the chat box
		Chat:sendSystemMsg("The first item with clods"..i.."The item id is:"..a)
	end
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getGridItemID

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain ID of items in backpack slots(Return to itemid, num)
  • The specific use cases are as follows:
--Get the item id and number of the specified item grid of the specified player
--The first parameter is the player mini number
--The second parameter 0 is the item id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result,itemid,num=Backpack:getGridItemID(1000,0)
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("The first item id of the player 1000 backpack storage bar is:"..itemid..",the number is:"..num)
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getGridItemName

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get item name in backpack
  • The specific use cases are as follows:
--Get the item name of the specified item grid of the specified player
--The first parameter is the player mini number
--The second parameter 0 is the item id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result,name=Backpack:getGridItemName(1000,0)
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("The name of the first item in the player 1000's backpack storage bar is:"..name)
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Failed to obtain,it may be that player 1000 is not in the current archive")
end

# getGridStack

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the number of stacks in backpack slot(Back to curstack, maxstack)
  • The specific use cases are as follows:
--Get the number and maximum number of item stacks for the designated backpack item grid of the specified player
--The first parameter is the player mini number
--The second parameter 0 is the id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result,num,maxstack=Backpack:getGridStack(1000,0)
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("The first item in the backpack storage column of player 1000 is currently stacked"..num..",this item can be stacked up to "..maxstack)
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getGridDurability

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the durability of backpack slot(Back to durcur, durmax)
  • The specific use cases are as follows:
--Get the current endurance value and maximum endurance value of items in the specified backpack item grid of the specified player
--The first parameter is the player mini number
--The second parameter 0 is the id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result,durcur,durmax=Backpack:getGridDurability(1000,0)
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("The durability value of the first item of the player 1000’s backpack storage column is "..durcur..",the maximum durability value of the item is "..durmax)
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getGridEnchantList

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get enchantment of items in backpack. Return to enchantment ID.
  • The specific use cases are as follows:
--Get the enchantment number and id of a certain item in the specified player's backpack
--The first parameter is the player mini number
--The second parameter is the id of the backpack bar,and 1000 is the first cell of the shortcut bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result,num,arr=Backpack:getGridEnchantList(1000,1000)
if result==0 then--If the acquisition is successful
	--Display the number of enchants in the chat box
	Chat:sendSystemMsg("The number of items enchanted in the first column of player 1000's shortcut bar is "..num)
	for i,a in ipairs(arr) do
		--Display enchant list in chat box
		Chat:sendSystemMsg("No."..i.."The enchantment id is:"..a)
	end
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# getGridToolType

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the item tool type in backpack (<0 means non-tool)
  • The specific use cases are as follows:
--Get the item type of the item specified by the specified player
--The first parameter is the player mini number
--The second parameter is the id of the backpack bar,and 1000 is the first cell of the shortcut bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
--The return value may be:-1 non-props 1 axe 2 pickaxe 3 shovel 4 hoe 6 sword 7 bow 14 throwing etc.
local result,type=Backpack:getGridToolType(1000,1000)
--Show in chat box
Chat:sendSystemMsg("The first item type in the player 1000 shortcut bar is:(-1 non-props 1 axe 2 pickaxe 3 shovel 4 hoe 6 sword 7 bow 14 throw))"..type)

# addItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Add the item to backpack
  • The specific use cases are as follows:
--Add items to the designated player's backpack
--The first parameter is the player mini number
--The second parameter is the item id to be added,101 is the soil block
--The third parameter is the number of items to be added
local result,successNum=Backpack:addItem(1000,101,999)
if result==0 then--If the addition is successful
	--Show in chat box
	Chat:sendSystemMsg("Try to add 999 clods to player 1000's backpack,actually added ".. successNum)
else--If the addition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end

# discardItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Discard an item in backpack slot
  • The specific use cases are as follows:
--Remove items from the designated backpack bar of the designated player
--The first parameter is the player mini number
--The second parameter 0 is the id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
--The third parameter is the number of removals
Backpack:discardItem(1000,0,10)
--Show in chat box
Chat:sendSystemMsg("Removed the first 10 items in the backpack bar of player 1000")

# getGridNum

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the number of items in one slot of backpack
  • The specific use cases are as follows:
--Get the number of items in the specified item grid of the specified player
--The first parameter is the player mini number
--The second parameter 0 is the item id of the backpack bar,and 0 is the first cell of the storage bar:0-29 storage bar 1000-1007 shortcut bar 8000-8004 equipment bar
local result,num=Backpack:getGridNum(1000,0)
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("The number of items in the first cell of the player 1000's backpack storage bar is:"..num)
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not currently archived")
end
Last Update: 6/11/2020, 9:30:46 PM