

/*********************************************************************************
*   Chicken Mod - 1.0.5
*   Official site - www.joe.to/chicken
*
*   AdminMod Version was created by OLO                                 
*   http://forums.unitedadmins.com/attachment.php?s=&postid=31796   
*   AMX Port by Tcquest78
*
*
*   Brought to you by OLO, [DsV]T(+)rget and dJeyL
*   http://djeyl.net/chickenmod.php
*                                                   
*   SMA Fixed by [DsV]T(+)rget and dJeyL
*   Commands(Most need ADMIN_LEVEL_A, can be changed with the ACCESS_CHICKEN define)                                         
*
*   amx_chicken
*   amx_unchicken
*   amx_chickenteam (0,1, or 2)
*   amx_unchickenteam (0,1, or 2)
*     amx_chicken_egg (0 or 1)
*     amx_chicken_bomb (0 or 1)
*     amx_chicken_gravity (# percent, > 0)
*     amx_chicken_maxspeed
*     amx_chicken_hprotect (0 or 1)
*   amx_chicken_life (1 - 255)
*   amx_chicken_glow (0 or 1)
*   amx_chickenme (For users, will make user a chicken)
*   amx_unchickenme (See above, will unchicken)
*   amx_chicken_self (0 or 1)(Will allow/disallow amx_chickenme/amx_unchickenme)
*    New:
*     amx_chicken_match <1 | 0>(Chickens Only! Takes effect on new round!)
*********************************************************************************/
#include <amxmod>

#define ACCESS_CHICKEN ADMIN_LEVEL_A
#define FLAG_INVALID 0
#define FLAG_CHICKEN 1

/************************ CHICKEN CONFIGURATION **************************/

// Sets health protection ON or OFF
// 1: ON : health can't be > 255
// 0: OFF: health has no theorical limit but will not be printed correctly in game
new HealthProtect = 0;

/************************ END OF CONFIGURATION ***************************/
new amx_chickenself = 0
new amx_chickenmatch = 0
new UserFlags[33] = {FLAG_INVALID,...};
new UserOldName[33][32];
new STRING_VERSION[256] = "1.0.5";

chicken_sound(sndno) {
  new i;
  new players[32]
  new iMaxPlayers 
  get_players(players,iMaxPlayers)

  if(sndno == 0) {
      for (i = 1; i <= iMaxPlayers; i++) {
          client_cmd(players[i],"spk sound/misc/chicken0");
    }
  } else if(sndno == 1) {
      for (i = 1; i <= iMaxPlayers; i++) {
          client_cmd(players[i],"spk sound/misc/cow");
    }
  }
}

public user_check_auth(id) {
   if (get_user_flags(id)&ACCESS_CHICKEN)
      return 1
   return 0
}

public amx_chickenme(id) {
   new name[32]
   get_user_name(id,name,32)
   if (amx_chickenself == 1) {
      if (is_user_connected(id) == 1 && UserFlags[id] == FLAG_INVALID) {
         UserFlags[id] = FLAG_CHICKEN;
         copy(UserOldName[id],32,name);
         client_cmd(id,"name %s(Chicken)",name);
         server_cmd("c_chicken # %i",id);
         chicken_sound(0);
         client_print(0,print_chat,"%s has been transformed into a chicken",UserOldName[id]);
      } else {
         client_print(id,print_console,"Already chicken or unrecognized player :");
         client_print(id,print_console,"%s",name);
      }
   } else {
      client_print(id,print_console,"[AMX] Disabled by admin")
   }
   return PLUGIN_HANDLED;
}

public amx_chicken(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied!")
      return PLUGIN_HANDLED
   }
   new namet[32]  
   read_argv(1,namet,32)
   new uid = find_player("b",namet)
   new name[32]
   get_user_name(uid,name,32)
   
   if (is_user_connected(uid) == 1 && UserFlags[uid] == FLAG_INVALID) {
      UserFlags[uid] = FLAG_CHICKEN;
      copy(UserOldName[uid],32,name);
      client_cmd(uid,"name %s(Chicken)",name);
      server_cmd("c_chicken # %i",uid);
      chicken_sound(0);
      client_print(0,print_chat,"%s has been transformed into a chicken",UserOldName[uid]);
   } else {
      client_print(id,print_console,"Already chicken or unrecognized player :");
      client_print(id,print_console,"%s",name);
   }
   return PLUGIN_HANDLED;
}
   
