Entities enter the team event||doc135525

September 20, 2022


  • The class to which the function belongs:Entity


This event is fired when an entity joins a team.


The context content of the event

name type Description
obj1 Entity Instances of entities entering the team
teamId int Entering team ID

Code Samples

On the server side of the entity templatemount script, when an entity of this type is registered to join the teamCallback, set the entity's maximum health to 60

Trigger.RegisterHandler(this:cfg(), "JOIN_TEAM", function(context)
    local entity = context.obj1                      
    local joinTeam = Game.GetTeam(context.teamId)    --Get a team to join
    entity:setProp('maxHp', 60)                      --Sets the maximum health of the entity
    local maxHP = entity:prop('maxHp')               

Add registered entities when entering the gameCallback, create a team, add entities to the team, trigger
Enter the team callback function

Trigger.addHandler(this:cfg(), "ENTITY_ENTER", function(context)
    local entity = context.obj1                       
    local team = Game.CreateTeam()                    --Create a team
    Game.TryJoinTeamByPlayer(entity, team.id)         --Adding this entity to a team will trigger the above join team event