Here's some code I have from Amx Match Deluxe Plugin. The function randomizes teams. But it doesn't take spectators into account. How do I make it work so that both people in teams and spectators are randomized.. ?
Would it work if I change if(is_user_connected(player) && (cs_get_user_team(player) != CS_TEAM_SPECTATOR )) ->
if(is_user_connected(player) && (cs_get_user_team(player) == CS_TEAM_SPECTATOR ))
Code:
public randomize_teams(id, level)
{
// Declare variables
new num
new players[32]
new playersT_pos
new playersCT_pos
new playersT[32]
new playersCT[32]
new random_team
new difference
new player
if (!access(id,level))
{
console_print(id,"* [AMX MATCH] %L", id, "COMMAND_NO_AUTH")
console_print(id,"* %L", id, "COMMAND_NO_AUTH")
return PLUGIN_HANDLED
}
ColorChat(0,TEAM_COLOR,"^4 [AMX MATCH] ^3 %L", LANG_PLAYER, "RANDOMIZING_TEAMS")
// Set the arrays
get_players(players, num)
for(new i = 0; i < num; i++)
{
player = players[i]
if(is_user_connected(player) && (cs_get_user_team(player) != CS_TEAM_SPECTATOR ))
{
random_team = random_num(1,2)
if(random_team == 1)
{
playersT[playersT_pos++] = player
}
else
{
playersCT[playersCT_pos++] = player
}
}
}
difference = abs(playersCT_pos - playersT_pos)
if(difference > 1)
{
if(playersCT_pos > playersT_pos)
{
for(new i = playersCT_pos; (i >= 0) && (playersCT_pos > playersT_pos); i--)
{
playersT[playersT_pos++] = playersCT[--playersCT_pos]
}
}
else
{
for(new i = playersT_pos; (i >= 0) && (playersT_pos > playersCT_pos); i--)
{
playersCT[playersCT_pos++] = playersT[--playersT_pos]
}
}
}
// Set T team
for(new i = 0; i < playersT_pos; i++)
{
cs_set_user_team(playersT[i], CS_TEAM_T)
ColorChat(playersT[i],TEAM_COLOR,"^4 [AMX MATCH] ^3 %L", playersT[i], "NOW_ON_T")
}
// Set CT team
for(new i = 0; i < playersCT_pos; i++)
{
cs_set_user_team(playersCT[i], CS_TEAM_CT)
ColorChat(playersCT[i],TEAM_COLOR,"^4 [AMX MATCH] ^3 %L", playersCT[i], "NOW_ON_CT")
}
misc_restart_round("2")
return PLUGIN_CONTINUE
}