So I needed this for a competition we're having where we are to rank players individually, and wanted a way to even out and randomize the teams so no players have advantages of being on a better/winning team.
But I quickly discovered during testing that allthough it does try to randomize the teams, it looks like be cause of the way the randomization is implemented, sometimes it needs to switch teams twice for a player which seems to result in that the change won't happen until the next round (atleast on cs 1.5 won which we wanted to play).
So I refactored the code a little bit and it seems to work ok now.
Code:
#include <amxmodx>
#include <cstrike>
public plugin_init()
{
register_plugin("random teams", "1", "atambo")
register_cvar("sv_randomteams", "1")
register_logevent("event_round_end", 2, "0=World triggered", "1=Round_End")
}
public event_round_end()
{
if(get_cvar_num("sv_randomteams") != 1) return PLUGIN_CONTINUE
new num, players[32]
get_players(players,num)
for(new i=0;i<=num;i++)
{
if(!is_user_connected(players[i])) continue
if(cs_get_user_team(players[i])==CS_TEAM_SPECTATOR) continue
new rannum = random_num(1,2)
if(rannum==1)
{
cs_set_user_team(players[i],CS_TEAM_T)
if(i+2<=num)
{
i = i+1
cs_set_user_team(players[i],CS_TEAM_CT)
}
}
else
{
cs_set_user_team(players[i],CS_TEAM_CT)
if(i+2<=num)
{
i = i+1
cs_set_user_team(players[i],CS_TEAM_T)
}
}
}
return PLUGIN_CONTINUE
}