remove item event||doc135523

September 20, 2022

Format

 TAKEOFF_EQUIPMEN
  • The class to which the function belongs:Entity

Description

This event is triggered when the entity object unloads the equipped item. The unloaded item here needs to be unloaded after the item type is set to the equipment type in the editor, and then the event can be triggered.


Context

The context content of the event

name type Description
obj1 Entity Entity instance
item Item The removed item instance


Code Samples

On the server side of the entity templatemount script, register this type of entity when unloading the equipmentCallback, if the removed item is armor, set the entity's max health to 20

Trigger.RegisterHandler(this:cfg(), "TAKEOFF_EQUIPMEN", function(context)
    local entity = context.obj1                          --Get the entity wearing the equipment
    local itemFullName = context.item:full_name()        --Get the configuration name of the item
    if itemFullName == "myplugin/armour" then            
        entity:setProp('maxHp', 20)                      --Sets the maximum health of the entity
        local maxHP = entity:prop('maxHp')               
        print(maxHP)                                     
    end
end)