destroy entity event||doc135515

September 20, 2022


  • The class to which the function belongs:Entity


This event is fired when an entity is destroyed.


The context content of the event

name type Description
obj1 Entity Destroyed entity instance

Code Samples

On the server side of the entity templatemount script, add the register when the entity of this class is destroyedCallbackbroadcast tipsDestroyed entity object name

Trigger.addHandler(this:cfg(), "ENTITY_LEAVE", function(context)        --Register entity destruction callback function
    local entity = context.obj1
    World.CurWorld.SystemNotice(1,, 40)                     --Broadcast object name

on the server sideglobal script, add the register when the game startsCallback, the entity is spawned, and destroyed after one second

Trigger.addHandler(World.cfg, "GAME_START", function()
    local world = World.CurWorld                     --Get current world
    local defaultMap = world.defaultMap              --Get the default map of the current world
    local createParams = {
    cfgName = "myplugin/entity",                     --The config name of the entity
    pos = { x = 0, y = 1, z = 0 } ,                  --Entity spawn location
    map = defaultMap                                 --Entity generated map
    local entity = EntityServer.Create(createParams) --Generate entity
        entity:destroy()                             --Destroy the entity and trigger the destroy entity callback function