
   /* AMX Mod script.
   *
   * (c) Copyright 2002, Namralkeeg
   * This file is provided as is (no warranties).
   *
   *  TFC Server Specific Admin Commands
   *    Allows admin to move people to different teams.
   *   Does forced team balancing.
   *
   *  This script was ported from adminmod.
   */
   #include <amxmod>
   public admin_balance(id) {
       if (!(get_user_flags(id)&ADMIN_CVAR)){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that command")
           return PLUGIN_HANDLED
       }
       if (read_argc() < 2){
           client_print(id,print_console,"[AMX] Usage: amx_balance < on |
   off >")
           return PLUGIN_HANDLED
       }
       new arg[128]
       read_argv(1,arg,127)
       if(equali(arg,"on")) {
           set_cvar_num("amx_balance_teams",1);
       }
       else if(equali(arg,"off")) {
           set_cvar_num("amx_balance_teams",0);
       }
       else
           client_print(id,print_console,"[AMX] Usage: amx_balance < on |
   off >")
       return PLUGIN_HANDLED;
   }
   public admin_changeteam(id) {
       if (!(get_user_flags(id)&ADMIN_KICK)){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that command")
           return PLUGIN_HANDLED
       }
       if (read_argc() < 2){
           client_print(id,print_console,"[AMX]                    Usage:
   amx_[blue|red|green|yellow] < authid | part of nick >")
           return PLUGIN_HANDLED
       }
       if (cvar_exists("amx_balance_teams"))
       {
           new arg[33], cmd[128]
           read_argv(0,cmd,128)
           read_argv(1,arg,32)
           new player = find_player("c",arg)
           if (!player)
               player = find_player("bl",arg)
           if (player)
           {
               if (get_user_flags(player)&ADMIN_IMMUNITY)
               {
                   client_print(id,print_console,"[AMX]  The  player  has
   immunity")
                   return PLUGIN_HANDLED
               }
               if(equali(cmd,"amx_blue"))
                   client_cmd(player,"jointeam 1")
               else if(equali(cmd,"amx_red"))
                   client_cmd(player,"jointeam 2")
               else if(equali(cmd,"amx_yellow"))
                   client_cmd(player,"jointeam 3")
               else if(equali(cmd,"amx_green "))
                   client_cmd(player,"jointeam 4")
           }
           else {
               client_print(id,print_console,"[AMX]   Client   with  that
   authid or part of nick not found")
           }
       }
       else
           client_print(id,print_console,"[AMX] Unknown cvar")
       return PLUGIN_HANDLED;
   }
   public HandleJoinTeam(id) {
       if (get_user_flags(id) & ADMIN_IMMUNITY)
           return PLUGIN_CONTINUE
       if (id < 1)
           return PLUGIN_CONTINUE;
       if(get_cvar_num("amx_balance_teams")) {
           new iTeam = get_user_team(id)
           new newTeam[128]
           read_args(newTeam,128)
           /* If they're not currently on a team, ignore it. */
           if(iTeam <= 0)
               return PLUGIN_CONTINUE;
           new iNewTeam = strtonum(newTeam)
           /* If they're trying to switch to the team they're already on,
   ignore it. */
           if (iTeam == iNewTeam)
               return PLUGIN_CONTINUE;
           new iOldTeamCount = getteamcount(iTeam)
           /*  If  they're  the only one on their current team, ignore it
   (this is for instances
           like  'Hunted',  where  the hunted team has only one person on
   it) */
           //if(iOldTeamCount<=1)
           //    return PLUGIN_CONTINUE
           new iNewTeamCount = getteamcount(iNewTeam)
           /* If there's only one person on the other team, ignore it. */
           //if(iNewTeamCount<=1)
           //    return PLUGIN_CONTINUE
           /*  Otherwise,  only allow the switch if the new team has less
   people than the old team. */
           if(iNewTeamCount >= iOldTeamCount) {
               client_print(id,print_notify,"Old Team: %d New Team: %d --
   Team Switch Denied", iOldTeamCount, iNewTeamCount)
               return PLUGIN_HANDLED
           }
       }
       return PLUGIN_CONTINUE;
   }
   getteamcount(teamid)
   {
       new players[32], num, cnt=0
       get_players(players,num)
       for(new i = 0; i < num; i++)
       {
           if(get_user_team(players[i]) == teamid)
               cnt++
       }
       return cnt
   }
   public plugin_init() {
       register_plugin("TFC Admin Plugin","0.1","Namralkeeg")
       register_clcmd("amx_balance","admin_balance",ADMIN_CVAR,"amx_balan
   ce <^"on^" | ^"off^">: Sets the forced team balancing.");
       register_clcmd("amx_blue","admin_changeteam",ADMIN_KICK,"amx_blue
   <target>: Changes target to the blue team.");
       register_clcmd("amx_green","admin_changeteam",ADMIN_KICK,"amx_gree
   n <target>: Changes target to the green team.");
       register_clcmd("amx_red","admin_changeteam",ADMIN_KICK,"amx_red
   <target>: Changes target to the red team.");
       register_clcmd("amx_yellow","admin_changeteam",ADMIN_KICK,"amx_yel
   low <target>: Changes target to the yellow team.");
       register_clcmd("jointeam","HandleJoinTeam");
       register_cvar("amx_balance_teams","0")
       return PLUGIN_CONTINUE;
   }
