Add item to tray||doc135690

September 20, 2022

Format

 tray:settle_item(slot, item)
  • The class to which the function belongs:tray

Description

Add an item to the specified tray slot.


Precautions

  • Please do not add item to existing slots, otherwise unpredictable consequences will occur

Parameters

Variable name type Description
slot int Tray slot
item item item instance


Code Samples

On the server side of the player entity templatemount script, get the player's tray and add item to the tray

local item = Item.new("myplugin/testItem", 1)         --Create item instance
local filterTB = {                                
    Define.TRAY_TYPE.HAND_BAG                  
}
local entityTrays = this:tray()                        
local trayTb = entityTrays:query_trays(filterTB)
for tid, _tray in pairs(trayTb) do
    local slot = _tray.tray:find_free()             --Get the empty slot in the tray
    _tray.tray:settle_item(slot, item)              --Add item to tray
end