public amx_unchicken(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied!")
      return PLUGIN_HANDLED
   }
   new namet[32]  
   read_argv(1,namet,32)
   new name[32] 
   new uid = find_player("b",namet)
   get_user_name(uid,name,32)
   
   if (is_user_connected(uid) == 1) {
      UserFlags[uid] = FLAG_INVALID;
      if (strlen(UserOldName[uid]) != 0) {
         client_cmd(uid,"name ^"%s^"",UserOldName[uid])      
      } else {
         client_cmd(uid,"name ^"NotAChicken #%i^"",uid)
      }
      server_cmd("c_unchicken # %i",uid);
      chicken_sound(1);
      client_print(0,print_chat,"%s is restored to human form",UserOldName[uid]);
   } else {
      client_print(id,print_console,"Already chicken or unrecognized player :");
      client_print(id,print_console,"%s",name);
   }
   return PLUGIN_HANDLED;
}

public amx_unchickenme(id) {
   new name[32] 
   get_user_name(id,name,32)
   if (amx_chickenself == 1) {
      if (is_user_connected(id) == 1) {
         UserFlags[id] = FLAG_INVALID;
         if (strlen(UserOldName[id]) != 0) {
            client_cmd(id,"name ^"%s^"",UserOldName[id])      
         } else {
            client_cmd(id,"name ^"NotAChicken #%i^"",id)
         }
         server_cmd("c_unchicken # %i",id);
         chicken_sound(1);
         client_print(0,print_chat,"%s is restored to human form",UserOldName[id]);
      } else {
         client_print(id,print_console,"Already chicken or unrecognized player :");
         client_print(id,print_console,"%s",name);
      }
   } else {
      client_print(id,print_console,"[AMX] Disabled by admin!")
   }
   return PLUGIN_HANDLED
}

public amx_chickenteam(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied!")
      return PLUGIN_HANDLED
   }
   new teamnum_str[12]
   new teamname[32]  
   read_argv(1,teamnum_str,12)
   new teamnum = str_to_num(teamnum_str)
   if (teamnum == 1) {
      copy(teamname,32,"T")
   } else if (teamnum == 2) {
      copy(teamname,32,"CT")
   } else if (teamnum == 0) {
      copy(teamname,32,"Everyone")
   } else {
      client_print(id,print_console,"Usage: amx_chickenteam <0 | 1 | 2>")
   }
   new players[32], num, uid, name[32]
   if (teamnum != 0)
      get_players(players,num,"e",teamname)
   if (teamnum == 0)
      get_players(players,num)
   for(new i = 0; i<num; i++) {
      uid = players[i] 
      get_user_name(players[i],name,32)
      if (is_user_connected(uid) == 1 && UserFlags[uid] == FLAG_INVALID) {
         UserFlags[uid] = FLAG_CHICKEN;
         copy(UserOldName[uid],32,name);
         client_cmd(uid,"name ^"%s(Chicken)^"",name);
         server_cmd("c_chicken # %i",uid);
      }
   }
   if (teamnum != 0)
      client_print(0,print_chat,"The %s's have been turned into chickens!",teamname)
   if (teamnum == 0)
      client_print(0,print_chat,"Everyone has become a chicken!")
   chicken_sound(0)
   return PLUGIN_HANDLED;
}

