click entity event||doc135516

September 20, 2022

Format

 ENTITY_CLICK
  • The class to which the function belongs:Entity

Description

This event is fired when an entity is clicked.


Precautions

This event will only be triggered when the clickable option is checked in the unit's properties in the editor.


Context

The context content of the event

name type Description
obj1 Entity the instance of the entity that was clicked
obj2 Entity The instance of the entity that initiated the click


Code Samples

On the server side of the entity templatemount script, register when the entity of this class is clickedCallback, injures the clicked entity, andbroadcast tipsclick relationship

Trigger.RegisterHandler(this:cfg(), "ENTITY_CLICK", function(context)
    local target = context.obj1                                            --Get the clicked entity
    local from = context.obj2                                              --Get the entity that initiated the click
    target:takeDamage(10, from, false, '')                                 --The clicked entity is injured
    World.CurWorld.SystemNotice(1, from.name..' click '..target.name, 40)  --Broadcast
end)