Tray removal item event||doc135540

September 20, 2022


  • The class to which the function belongs:Entity


Triggered when an item is removed from 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
isSwitchTray boolean Whether to switch tray

Code Samples

On the server side of the entity templatemount script, when registering this type of entity object tray to remove itemCallback, if the item is 'armour', and the item is not a function that is triggered when switching trays, set the object's maximum health to 20

Trigger.RegisterHandler(this:cfg(), "REMOVE_ITEM", function(context)
    local entity = context.obj1
    local isSwitchTray = context.isSwitchTray
    if itemFullName == "myplugin/armour" and not isSwitchTray then  --When the item is 'armour' and the item is not switching tray
        entity:setProp('maxHp', 20) 
        local maxHP = entity:prop('maxHp')                          --Sets the maximum health of the entity