public amx_unchickenteam(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied!")
      return PLUGIN_HANDLED
   }
   new teamnum_str[12]
   new teamname[32]  
   read_argv(1,teamnum_str,12)
   new teamnum = str_to_num(teamnum_str)
   if (teamnum == 1) {
      copy(teamname,32,"T")
   } else if (teamnum == 2) {
      copy(teamname,32,"CT")
   } else if (teamnum == 0) {
      copy(teamname,32,"Everyone")
   } else {
      client_print(id,print_console,"Usage: amx_unchickenteam <0 | 1 | 2>")
   }
   new players[32], num, uid, name[32]
   if(teamnum != 0)
      get_players(players,num,"e",teamname)
   if(teamnum == 0)
      get_players(players,num)

   for(new i = 0; i<num; i++) {
      uid = players[i] 
      get_user_name(players[i],name,32)
      UserFlags[uid] = FLAG_INVALID;
      if (strlen(UserOldName[uid]) != 0) {
         client_cmd(uid,"name ^"%s^"",UserOldName[uid])      
      } else {
         client_cmd(uid,"name ^"NotAChicken #%i^"",uid)
      }
      server_cmd("c_unchicken # %i",uid);
   }
   if(teamnum != 0)   
      client_print(0,print_chat,"The %s's have been restored to human form!",teamname)
   if(teamnum == 0)
      client_print(0,print_chat,"Everyone has been restored to human form!")
   chicken_sound(1)
   return PLUGIN_HANDLED;
}


public client_disconnect(id) {
   new UserIndex = id
   if (UserIndex >= 1 && UserIndex <= 32) {
      UserFlags[UserIndex] = FLAG_INVALID;
      copy(UserOldName[UserIndex],32,"");
   }
   return PLUGIN_CONTINUE;
}

public client_infochanged(id) {
   new NewName[32];
   new OldName[32];
   get_user_name(id,OldName,32)
   get_user_info(id,"name",NewName,32)
   new amx_chicken_name[12]
   get_cvar_string("amx_chicken_name",amx_chicken_name,12)
   if(str_to_num(amx_chicken_name) != 1)
	return PLUGIN_HANDLED

   if(equal(OldName,NewName)==0) {
      if (UserFlags[id] == FLAG_CHICKEN) {
         client_cmd(id, "name ^"%s(Chicken)^"",OldName);
         return PLUGIN_HANDLED;
      }
   }
   return PLUGIN_CONTINUE;
}

public amx_chicken_glow(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
      if(get_cvar_num("c_glow")==0) {
         client_print(id,print_console,"Chicken Glowing is currently OFF")
      } else {
         client_print(id,print_console,"Chicken Glowing is currently ON")
      }
   }
   new Datastr[12]  
   read_argv(1,Datastr,12)
   new Data = str_to_num(Datastr)
   
   if(Data==0 && cvar_exists("c_glow")) {
      server_cmd("c_glow 0");
      client_print(0,print_chat,"[CHICKEN] The Admin has DISABLED chicken glowing");
   }
   else if(cvar_exists("c_glow")) {
      server_cmd("c_glow 1");
      client_print(0,print_chat,"[CHICKEN] The Admin has ENABLED chicken glowing");
   }
   return PLUGIN_HANDLED;
}

public amx_chicken_egg(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
      if(get_cvar_num("c_egg")==0) {
         client_print(id,print_console,"Chicken Egg Dropping is currently OFF")
      } else {
         client_print(id,print_console,"Chicken Egg Dropping is currently ON")
      }
   }
   new Datastr[12]  
   read_argv(1,Datastr,12)
   new Data = str_to_num(Datastr)
   
   if(Data==0 && cvar_exists("c_egg")) {
      server_cmd("c_egg 0");
      client_print(0,print_chat,"[CHICKEN] The Admin has DISABLED chicken egg dropping");
   }
   else if(cvar_exists("c_egg")) {
      server_cmd("c_egg 1");
      client_print(0,print_chat,"[CHICKEN] The Admin has ENABLED chicken egg dropping");
   }
   return PLUGIN_HANDLED;
}

public amx_chicken_bomb(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
      if(get_cvar_num("c_bomb")==0) {
         client_print(id,print_console,"Chicken Bomb Planting is currently OFF")
      } else {
         client_print(id,print_console,"Chicken Bomb Planting is currently ON")
      }
   }
   new Datastr[12]  
   read_argv(1,Datastr,12)
   new Data = str_to_num(Datastr)
   
   if(Data==0 && cvar_exists("c_bomb")) {
      server_cmd("c_bomb 0");
      client_print(0,print_chat,"[CHICKEN] The Admin has DISABLED chicken bomb plantingg");
   }
   else if(cvar_exists("c_bomb")) {
      server_cmd("c_bomb 1");
      client_print(0,print_chat,"[CHICKEN] The Admin has ENABLED chicken bomb plantingg");
   }
   return PLUGIN_HANDLED;
}

