Tool case used||doc135521

September 20, 2022

Format

 ENTITY_USE_ITEM
  • The class to which the function belongs:Entity

Description

This event is triggered when an entity object uses a item. The item type used here needs to be set as the consumption type in the editor, and then the event can be triggered by using it.

Context

The context content of the event

name type Description
obj1 Entity Entity instance
item Item Instances of item used
itemName string Tool placement name


Code Samples

On the server side of the entity templatemount script, when registering this class of entities to use itemCallback, if the item used are medicines, increase the physical blood volume

Trigger.RegisterHandler(this:cfg(), "ENTITY_USE_ITEM", function(context)
    local entity = context.obj1                       --Get the entity that uses the item
    local itemName = context.itemName                 --Get the config name of the item
    if itemName == "myplugin/Cure" then               
       entity:addHp(5)                                --Add Hp to an entity
    end
end)