Entity enters map event||doc135527

September 20, 2022

Format

 ENTER_MAP
  • The class to which the function belongs:Entity

Description

This event is fired when an entity enters a map.


Context

The context content of the event

name type Description
obj1 Entity Entity instance into the map
map Map Incoming map instance


Code Samples

On the server side of the entity templatemount script, add the following when registering entities of this type into the mapCallback, set the blood volume of the entity entering the map to full blood

Trigger.addHandler(this:cfg(), "ENTER_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)

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

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 enter the map callback function
end)