public amx_chicken_self(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
      if(amx_chickenself==0) {
         client_print(id,print_console,"Chickening self is currently OFF")
      } else {
         client_print(id,print_console,"Chickening self is currently ON")
      }
   }
   
   if(amx_chickenself == 1) {
      amx_chickenself = 0
      client_print(0,print_chat,"[CHICKEN] The Admin has DISABLED chicken/unchicken self");
   }
   else if(amx_chickenself == 0) {
      amx_chickenself = 1
      client_print(0,print_chat,"[CHICKEN] The Admin has ENABLED chicken/unchicken self");
   }
   return PLUGIN_HANDLED;
}

public amx_chicken_hprot(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
      if(HealthProtect==0) {
         client_print(id,print_console,"Chicken Health Protection is currently OFF")
      } else {
         client_print(id,print_console,"Chicken Health Protection is currently ON")
      }
   }
   new Datastr[12]  
   read_argv(1,Datastr,12)
   new Data = str_to_num(Datastr)
   
   if(Data==0) {
      HealthProtect = 0
      client_print(0,print_chat,"[CHICKEN] The Admin has DISABLED chicken Health Protectiong");
   }
   else {
      HealthProtect = 1
      client_print(0,print_chat,"[CHICKEN] The Admin has ENABLED chicken Health Protectiong");
   }
   return PLUGIN_HANDLED;
}


public amx_chicken_life(id) {
   if (!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
          client_print(id,print_console,"Chickens Health is currently : %i",get_cvar_num("c_health"));
          return PLUGIN_HANDLED
   }
   new iDataStr[12]
   read_argv(1,iDataStr,12)
   new iData = str_to_num(iDataStr)
   if (iData > 0) {
       if(iData <= 255 || HealthProtect == 0) {
             client_print(id,print_console,"Chickens Health is now set to : %i",iData)
             client_print(0,print_chat,"[CHICKEN] The Admin has set chickens HEALTH to : %i",iData)
             server_cmd("c_health %i",iData)
       } else {
         client_print(id,print_console,"Health Protection is on! Setting Chicken Max health to 255")
         client_print(0,print_chat,"[CHICKEN] The Admin has set chickens HEALTH to: 255")
         server_cmd("c_health 255")
      }
   } else {
             client_print(id,print_console,"INVALID NUMBER : please choose a number > 0");
   }
   return PLUGIN_HANDLED;
}

public amx_chicken_grav(id) {
   if (!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
          client_print(id,print_console,"Chickens Gravity is currently : %i%",get_cvar_num("c_gravity"));
          return PLUGIN_HANDLED
   }
   new iDataStr[12]
   read_argv(1,iDataStr,12)
   new iData = str_to_num(iDataStr)
   if (iData > 0) {
             client_print(id,print_console,"Chickens Gravity is now set to : %i%",iData)
             client_print(0,print_chat,"[CHICKEN] The Admin has set chickens Gravity to : %i%",iData)
             server_cmd("c_gravity %i",iData)
   }
   else {
             client_print(id,print_console,"INVALID NUMBER : please choose a number > 0");
   }
   return PLUGIN_HANDLED;
}

public amx_chicken_sp(id) {
   if (!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
          client_print(id,print_console,"Chickens Max Speed is currently : %i%",get_cvar_num("c_maxspeed"));
          return PLUGIN_HANDLED
   }
   new iDataStr[12]
   read_argv(1,iDataStr,12)
   new iData = str_to_num(iDataStr)
   if (iData > 0) {
             client_print(id,print_console,"Chickens Max Speed is now set to : %i",iData);
             client_print(id,print_chat,"[CHICKEN] The Admin has set chickens MAX SPEED to : %i",iData);
             server_cmd("c_maxspeed %i",iData);
   } else {
                     client_print(id,print_console,"Chickens now have maximum speed");
                     client_print(id,print_chat,"[CHICKEN] The Admin has given MAXIMUM SPEED to chickens");
                     server_cmd("c_maxspeed %i",iData);
   }
   return PLUGIN_HANDLED;
}

