
   /* AMX Mod script.
   *
   * (c) Copyright 2002, OLO axtended by Sai
   * This file is provided as is (no warranties).
   *
   */
   #include <amxmod>
   /*
   * NEW cvar: amx_mapscfg "1"/"0"
   *   if   amx_mapscfg   set   1   (in   admin.cfg)  then  use  maps.cfg
   (addons/amx/maps.cfg) for amx_votemap.
   *  if  amx_mapscfg  set  0  (default)  then use all maps on server for
   amx_votemap.
   *
   * For list maps (from maps.cfg).
   * NEW  command: amx_maps
   *
   *
   * vote for changing the level:
   * amx_votemap < map > [ map ]
   * examples:
   * amx_votemap "de_dust"
   * amx_votemap "de_dust" "de_dust2" "cs_italy"
   *
   * vote for kicking the player:
   * amx_votekick < part of nick >
   * examples:
   * amx_votekick "Man"
   *
   * vote for banning and kicking the player for 30 minutes:
   * amx_voteban < part of nick >
   * examples:
   * amx_voteban "Man"
   *
   * custom voting:
   * amx_vote < question > < answer1 > < answer2 >
   * examples:
   * amx_vote "sv_restart" "5" "0"
   * amx_vote "mp_timelimit" "20" "45"
   * amx_vote "are you hungry?" "yes" "no"
   *
   */
   #define MAX_MAPS 64
   new bool:cstrike_running
   new maplist[32] = "addons/amx/maps.cfg"
   new answer[128]
   new option_name[4][32]
   new option[4]
   new valid_maps = 0
   new Float:vote_ratio
   new Float:voting
   new num_words = 0
   new maps[MAX_MAPS][32]
   public read_list(){
      new index=0, line[32]
      if (file_exists(maplist)){
         new length
         while(read_file(maplist,index++,line,32,length))
         maps[index] = line
         num_words = index
         }
      else log_message("[AMX] file maps.cfg not found")
      return PLUGIN_CONTINUE
   }
   public admin_maps(id){
   for (new i = 1; i < num_words; ++i){
       client_print(id,print_console,"%s", maps[i])
   }
   return PLUGIN_HANDLED
   }
   public delay_action(cmd[])
       server_cmd(cmd)
   public check_votes() {
       new players[32], inum, best = 0
       get_players(players,inum,"c")
       for(new a = 0; a < 4; ++a)
           if (option[a] > option[best])
               best = a
       new  Float:result_v = inum ? (float(option[best]) / float(inum)) :
   0.0
       if (result_v < vote_ratio){
           client_print(0,print_chat,"[AMX] Voting failed...")
           log_to_file("addons/amx/admin.log","World            triggered
   ^"voting_failure^" (needed ^"%.2f^") (ratio ^"%.2f^")",
               vote_ratio,result_v)
           return PLUGIN_HANDLED
       }
       new execute[128]
       new len = format(execute,127,answer,option_name[best])
       set_task(2.0,"delay_action",0,execute,len + 1)
       client_print(0,print_chat,"[AMX]  Voting  successful.  The result:
   %s.",execute)
       log_to_file("addons/amx/admin.log","World                triggered
   ^"voting_success^"   (needed   ^"%.2f^")   (ratio   ^"%.2f^")  (result
   ^"%s^")",
           vote_ratio,result_v,execute)
       return PLUGIN_HANDLED
   }
   public vote_count(id,key){
       if (get_cvar_float("amx_vote_answers")) {
           new name[32]
           get_user_name(id,name,31)
           client_print(0,print_chat,"[AMX]   %s   voted   for  option  #
   %d.",name,key+1)
       }
       ++option[key]
       return PLUGIN_HANDLED
   }
   public admin_votemap(id) {
       if (!(get_user_flags(id)&ADMIN_LEVEL_B)){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that command.")
           return PLUGIN_HANDLED
       }
       if (voting > get_gametime()){
           client_print(id,print_console,"[AMX]   There  is  already  one
   voting...")
           return PLUGIN_HANDLED
       }
       if  (voting  >  0.0 && voting + get_cvar_float("amx_vote_delay") >
   get_gametime()) {
           client_print(id,print_console,"[AMX]  Voting  not  allowed  at
   this time.")
           return PLUGIN_HANDLED
       }
       new argc = read_argc()
       if (argc > 5)
           argc = 5
       if (argc < 2){
           client_print(id,print_console,"[AMX]  Usage: amx_votemap < map
   > [ map ] [ map ] [ map ]")
           return PLUGIN_HANDLED
       }
       new menu_msg[256]
       new keys = (1<<9)
       valid_maps = 0
       if (get_cvar_num("amx_mapscfg") == 1) {
       for(new i = 1; i < argc; ++i){
           read_argv(i,option_name[valid_maps],31)
           for (new j = 1; j < num_words; ++j){
               if        (is_map_valid(option_name[valid_maps])        &&
   containi(option_name[valid_maps],maps[j]) != -1)
               valid_maps++;
           }
       }
       }
       else {
       for(new i = 1; i < argc; ++i){
           read_argv(i,option_name[valid_maps],31)
           if (is_map_valid(option_name[valid_maps]))
               valid_maps++;
       }
       }
       if (valid_maps == 0 && !(get_cvar_num("amx_mapscfg") == 1)) {
           client_print(id,print_console,"[AMX]      Given     %s     not
   valid.",(argc==2)?"map is":"maps are")
           return PLUGIN_HANDLED
       }
       else if (valid_maps == 0 && get_cvar_num("amx_mapscfg") == 1){
           client_print(id,print_console,"[AMX]  Given  %s not valid. Use
   amx_maps to view list.",(argc==2)?"map is":"maps are")
           return PLUGIN_HANDLED
       }
       else if (valid_maps > 1){
           if(cstrike_running)
               copy(menu_msg,255,"\y[AMX] Choose map \w^n^n")
           else
               copy(menu_msg,255,"[AMX] Choose map ^n^n")
           new temp[128]
           for(new a = 0; a < valid_maps; ++a){
               format(temp,127,"%d.  %s^n",a+1,option_name[a])
               add(menu_msg,255,temp)
               keys |= (1<<a)
           }
           add(menu_msg,255,"^n0.  None")
       }
       else{
           if(cstrike_running)
               format(menu_msg,255,"\y[AMX]       Change      map      to
   %s?\w^n^n1.  Yes^n0.  No",option_name[0])
           else
               format(menu_msg,255,"[AMX]       Change       map       to
   %s?^n^n1.  Yes^n0.  No",option_name[0])
           keys |= (1<<0)
       }
       new ip[16],name[32]
       get_user_ip(id,ip,15)
       get_user_name(id,name,31)
       log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"          vote
   map(s)",name,get_user_userid(id),ip)
       new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
       voting = get_gametime() + vote_time
       vote_ratio = get_cvar_float("amx_votemap_ratio")
       copy(answer,127,"changelevel %s")
       show_menu(0,keys,menu_msg,floatround(vote_time))
       set_task(vote_time,"check_votes")
       client_print(id,print_console,"[AMX] Voting has started...")
       for(new j = 0; j < 4;++j) option[j] = 0
       return PLUGIN_HANDLED
   }
   public admin_vote(id) {
       if (!(get_user_flags(id)&ADMIN_VOTE)){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that command.")
           return PLUGIN_HANDLED
       }
       if (voting > get_gametime()){
           client_print(id,print_console,"[AMX]   There  is  already  one
   voting...")
           return PLUGIN_HANDLED
       }
       if  (voting  >  0.0 && voting + get_cvar_float("amx_vote_delay") >
   get_gametime()) {
           client_print(id,print_console,"[AMX]  Voting  not  allowed  at
   this time.")
           return PLUGIN_HANDLED
       }
       if (read_argc() < 4){
           client_print(id,print_console,"[AMX]  amx_vote  < question > <
   answer#1 > < answer#2 >")
           return PLUGIN_HANDLED
       }
       new quest[128]
       read_argv(1,quest,127)
       if
   ((contain(quest,"sv_password")!=-1)||(contain(quest,"rcon_password")!=
   -1)){
           client_print(id,print_console,"[AMX]  Voting for that has been
   forbidden.")
           return PLUGIN_HANDLED
       }
       read_argv(2,option_name[0],31)
       read_argv(3,option_name[1],31)
       new authid[16],name[32]
       get_user_authid(id,authid,15)
       get_user_name(id,name,31)
       log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"  vote  custom
   (question ^"%s^") (option1 ^"%s^") (option2 ^"%s^")",
           name,get_user_userid(id),authid,quest,option_name[0],option_na
   me[1])
       new menu_msg[256]
       new keys = (1<<0)|(1<<1)
       if(cstrike_running)
           format(menu_msg,255,"\y[AMX] Vote:
   %s?\w^n^n1.  %s^n2.  %s",quest,option_name[0],option_name[1])
       else
           format(menu_msg,255,"[AMX] Vote:
   %s?^n^n1.  %s^n2.  %s",quest,option_name[0],option_name[1])
       new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
       voting = get_gametime() + vote_time
       vote_ratio = get_cvar_float("amx_vote_ratio")
       format(answer,127,"%s %%s",quest)
       show_menu(0,keys,menu_msg,floatround(vote_time))
       set_task(vote_time,"check_votes")
       client_print(id,print_console,"[AMX] Voting has started...")
       for(new j = 0; j < 4;++j) option[j] = 0
       return PLUGIN_HANDLED
   }
   public admin_votekickban(id) {
       if (!(get_user_flags(id)&ADMIN_LEVEL_B)){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that command.")
           return PLUGIN_HANDLED
       }
       if (voting > get_gametime()){
           client_print(id,print_console,"[AMX]   There  is  already  one
   voting...")
           return PLUGIN_HANDLED
       }
       if  (voting  >  0.0 && voting + get_cvar_float("amx_vote_delay") >
   get_gametime()) {
           client_print(id,print_console,"[AMX]  Voting  not  allowed  at
   this time.")
           return PLUGIN_HANDLED
       }
       new cmd[32]
       read_argv(0,cmd,31)
       if (read_argc() < 2){
           client_print(id,print_console,"[AMX] Usage: %s < ip or part of
   nick >",cmd)
           return PLUGIN_HANDLED
       }
       new voteban = equal(cmd,"amx_voteban") ? 1 : 0
       new arg[32]
       read_argv(1,arg,31)
       new player = find_player("d",arg)
       if (!player) player = find_player("bl",arg)
       new menu_msg[256]
       new keys = (1<<9)
       if (player == 0) {
           client_print(id,print_console,"[AMX]  Client  with  that ip or
   part of nick not found.")
           return PLUGIN_HANDLED
       }
       else{
           if (get_user_flags(player)&ADMIN_IMMUNITY){
               new imname[32]
               get_user_name(player,imname,31)
               client_print(id,print_console,"[AMX]   Client  ^"%s^"  has
   immunity.",imname)
               return PLUGIN_HANDLED
           } else if (voteban && is_user_bot(player))   {
               new imname[32]
               get_user_name(player,imname,31)
               client_print(id,print_console,"[AMX]  Bot  ^"%s^" can't be
   banned.",imname)
               return PLUGIN_HANDLED
           }
           get_user_name(player,arg,31)
           if(cstrike_running)
               format(menu_msg,255,"\y[AMX] %s %s?\w^n^n1.  Yes^n0.  No",
   voteban ? "Ban" : "Kick", arg)
           else
               format(menu_msg,255,"[AMX]   %s   %s?^n^n1.  Yes^n0.  No",
   voteban ? "Ban" : "Kick", arg)
           if (voteban)
               get_user_ip(player,option_name[0],31)
           else
               num_to_str(get_user_userid(player),option_name[0],31)
           keys |= (1<<0)
       }
       new ip[16],name[32]
       get_user_ip(id,ip,15)
       get_user_name(id,name,31)
       log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"    vote    %s
   (target ^"%s^")",
           name,get_user_userid(id),ip,voteban ? "ban" : "kick",arg)
       new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
       voting = get_gametime() + vote_time
       vote_ratio   =   get_cvar_float(voteban  ?  "amx_voteban_ratio"  :
   "amx_votekick_ratio")
       copy(answer,127, voteban ? "banid 30.0 %s kick" : "kick #%s")
       show_menu(0,keys,menu_msg,floatround(vote_time))
       set_task(vote_time,"check_votes")
       client_print(id,print_console,"[AMX] Voting has started...")
       for(new j = 0; j < 4;++j) option[j] = 0
       return PLUGIN_HANDLED
   }
   public plugin_init()
   {
       register_plugin("Admin Votes","0.10 LAN","default")
       register_menucmd(register_menuid("[AMX]    Change    map   to   ")
   ,(1<<0)|(1<<1)|(1<<2)|(1<<3),"vote_count")
       register_menucmd(register_menuid("[AMX]      Choose     map     ")
   ,(1<<0)|(1<<1)|(1<<2)|(1<<3),"vote_count")
       register_menucmd(register_menuid("[AMX]           Kick          ")
   ,(1<<0)|(1<<1)|(1<<2)|(1<<3),"vote_count")
       register_menucmd(register_menuid("[AMX]           Ban           ")
   ,(1<<0)|(1<<1)|(1<<2)|(1<<3),"vote_count")
       register_menucmd(register_menuid("[AMX]          Vote:          ")
   ,(1<<0)|(1<<1)|(1<<2)|(1<<3),"vote_count")
       register_clcmd("amx_votemap","admin_votemap",ADMIN_LEVEL_B,"amx_vo
   temap < map > [ map ] [ map ] [ map ]")
       register_clcmd("amx_votekick","admin_votekickban",ADMIN_LEVEL_B,"a
   mx_votekick < authid or part of nick >")
       register_clcmd("amx_voteban","admin_votekickban",ADMIN_VOTE,"amx_v
   oteban < authid or part of nick >")
       register_clcmd("amx_vote","admin_vote",ADMIN_VOTE,"amx_vote      <
   question > < answer#1 > < answer#2 >")
       register_clcmd("amx_maps","admin_maps",0,"amx_maps : List maps for
   voting")
       register_cvar("amx_votekick_ratio","0.80")
       register_cvar("amx_voteban_ratio","0.90")
       register_cvar("amx_votemap_ratio","0.60")
       register_cvar("amx_vote_ratio","0.60")
       register_cvar("amx_vote_time","20")
       register_cvar("amx_vote_answers","1")
       register_cvar("amx_vote_delay","180")
       register_cvar("amx_mapscfg","0")
       read_list()
       new mod_name[32]
       get_modname(mod_name,31)
       cstrike_running = equal(mod_name,"cstrike") ? true : false
       return PLUGIN_CONTINUE
   }
