equipment event||doc135522

September 20, 2022

Format

 WEAR_EQUIPMEN
  • The class to which the function belongs:Entity

Description

This event is triggered when the entity object is equipped with a item. The equipped item here needs to be equipped with the item type in the editor to trigger this event.


Context

The context content of the event

name type Description
obj1 Entity Entity instance
item Item Instances of equipped item


On the server side of the entity templatemount script, when registering this type of entity to wear equipmentCallback, if the item being worn is armor, set the entity's max health to 60

Code Samples

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