public reset_event(id) {
      if(amx_chickenmatch==0)
      return PLUGIN_HANDLED
      if (is_user_connected(id) == 1 && UserFlags[id] == FLAG_INVALID) {
         new name[32+1]
         get_user_name(id,name,32)
         UserFlags[id] = FLAG_CHICKEN;
         copy(UserOldName[id],32,name);
         client_cmd(id,"name %s(Chicken)",name);
         server_cmd("c_chicken # %i",id);
      }
      return PLUGIN_HANDLED
}

public amx_chicken_match(id) {
   if(!(user_check_auth(id))) {
      client_print(id,print_console,"[AMX] Permission Denied")
      return PLUGIN_HANDLED
   }
   if (read_argc() == 1) {
      if(amx_chickenmatch==0) {
         client_print(id,print_console,"Chicken match is currently OFF")
      } else {
         client_print(id,print_console,"Chicken match is currently ON")
      }
   }
   
   if(amx_chickenmatch == 1) {
      amx_chickenmatch = 0
      client_print(0,print_chat,"[CHICKEN] The Admin has DISABLED chicken match");
   }
   else if(amx_chickenmatch == 0) {
      amx_chickenmatch = 1
      client_print(0,print_chat,"[CHICKEN] The Admin has ENABLED chicken match");
   }
   return PLUGIN_HANDLED;
}


public plugin_init() {
   register_plugin("Amx Chicken Plugin",STRING_VERSION,"Somebody Else");
   register_event("ResetHUD","reset_event","b")
   register_cvar("amx_chicken_nchange","1")
   register_clcmd("amx_chicken_self","amx_chicken_self",ACCESS_CHICKEN,"amx_chicken_self <0 | 1> Disables/Enables amx_chickeme/amx_unchickenme")
   register_clcmd("amx_chickenme","amx_chickenme",0,"amx_chickenme: chicken yourself")
   register_clcmd("amx_unchickenme","amx_unchickenme",0,"amx_unchickenme: unchicken yourself")
   register_clcmd("amx_chicken","amx_chicken",ACCESS_CHICKEN,"amx_chicken <target>: chicken-fy target");
   register_clcmd("amx_unchicken","amx_unchicken",ACCESS_CHICKEN,"amx_unchicken <target>: unchicken-fy target");
   register_clcmd("amx_chickenteam","amx_chickenteam",ACCESS_CHICKEN,"amx_chickenteam <#>: chicken-fy team (1 = Terrorists, 2 = Counter-Terrorists 0 = All)");
   register_clcmd("amx_unchickenteam","amx_unchickenteam",ACCESS_CHICKEN,"amx_unchickenteam <#>: unchicken-fy team (1 = Terrorists, 2 = Counter-Terrorists 0 = All)");

   register_clcmd("amx_chicken_glow","amx_chicken_glow",ACCESS_CHICKEN,"amx_chicken_glow <0/1>: prints / sets chickens glowing off or on");
   register_clcmd("amx_chicken_hprotect","amx_chicken_hprot",ACCESS_CHICKEN,"amx_chicken_hprotect <0/1>: prints / sets chickens health protection");
   register_clcmd("amx_chicken_egg","amx_chicken_egg",ACCESS_CHICKEN,"amx_chicken_egg <0/1>: prints / sets chickens ability to drop he grenades as eggs");
   register_clcmd("amx_chicken_bomb","amx_chicken_bomb",ACCESS_CHICKEN,"amx_chicken_bomb <0/1>: prints / sets chickens ability to plant the bomb");
   register_clcmd("amx_chicken_health","amx_chicken_life",ACCESS_CHICKEN,"amx_chicken_health <#>: prints / sets chickens health");
   register_clcmd("amx_chicken_gravity","amx_chicken_grav",ACCESS_CHICKEN,"amx_chicken_gravity <#>: prints / sets chickens gravity (% of normal gravity)");
   register_clcmd("amx_chicken_maxspeed","amx_chicken_sp",ACCESS_CHICKEN,"amx_chicken_maxspeed <#>: prints / sets chickens maxspeed (0 for max)");
   register_clcmd("amx_chicken_match","amx_chicken_match",ACCESS_CHICKEN,"amx_chicken_match <1 | 0>: prints / sets chicken match state")
   return PLUGIN_CONTINUE;   
} 

