Garry's Mod Wiki

Revision Difference

GM:PlayerChangedTeam#527322

<function name="PlayerChangedTeam" parent="GM" type="hook"> <ishook>yes</ishook> <added>2020.03.17</added> <description> Called when a player has changed team using <page>Player:SetTeam</page>. <warning>Avoid calling <page>Player:SetTeam</page> in this hook as it may cause an infinite loop!</warning> </description> <realm>Server</realm> <predicted>No</predicted> <args> <arg name="ply" type="Player">Player whose team has changed</arg> <arg name="oldTeam" type="number">Index of the team the player was originally in. See <page>team.GetName</page> and the <page>team</page> library.</arg> <arg name="newTeam" type="number">Index of the team the player has changed to</arg> </args> </function> ⤶ <example>⤶ <description>Print the old Team name and the new Team name of players</description>⤶ <code>⤶ hook.Add("PlayerChangedTeam", "PrintOldAndNewTeam", function(ply, oldTeam, newTeam)⤶ PrintMessage(HUD_PRINTTALK, ply:Nick() .. " changed from " .. team.GetName(oldTeam) .. " to " .. team.GetName(newTeam))⤶ end)⤶ </code>⤶ ⤶ <upload src="8e3f9/8d8138b08ccd3ed.png" size="37088" name="image.png" />⤶ <output><image src="8e3f9/8d8138b08ccd3ed.png"/></output>⤶ </example>⤶