Entity leaves map event||doc135528

September 20, 2022

Format

 LEAVE_MAP
  • The class to which the function belongs:Entity

Description

This event is fired when the entity leaves the map.


Context

The context content of the event

name type Description
obj1 Entity Entity instance that leaves the map
map Map away map instance


Code Samples

On the server side of the entity templatemount script, register when the entity of this class leaves the mapCallback, set the health of the entity leaving the map to full health

Trigger.RegisterHandler(this:cfg(), "LEAVE_MAP", function(context)
    local entity = context.obj1            
    local map = context.map 
    local maxHp = entity:prop('maxHp')     --Get the maximum health of the entity
    entity:setHp(maxHp)                    --Sets the entity's health
end)
end)

Add registered entities when entering the gameCallback, jump to the map, and trigger the leave map callback function

Trigger.addHandler(this:cfg(), "ENTITY_ENTER", function(context)
    local entity = context.obj1                                         
    local dynamicMap = World.CurWorld:createDynamicMap("map001", true)  --Create dynamic maps
    entity:setMapPos(dynamicMap, Vector3.new(30, 55, 30))               --Set the entity map and coordinates, and trigger the entity to leave the map callback function
end)