Entity leaving the team event||doc135526

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 the team to join
    entity:setProp('maxHp', 60) -- set 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 the entity to the team will trigger the above join team event