Find an eligible item in the tray||doc135493

September 20, 2022


 Entity:searchItem(cfgKey, val, type_list) 
  • The class to which the function belongs:Entity


Finds the first item in the entity's inventory that matches the key-value pair.


Variable name type Description
cfgKey string item configuration key
val variant item configuration value
type_list Define.TRAY_TYPE Tray type, the default is to find from all trays

Value Returned

type Description
Item item instance

Code Samples

On the server side of the entity objectmount script, add the registered entity object when enteringCallback, create a new item and find it, print its configuration information

Trigger.addHandler(this:cfg(), "ENTITY_ENTER", function(context)
    local entity = context.obj1
    entity:addItem("myplugin/testItem", 1, nil, "enter")
    local item =  entity:searchItem("fullName","myplugin/testItem")
    for k,v in pairs(item:cfg() or {}) do