# Item management

Derive from Actor

Before using item management API, create a item management object is required, as below:

local Item = class.Item.new()

The specific function name and description are as follows:

Serial number Function name Description
1 getItemName(...) Get the name of item
2 getItemId(...) Acquire itemid
3 getDropItemNum(...) Get the number of dorps

# getItemName

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the name of item
  • The specific use cases are as follows:
--Get the name of the item with id 1,the parameter 1 is the item id that needs to get the name
local result,name=Item:getItemName(1)
--Show in chat box
Chat:sendSystemMsg("The name of the item with id 1 is:"..name)

# getItemId

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Acquire itemid
  • The specific use cases are as follows:
--Whenever a player makes an animated expression,the chat box displays the id of one of the falling objects within 10 squares around the host
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Get the coordinates of the homeowner
	local result,x,y,z=Player:getPosition(0)
	--Get the number and list of drops within 10 blocks around the homeowner
	local result2,num,objids=World:getActorsByBox(3,x-10,y-10,z-10,x+10,y+10,z+10)
	if num>0 then--if there is a drop
		--Get the id of the first item in the drop list
		local result3,itemid=Item:getItemId(objids[1])
		--Show in chat box
		Chat:sendSystemMsg("A drop item was found in 10 nearby blocks! One of the item id is "..itemid)
	else--if there is no drop
		--Show in chat box
		Chat:sendSystemMsg("No items found in 10 nearby blocks!")
	end
end
--Register animation expression listener,execute the above function when the player makes animation expression
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# getDropItemNum

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the number of dorps
  • The specific use cases are as follows:
--Whenever a player makes animated expressions,the chat box displays the number of stacks of one of the falling objects within 10 blocks around the homeowner
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Get the coordinates of the homeowner
	local result,x,y,z=Player:getPosition(0)
	--Get the number and list of drops within 10 blocks around the homeowner
	local result2,num,objids=World:getActorsByBox(3,x-10,y-10,z-10,x+10,y+10,z+10)
	if num>0 then--if there is a drop
		--Get the stacking number of the first item in the drop list
		local result3,itemnum=Item:getDropItemNum(objids[1])
		--Show in chat box
		Chat:sendSystemMsg("10 items found nearby! One of the items has "..itemnum.." stacked together")
	else--if there is no drop
		--Show in chat box
		Chat:sendSystemMsg("No items found in 10 nearby blocks!")
	end
end
--Register animation expression listener,execute the above function when the player makes animation expression
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)
Last Update: 6/11/2020, 9:30:46 PM