Garry's Mod Wiki


GM:PlayerChangedTeam( Player ply, number oldTeam, number newTeam )


Called when a player has changed team using Player:SetTeam.

Avoid calling Player:SetTeam in this hook as it may cause an infinite loop!


1 Player ply
Player whose team has changed
2 number oldTeam
Index of the team the player was originally in. See team.GetName and the team library.
3 number newTeam
Index of the team the player has changed to


Print the old Team name and the new Team name of players

hook.Add("PlayerChangedTeam", "PrintOldAndNewTeam", function(ply, oldTeam, newTeam) PrintMessage(HUD_PRINTTALK, ply:Nick() .. " switched from " .. team.GetName(oldTeam) .. " to " .. team.GetName(newTeam)) end)
Output: Player1 switched from Team1 to Team2

Page Links

Special Pages



Render Time: 33ms

DB GetPage 3
Generate Html 13
SaveChanges (1) 8
Render Body 0
Render Sidebar 6