Entities enter the team event||doc135525

September 20, 2022

Format

 JOIN_TEAM
  • The class to which the function belongs:Entity

Description

This event is fired when an entity joins a team.


Context

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')               
    print(maxHP)                                     
end)

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
end)