Tray add item event||doc135539

September 20, 2022


  • The class to which the function belongs:Entity


Triggered when an item is added to the player's tray


Moving an item from one tray to another also triggers this event


The context content of the event

name type Description
obj1 Entity the object instance that fires the projectile
item Item item instance
slot int Tray slot where the item is located
tray tray knapsack instance

Code Samples

On the server side of the entity templatemount script, when registering this type of entity object tray to add itemCallback, to determine whether the item added to the tray is 'armour', if so, set the maximum life value of the object to 60

Trigger.RegisterHandler(this:cfg(), "SETTLE_ITEM", function(context)
    local entity = context.obj1
    local itemFullName = context.item:full_name()        --Get the config name of the item
    if itemFullName == "myplugin/armour" then
        entity:setProp('maxHp', 60) 
        local maxHP = entity:prop('maxHp')               --Sets the maximum health of the entity