Never faced such problem, what version of amx are you using? Anyway, here are some corrections to your code.
Code:
public SwapTeams()
{
new players[32];
new playercount;
get_players(players, playercount, "h"); // 'h' to not include hltv
new i, id // do not create vars inside a loop
for (i=0; i<playercount; i++)
{
id = players[i]
if (cs_get_user_team(id) != CS_TEAM_SPECTATOR && cs_get_user_team(id) != CS_TEAM_UNASSIGNED) // You also check if he hasn't chosen any team yet, ie "unassigned".
{
cs_set_user_team(id, (cs_get_user_team(id) == CS_TEAM_T) ? CS_TEAM_CT : CS_TEAM_T)
}
}
}
__________________