
     /* AMX Mod script.
   *
   * (c) Copyright 2002-2003, SPiRiT
   * Made by SPiRiT
   * Http://www.cscup.com
   * Inspired of f117bomb & beetle & Shromilder scripts
   * But this is the super deluxe version ;-p :p :p :p
   *
   * This file is provided as is (no warranties).
   *
   * -=[ AMX Match SUPER Deluxe ]=-
   *
   * Works with AMX 0.9.3 or more only!!
   *    You    also    need   some   config   files   which   are   here:
   http://shromy.free.fr/amx_match_cfgs.zip
   * Need admin level "a" and works with CS mod only.
   *
   *   These   plug-in   allow   you   to   play   matchs   in   MaxRound
   ((warmup,kniferound),warmup, CT, warmup2, Terrorist) or TimeLimit.
   *  It loads match server configs before the match and loads FFA server
   config when it's finished.
   * It takes screenshots and can also record demos if you want it.
   *
   * Usage:
   *  To  load a match: amx_match <CT's clan tag> <T's clan tag> <mrXX or
   clXX> <Config filename> [recdemo]
   *                  amx_match  <CT's  clan tag> <T's clan tag> <mrXX or
   clXX> <Config filename> [rechltv]
   *                  for exemple: amx_match SK eoL mr12 ecup recdemo
   *                               amx_match SK eoL mr12 ecup rechltv
   *
   *                               These  will load a match with MaxRound
   12 rule,
   *                               using ecup.cfg server config file, and
   will record demos & take screenshots
   *                               of every players.
   *                               P.S: if your clan tag has a space, use
   "". ex: "SK swe"
   *
   * To stop a match: amx_matchstop
   * To swap teams: amx_swapteams
   *
   *
   *
   * match_hltv_proxypassword : proxypassword of hltv
   * match_hltv_name: name of hltv
   * match_pause_on_disconnect : 0 - 1
   * match_kniferound : 0 - 1
   *  match_num_tobe_ready : number of player that must say ready by team
   (default=5)
   *
   * For MaxRound:
   *  When  a match is loaded, warmup time begins and match server config
   is loaded.
   * Then, when one player of each team says 'ready', the 1st half of the
   match starts.
   * When the maxround limit is reached, it goes back to warmup.
   * Then, when both teams say 'ready' again, the 2nd half starts.
   * When the game is finished, it tells you which team has won the match
   and loads FFA server config file.
   * It also records both side demos if you want it.
   *
   *
   * Config Files:
   * All config files need to be into addons/amx/plugins/leagues/ folder
   * and have .cfg extention (/!\ case sensitiv so .CFG will not work!!)
   * There are some special config files:
   *    -  default.cfg  is  a server config file which is executed before
   every games.
   *      It  can be used to disable some plug-ins like stats or set some
   default cvars
   *      which will erase your match config file cvars
   *    -  ffa.cfg is the server config file which is executed at the end
   of the match
   *      in order that your server can be played by everyone =)
   *    - cfglist.txt is the list of your available config file.
   *      It  is  shown  when  you  type  a wrong config file when you're
   trying to load a match.
   *      So  if  you  don't want to remember the name of all your server
   config file,
   *      just add them into these file =)
   *
   * cya, Shromilder
   *
   * Changelog:
   *  - 1.54 (spirit mod): hltv woking. Credits to en3my!
   *  - 1.51 (spirit mod): improve display ready/unready players by team
   *  -  1.50 (spirit mod): bugfixes and rewrite of count points,cleaning
   identation warning
   *  - 1.41 (spirit mod): bugfixes and rewrite of code
   *  -  1.40(spirit  mod) : added readybyplayer and match_num_tobe_ready
   cvar
   *  - 1.30(spirit mod) : added
   hltvsupport,pauseondisconnect,kniferound,chooseteam menu
   *  -  1.20:  added  amx_match_endtype  cvar  &  fixed  some  bugs like
   recording demos with voicecom on.
   *  -   1.10:   added   amx_match2  and  amx_swapteams  command,  added
   screenshots feature
   *  - 1.02: other bugs removed, less warmup msg flood
   *  - 1.01: added log commands, small bug removed
   *  - 1.00: first release
   *
   * To do:
   *  - amx_match_vote
   *  - add cvar: everybody must say ready
   */
   #include <amxmod>
   #include <amxmisc>
   #include <udp>
   new cmdtype // 1= amx_match
   new  match_inprogress  //  0=  no  match,  1=  warmup, 2= 1st half, 3=
   warmup2, 4= 2nd half ,5=kniferound warmup , 6=kniferound
   new  Team1[32],Team2[32],cfgfile[32],matchtype1,matchtype2,recdemo  //
   matchtype1= 1 -> mr, 2 -> tl
   new address_hltv = -1
   new setpause
   new removepause
   new pausable
   new paused
   new bool:KnifeEnabled
   new option[2]
   new voteswaps[] = "\yAMX %s SWAP TEAMS?\w^n^n1. Yes^n2. No"
   new p_info[33][5]
   new t1[4],t2[4]
   public auto_join(id){
   if ((p_info[id][0]==0) && (match_inprogress > 0) && (cmdtype==1) ){
         new parm[1]
         parm[0]=id
         set_task(1.0,"auto_join_delay",34,parm,1)
   }
   return PLUGIN_CONTINUE
   }
   public auto_join_delay(parm[1]){
      new id = parm[0]
      if (p_info[id][0]==0){
      set_task(1.0,"auto_join_delay",35,parm,1)
      select_team(id)
      }
      return PLUGIN_CONTINUE
   }
   public select_team(id){
      new menu_msg[256]
      format(menu_msg,255,"\ySelect    Team:\w^n^n1.    %s^n2.   %s^n^n",
   Team1,Team2)
      show_menu(id,(1<<0)|(1<<1)|(1<<2),menu_msg,-1)
      return PLUGIN_CONTINUE
   }
   public set_team(id,key){
   if (key == 0)
   {
   p_info[id][0] = 1
   if (t1[0]==1)
   {
   client_cmd(id, "chooseteam")
   client_cmd(id, "menuselect 1")
   }
   else
   {
   client_cmd(id, "chooseteam")
   client_cmd(id, "menuselect 2")
   }
   }
   else if (key == 1)
   {
   p_info[id][0] = 2
   if (t2[0]==1)
   {
   client_cmd(id, "chooseteam")
   client_cmd(id, "menuselect 1")
   }
   else
   {
   client_cmd(id, "chooseteam")
   client_cmd(id, "menuselect 2")
   }
   }
   return PLUGIN_HANDLED
   }
   public vote_swapteam(id){
      new Float:voting = get_cvar_float("match_last_voting")
      new num
      new players[32]
      if   (voting   &&  voting  +  get_cvar_float("match_vote_delay")  >
   get_gametime()) {
         client_print(id,print_chat,"*   Voting   not   allowed  at  this
   time...")
         return PLUGIN_HANDLED
      }
      new menu_msg[256]
      format(menu_msg,255,voteswaps)
      new Float:vote_time = get_cvar_float("match_vote_time")
      set_cvar_float("amx_last_voting",  get_gametime() + vote_time )
      if (t1[1]>t2[1]){
       get_players(players,num,"ae","TERRORIST")
      }
      else if (t2[1]>t1[1])
      {
       get_players(players,num,"ae","CT")
      }
      for(new i = 0; i < num; ++i)
      {
      show_menu(players[i],(1<<0)|(1<<1),menu_msg,floatround(vote_time))

      }
      set_task(vote_time,"check_votes")
      client_print(0,print_chat,"* Voting has started...")
      option[0]=option[1]=0
      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,"* %s a voté %s", name, key ? "Contre"
   : "Pour" )
      }
      ++option[key]
      return PLUGIN_HANDLED
   }
   public check_votes(id){
   if (option[0] > option[1]){

     if(t1[0]==1){
        t1[0]=2
        t2[0]=1
       }
       else if (t1[0]==2){
        t1[0]=1
        t2[0]=2
       }

     set_task(1.0,"swap_teams")
     set_task(5.0,"start_warmup")
     client_print(0,print_chat,"*  Voting  successful  (yes  ^"%d^")  (no
   ^"%d^").",option[0],option[1])
     }
     else{
         client_print(0,print_chat,"*  Voting  failed  (yes  ^"%d^")  (no
   ^"%d^").",option[0],option[1])
     }
   return PLUGIN_CONTINUE
   }
   public amx_enableknife(id) {

      new arg1[4]
      read_argv(1,arg1,3)

      if (equal(arg1,"1")||equali(arg1,"on")){
         KnifeEnabled = true
         unpause("b","switchweapon")
      }
      else if (equal(arg1,"0")||equali(arg1,"off")){
         KnifeEnabled = false
         pause("b","switchweapon")
      }
      else {
         console_print(id,"Knives   Only   Mode   is  %s",KnifeEnabled  ?
   "enabled" : "disabled")
         return PLUGIN_HANDLED
      }
      console_print(id,"Knives  Only  Mode %s",KnifeEnabled ? "enabled" :
   "disabled")
      client_print(0,print_center,"Knives     Only    Mode    Has    Been
   %s!",KnifeEnabled ? "Enabled" : "Disabled")

      engclient_cmd(0,"weapon_knife")

      set_hudmessage(0,  100,  0,  0.05,  0.65, 2, 0.02, 10.0, 0.01, 0.1,
   2)
      show_hudmessage(0,KnifeEnabled  ? "Knives Only Allowed" : "All Guns
   Allowed" )
      return PLUGIN_HANDLED
   }
   public switchweapon(id)
      engclient_cmd(id,"weapon_knife")
   public pause_success(){
      set_cvar_num("pausable",pausable)
      server_print("[AMX] Server %s", paused ? "unpaused" : "paused")
      paused = (paused) ? 0 : 1
      return PLUGIN_HANDLED
   }
   pause_server(id){
      pausable = get_cvar_num("pausable")
      if (!id)
        id = find_player("h")
      if (id){
         set_cvar_num("pausable",1)
         client_cmd(id,"pause;pause_loopback")
      }
      else
         server_print("[AMX]  Server  was  unable to pause the game. Real
   players on server are needed.")
   }
   public round_start(){
   if (setpause == 1)
   {
      removepause = 1
      pause_server(0)
   }
   return PLUGIN_CONTINUE
   }
   public client_disconnect(id){
      if           (get_cvar_num("match_pause_on_disconnect")          &&
   ((match_inprogress==2) || (match_inprogress==4)) )
      {
         setpause=1
      }
      p_info[id][0] = 0
      p_info[id][1] = 0
      p_info[id][2] = 0
      p_info[id][3] = 0
      p_info[id][4] = 0
      return PLUGIN_CONTINUE
   }
   public client_putinserver(id){
     if (removepause == 1 )
     {
     pause_server(0)
     removepause=0
     }
     setpause=0
     return PLUGIN_CONTINUE
   }
   public match_hltv_init(id,level,cid){
      if (address_hltv != -1){
         console_print(id,"* Already initialized HLTV")
         return PLUGIN_HANDLED
      }
      new name[32], address[32], ip[32]
      // get string to look for in name which will be hltv's name
      get_cvar_string("match_hltv_name",name,31)
      // get the id of the hltv server based on the name
      new hltvid = find_player("lb", name)
      if (hltvid) {
         get_user_ip(hltvid,ip,31)
         new pos = copyc(address,31,ip,':') + 1
         console_print(id,"* Found HLTV (%s:%s)",address,ip[pos])
         address_hltv = set_iaddress(address,strtonum(ip[pos]))
         new hltvpassword[32]
         get_cvar_string("match_hltv_proxypassword",hltvpassword,31)
         console_print(id,"* Challenged the access with success")
      }
      return PLUGIN_HANDLED
   }
   public match_hltv_rec(id,level,cid){

       if (address_hltv==-1)
       match_hltv_init(id,level,cid)

       new rcv[256],snd[256]
       new rconid[13]
       new pass[64]
       get_cvar_string("amx_hltv_proxypassword",pass,63)
       new demoname[256],curmap[32],time_date[32]
       get_mapname(curmap,32)
       get_time("%Y.%m.%d-%H.%M.%S",time_date,32)
       format(demoname,256,"%s_vs_%s_%s_hltv_%s.dem",Team1,Team2,curmap,t
   ime_date)
     // Remove bad strings before recording
       while(replace(demoname,256,"/","-")) {}
       while(replace(demoname,256,"\","-")) {}
       while(replace(demoname,256,":","-")) {}
       while(replace(demoname,256,"*","-")) {}
       while(replace(demoname,256,"?","-")) {}
       while(replace(demoname,256,">","-")) {}
       while(replace(demoname,256,"<","-")) {}
       while(replace(demoname,256,"|","-")) {}
       setc(snd,4,0xff)
       copy(snd[4],255,"challenge rcon")
       setc(snd[18],1,'^n')
       query_udp_msg(address_hltv,rcv,255,snd)
       copy(rconid,12,rcv[15])
       replace(rconid,255,"^n","")
       setc(snd,4,0xff)
       format(snd[4],255,"rcon %s ^"%s^" record
   %s^n",rconid,pass,demoname)
       send_udp_msg(address_hltv,snd)
       console_print(id,"* Started recording to %s",demoname)
       return PLUGIN_HANDLED
   }
   public match_hltv_stop(id,level,cid){

       new rcv[256],snd[256]
       new rconid[13]
       new pass[64]
       get_cvar_string("amx_hltv_proxypassword",pass,63)
       if (address_hltv==-1)
       match_hltv_init(id,level,cid)
       setc(snd,4,0xff)
       copy(snd[4],255,"challenge rcon")
       setc(snd[18],1,'^n')
       query_udp_msg(address_hltv,rcv,255,snd)
       copy(rconid,12,rcv[15])
       replace(rconid,255,"^n","")
       setc(snd,4,0xff)
       format(snd[4],255,"rcon %s ^"%s^" stoprecord ^n",rconid,pass)
       send_udp_msg(address_hltv,snd)
       console_print(id,"* Stoped recording")
       return PLUGIN_HANDLED
   }
   public swap()
   {
      new playersCT[32]
      new playersT[32]
      new nbrCT,nbrT
      get_players(playersCT,nbrCT,"e","CT")
      get_players(playersT,nbrT,"e","TERRORIST")
      for(new i = 0; i < nbrCT; i++) {
            engclient_cmd(playersCT[i], "chooseteam")
            engclient_cmd(playersCT[i], "menuselect", "1")
            engclient_cmd(playersCT[i], "menuselect", "2")
      }
      for(new i = 0; i < nbrT; i++) {
            engclient_cmd(playersT[i], "chooseteam")
            engclient_cmd(playersT[i], "menuselect", "2")
            engclient_cmd(playersT[i], "menuselect", "4")
      }

      return PLUGIN_CONTINUE
   }
   public swap_teams()
   {
      client_print(0,print_chat,"* [AMX] Switching teams!...")
      set_cvar_string("mp_limitteams","0")
      set_cvar_string("mp_autoteambalance","0")
      restart_round("1")
      set_task(2.0,"swap")
      return PLUGIN_CONTINUE
   }
   public restart_round(time[])
   {
      server_cmd("sv_restartround %s",time)
      return PLUGIN_CONTINUE
   }
   public voice_enable(time[])
   {
      server_cmd("sv_voiceenable %s",time)
      return PLUGIN_CONTINUE
   }
   public rec_demos()
   {
      new players[32],playername[32],playerteam[16]
      new demoname[256],curmap[32],time_date[32]
      new nbr,i
      get_mapname(curmap,32)
      get_time("%Y.%m.%d-%H.%M.%S",time_date,32)
      get_players(players,nbr)
      for(i=0; i<nbr; i++) {
         get_user_team(players[i],playerteam,15)
         if (equal(playerteam,"CT")) {
            get_user_name(players[i],playername,32)

            if (t1[0]==2)
               format(demoname,256,"%s(CT)_%s(T)_%s_ineyes_%s_%s.dem",Tea
   m1,Team2,curmap,playername,time_date)
            else
               format(demoname,256,"%s(CT)_%s(T)_%s_ineyes_%s_%s.dem",Tea
   m2,Team1,curmap,playername,time_date)
         }
         else {
            if (equal(playerteam,"TERRORIST")) {
                  get_user_name(players[i],playername,32)

                  if (t1[0]==1)
                     format(demoname,256,"%s(T)_%s(CT)_%s_ineyes_%s_%s.de
   m",Team1,Team2,curmap,playername,time_date)
                  else
                     format(demoname,256,"%s(T)_%s(CT)_%s_ineyes_%s_%s.de
   m",Team2,Team1,curmap,playername,time_date)

         }
       }
         // Remove bad strings before recording
         while(replace(demoname,256,"/","-")) {}
         while(replace(demoname,256,"","-")) {}
         while(replace(demoname,256,":","-")) {}
         while(replace(demoname,256,"*","-")) {}
         while(replace(demoname,256,"?","-")) {}
         while(replace(demoname,256,">","-")) {}
         while(replace(demoname,256,"<","-")) {}
         while(replace(demoname,256,"|","-")) {}
         if ((equal(playerteam,"CT"))||(equal(playerteam,"TERRORIST"))) {
            client_cmd(players[i],"record ^"%s^"",demoname)
            client_print(players[i],print_chat,"* [AMX MATCH] Recording a
   demo on your PC: %s",demoname)
         }
      }
      return PLUGIN_CONTINUE
   }
   public stop_demo()
   {
      client_cmd(0,"stop")
      client_print(0,print_chat,"*  [AMX  MATCH]  Stopped  recording  the
   demo.")
      return PLUGIN_CONTINUE
   }
   public screenshot()
   {
      client_cmd(0,"snapshot")
      return PLUGIN_CONTINUE
   }
   public remove_scoreboard()
   {
      client_cmd(0,"-showscores")
      return PLUGIN_CONTINUE
   }
   public take_screenshot()
   {
      client_cmd(0,"+showscores")
      client_print(0,print_chat,"*  [AMX  MATCH]  Taking  a screenshot...
   Smile!")
      set_task(1.0,"screenshot")
      set_task(5.0,"remove_scoreboard")
      return PLUGIN_CONTINUE
   }
   public start_match(id,level,cid)
   {
      new command[16]
      new playersCT[32]
      new playersT[32]
      new nbrCT,nbrT
      read_argv(0,command,15)
      if (equal(command,"amx_match"))
         cmdtype = 1
      else
         cmdtype = 2
      if (cmdtype == 1) {
         if (!cmd_access(id,level,cid,5)) {
            return PLUGIN_HANDLED
         }
      }
      else {
         if (!cmd_access(id,level,cid,3)) {
            return PLUGIN_HANDLED
         }
      }
      if (match_inprogress == 0) {
         //check config file
         if (cmdtype == 1)
            read_argv(4,cfgfile,31)
         else
            read_argv(2,cfgfile,31)
         new cfgfile2[64]
         format(cfgfile2,63,"addons/amx/plugins/leagues/%s.cfg",cfgfile)
         if (!file_exists(cfgfile2)) {
            console_print(id,"[AMX   MATCH]  These  config  file  doesn't
   exist.")
            if (file_exists("addons/amx/plugins/leagues/cfglist.txt")) {
               new line = 0, txtsize = 0
               console_print(id,"[AMX   MATCH]   Here   is  the  list  of
   available config files:")
               while((line=read_file("addons/amx/plugins/leagues/cfglist.
   txt",line,cfgfile2,192,txtsize))!=0)
                  console_print(id,"[AMX MATCH]   %s",cfgfile2)
            }
            return PLUGIN_HANDLED
         }
         // check type of match
         new checktype[32]
         if (cmdtype == 1)
            read_argv(3,checktype,31)
         else
            read_argv(1,checktype,31)
         if (equali(checktype,"mr",2))
            matchtype1 = 1
         else {
            if (equali(checktype,"tl",2))
               matchtype1 = 2
         }
         new i,length
         length=strlen(checktype)
         for(i=0;i<(length-2);i++)
            checktype[i] = checktype[i+2]
         checktype[i]= 0
         if (!( matchtype1 && str_to_num(checktype) )) {
            console_print(id,"[AMX   MATCH]  That  type  of  match  isn't
   supported  :/^n[AMX  MATCH] Type supported is maxround: mrXX (mr12 for
   exemple) or timelimit: tlXX (tl30 for exemple).")
            return PLUGIN_HANDLED
         }
         // starting the match
         if (get_cvar_num("match_kniferound"))
         {
            match_inprogress = 5
         }
         else{
            match_inprogress = 1
         }

         read_argv(1,Team1,31)
         read_argv(2,Team2,31)
         server_cmd("hostname  ^"%s vs %s^"    ",Team1,Team2)

         t1[0]=1
         t2[0]=2

         new demo[8]

         read_argv(5,demo,7)

         if (equal(demo,"recdemo"))
            recdemo = 1
         else if (equal(demo,"rechltv"))
            recdemo = 2
         matchtype2 = str_to_num(checktype)
         set_hudmessage(0,  200,  200, -1.0, 0.32, 0, 2.0, 6.0, 0.8, 0.8,
   2)
         new hudmsg[1024]
         new buffor[512]
         format(hudmsg,1024,"--[ Match Loaded: %s vs %s ]--^n^nMatch type
   is ",Team1,Team2)

         if (matchtype1 == 1)
            add(hudmsg,1023,"MaxRound ")
         else
            add(hudmsg,1023,"TimeLimit ")
         format(buffor,511,"%i (%s config)^n",matchtype2,cfgfile)
         if (recdemo ==1)
            add(buffor,511,"Demos will be automaticaly recorded.^n^n")
         if (recdemo ==2)
            add(buffor,511,"HLTV     Demo     will     be    automaticaly
   recorded.^n^n")
         add(buffor,511,"Entering warmup session...")
         add(hudmsg,1023,buffor)
         show_hudmessage(0,hudmsg)
         // log
         new name[32],authid[16], userid
         get_user_name(id,name,31)
         get_user_authid(id,authid,15)
         userid = get_user_userid(id)
         format(hudmsg,1023,"%s vs %s. Matchtype: ",Team1,Team2)

         if (matchtype1 == 1)
            add(hudmsg,1023,"mr")
         else
            add(hudmsg,1023,"tl")
         format(buffor,511,"%i.   Config   file:  %s.cfg.  Record  demos:
   %i",matchtype2,cfgfile,recdemo)
         add(hudmsg,1023,buffor)
         log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"  started  a
   match ^"%s^"",name,userid,authid,hudmsg)
         get_players(playersCT,nbrCT,"e","CT")
         get_players(playersT,nbrT,"e","TERRORIST")
         for(new j = 0; j < nbrCT; j++) {
            engclient_cmd(playersCT[j], "chooseteam")
         }
         for(new k = 0; k < nbrT; k++) {
            engclient_cmd(playersT[k], "chooseteam")
         }
         start_warmup()
      }
      else
         console_print(id,"[AMX MATCH] Match already in progress.")
      return PLUGIN_CONTINUE
   }
   public stop_match(id,level)
   {
      if (!access(id,level)) {
         console_print(id,"[AMX] You have not access to that command.")
         return PLUGIN_HANDLED
      }
      if (match_inprogress > 0){
         new num
         new players[32]
         set_hudmessage(200, 0, 0, -1.0, 0.32, 0, 2.0, 6.0, 0.8, 0.8, 2)
         show_hudmessage(0,"--[  The  match has been stopped ]--^n^nLet's
   go back to FFA ;-)")
         server_print("[AMX MATCH] Match stopped.")
         client_print(0,print_chat,"*  [AMX  MATCH]  Executing FFA config
   file (ffa.cfg)")
         server_cmd("exec ^"addons/amx/plugins/leagues/ffa.cfg^"")
         if (recdemo == 1)
            set_task(1.0,"stop_demo")
         if (recdemo == 2)
            set_task(1.0,"match_hltv_stop")
         match_inprogress = 0
         Team1[0] = 0
         Team2[0] = 0
         cfgfile[0] = 0
         matchtype1 = 0
         matchtype2 = 0

         t1[1]=0
         t1[2]=0
         t2[1]=0
         t2[2]=0
         remove_task(1337)

         new name[32],authid[16], userid
         get_user_name(id,name,31)
         get_user_authid(id,authid,15)
         userid = get_user_userid(id)
         log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"  stopped  a
   match",name,userid,authid)

         if (recdemo == 2) {
           set_task(20.0,"match_hltv_stop")
         }
         recdemo = 0
         get_players(players,num)
         for(new i = 0; i < num; ++i)
         {
          p_info[players[i]][0]=0
         }
      }
      else
         console_print(id,"[AMX MATCH] There's no match to stop.")
      return PLUGIN_CONTINUE
   }
   public back_to_ffa()
   {
      new num
      new players[32]
      match_inprogress = 0
      Team1[0] = 0
      Team2[0] = 0
      cfgfile[0] = 0
      matchtype1 = 0
      matchtype2 = 0

      t1[1]=0
      t1[2]=0
      t2[1]=0
      t2[2]=0
      restart_round("8")
      client_print(0,print_chat,"*  [AMX MATCH] Executing FFA config file
   (ffa.cfg)")
      server_cmd("exec ^"addons/amx/plugins/leagues/ffa.cfg^"")
      if (recdemo == 2) {
            set_task(2.0,"match_hltv_stop")

      }
      recdemo = 0
      get_players(players,num)
      for(new i = 0; i < num; ++i)
        {
        p_info[players[i]][0]=0
        }
      return PLUGIN_CONTINUE
   }
   public warmup_msg()
   {
      if ((match_inprogress == 1)||(match_inprogress == 3)) {
         set_hudmessage(200,  200,  200,  -1.0,  0.02, 0, 2.0, 10.0, 0.8,
   0.8, 1)

         if (recdemo == 1)
            show_hudmessage(0,"--[    Warmup    Time   ]--^n^nDemos   are
   automatically  recorded  on  your  PC^nNo  need to record yourself (If
   you're not spectating...)^nScreenshots are also taken.")
         else if (recdemo == 2)
            show_hudmessage(0,"--[   Warmup   Time  ]--^n^nHLTV  demo  is
   automatically  recorded  ^nNo  need  to record yourself (If you're not
   spectating...)^nScreenshots are also taken.")
         else
            show_hudmessage(0,"--[  Warmup  Time  ]--^n^nScreenshots  are
   taken.^nPlease remember to record demos ;-)")
         client_print(0,print_chat,"* [AMX MATCH] Warmup Time...")
         client_print(0,print_chat,"*  [AMX MATCH] When you are is ready:
   say ready")
         set_task(30.0,"warmup_msg")
      }
      return PLUGIN_CONTINUE
   }
   public start_warmup()
   {
      restart_round("8")
      client_print(0,print_chat,"*  [AMX  MATCH]  Executing  match config
   file (%s.cfg + default.cfg)",cfgfile)
      server_cmd("exec ^"addons/amx/plugins/leagues/%s.cfg^"",cfgfile)
      server_cmd("exec ^"addons/amx/plugins/leagues/default.cfg^"")
      if (matchtype1 == 2) {
         new currentmap[64]
         get_mapname(currentmap,63)
         set_cvar_string("amx_nextmap",currentmap)
      }
      server_cmd("mp_timelimit ^"0^"")
      server_cmd("mp_winlimit ^"0^"")
      server_cmd("mp_maxrounds ^"0^"")
      server_cmd("mp_limitteams ^"0^"")
      server_cmd("mp_autoteambalance ^"0^"")
      set_task(10.0,"warmup_msg")
      return PLUGIN_CONTINUE
   }
   public live_msg()
   {

      set_hudmessage(0, 200, 200, -1.0, 0.32, 0, 2.0, 6.0, 0.8, 0.8, 2)
      show_hudmessage(0,"--[  LIVE  !!! GL & HF ]--^n--[ LIVE !!! GL & HF
   ]--^n--[ LIVE !!! GL & HF ]--")
      client_print(0,print_chat,"* [AMX MATCH] LIVE LIVE LIVE  !!!")
      client_print(0,print_chat,"* [AMX MATCH] LIVE LIVE LIVE  !!!")
      client_print(0,print_chat,"* [AMX MATCH] LIVE LIVE LIVE  !!!")
      return PLUGIN_CONTINUE
   }
   public start_half()
   {
   new num
   new players[32]
   get_players(players,num)
   for(new i = 0; i < num; ++i)
   {
       p_info[players[i]][1]=0

   }
   if (matchtype1 == 1)
         server_cmd("mp_maxrounds ^"%i^"",matchtype2+2)
   else
         server_cmd("mp_timelimit ^"%i^"",matchtype2)
   if (match_inprogress == 2) {
            t1[1]=0
            t2[1]=0
            if (recdemo == 1) {
             server_cmd("sv_voiceenable 0")
             set_task(2.0,"rec_demos")
             set_task(4.0,"voice_enable",0,"1",1)
            }
            if (recdemo == 2) {
             set_task(2.0,"match_hltv_rec")
            }
            client_print(0,print_chat,"* [AMX MATCH] 1st Half starting")
            client_print(0,print_chat,"*  [AMX  MATCH] GOING LIVE !!! GET
   READY !!!")
            client_print(0,print_chat,"*  [AMX  MATCH] GOING LIVE !!! GET
   READY !!!")
   }
      else if (match_inprogress == 4){

            if (recdemo == 1) {
             server_cmd("sv_voiceenable 0")
             set_task(2.0,"rec_demos")
             set_task(4.0,"voice_enable",0,"1",1)
            }
            else if (recdemo == 2) {
             set_task(2.0,"match_hltv_rec")
            }
            client_print(0,print_chat,"* [AMX MATCH] 2nd Half starting")
            client_print(0,print_chat,"*  [AMX  MATCH] GOING LIVE !!! GET
   READY !!!")
            client_print(0,print_chat,"*  [AMX  MATCH] GOING LIVE !!! GET
   READY !!!")
      }
      else if (match_inprogress == 6){
         client_print(0,print_chat,"* Kniferound starting")
         unpause("b","switchweapon")
         client_print(0,print_chat,"* Kniferound !!! GET READY !!!")
         client_print(0,print_chat,"* Kniferound !!! GET READY !!!")
      }

   set_task(2.0,"restart_round",0,"1",1)
   set_task(4.0,"restart_round",0,"1",1)
   set_task(6.0,"restart_round",0,"3",1)
   set_task(11.0,"live_msg")
   return PLUGIN_CONTINUE
   }
   public check_ready(id)
   {
   // set ready or not ready by player
   if     ((match_inprogress     ==     1)||(match_inprogress    ==    3)
   ||(match_inprogress == 5)) {
       new team1ready,team2ready
       new num
       new playersnum
       new players[32]
       new name[32]
       team1ready=0
       team2ready=0

       if(p_info[id][1] == 0){
            p_info[id][1]=1
       }
       else if(p_info[id][1] == 1){
            p_info[id][1]=0
       }
       get_players(players,num)
       for(new i = 0; i < num; ++i)
       {
        if (p_info[players[i]][0]==1 && p_info[players[i]][1]==1)
           {
           team1ready=team1ready+1
           }
        else if (p_info[players[i]][0]==2 && p_info[players[i]][1]==1)
           {

           team2ready=team2ready+1
           }

        }
       playersnum = get_cvar_num("match_num_tobe_ready")
       if ((team1ready == playersnum) && (team2ready == playersnum)) { //
   Both are now ready
               set_hudmessage(200,  0,  0,  -1.0, 0.32, 0, 2.0, 6.0, 0.8,
   0.8, 3)

               show_hudmessage(0,"--[ BOTH TEAMS ARE READY !!! ]--^n^nThe
   match   between   %s   and   %s  can  now  begin  :)^n3  restarts  and
   GO!",Team1,Team2)

               match_inprogress++
               set_task(5.0,"start_half",1337)
         }
         else   if   ((team2ready   <   playersnum)   &&  (team1ready  ==
   playersnum)) { // team1 are ready
               set_hudmessage(0,  200, 200, -1.0, 0.35, 1, 2.0, 6.0, 0.8,
   0.8, 3)
               show_hudmessage(0,"--[%s    %i/%i   ready   :   %s   %i/%i
   ready]--^n^n--[   %s   are   now  ready  ]--^nWaiting  for  %s  to  be
   ready",Team1,team1ready,playersnum,Team2,team2ready,playersnum,Team1,T
   eam2)
         }

         else   if   ((team2ready   ==   playersnum)   &&  (team1ready  <
   playersnum)) { // team2 are now ready
                set_hudmessage(0, 200, 200, -1.0, 0.35, 1, 2.0, 6.0, 0.8,
   0.8, 3)
                show_hudmessage(0,"--[%s   %i/%i   ready   :   %s   %i/%i
   ready]--^n^n--[   %s   are   now  ready  ]--^nWaiting  for  %s  to  be
   ready",Team1,team1ready,playersnum,Team2,team2ready,playersnum,Team2,T
   eam1)
         }
         else {
                set_hudmessage(0, 200, 200, -1.0, 0.35, 1, 2.0, 6.0, 0.8,
   0.8, 3)
                show_hudmessage(0,"--[%s   %i/%i   ready   :   %s   %i/%i
   ready]--",Team1,team1ready,playersnum,Team2,team2ready,playersnum)
         }

       get_user_name(id,name,32);
       if (p_info[id][1]==1){
       client_print(0,print_chat,"* [AMX MATCH] %s is ready.",name)
     }
       else
       {
        client_print(0,print_chat,"* [AMX MATCH] %s is unready.",name)
       }

     }
      else {
         if     ((match_inprogress     ==     2)||(match_inprogress    ==
   4)||(match_inprogress == 6))
            client_print(id,print_chat,"*   [AMX  MATCH]  The  match  has
   already started! O_o")
      }
   return PLUGIN_CONTINUE
   }
   public new_score()
   {
   //counting score for kniferound & 1st half
      if    (    (matchtype1    ==    1)    &&    ((match_inprogress   ==
   2)||(match_inprogress == 6)) ) {
         new team[32]
         read_data(1,team,32)
         if (equal(team,"CT"))
         {
               if(t1[0]==2)
                {
                  t1[1] = read_data(2)
                }
               else if(t2[0]==2)
                {
                  t2[1] = read_data(2)
                }
         }
         else
         {
            if (equal(team,"TERRORIST"))
            {
               if(t1[0]==1)
                {
                  t1[1] = read_data(2)
                }
               else if(t2[0]==1)
                {
                  t2[1] = read_data(2)
                }
            }
         }
     }
   //counting score for  2eme half
      if ( (matchtype1 == 1) && (match_inprogress == 4) ) {
         new team[32]
         read_data(1,team,32)
         if (equal(team,"CT"))
         {
               if(t1[0]==2)
                {
                  t1[2] = read_data(2)
                }
               else if(t2[0]==2)
                {
                  t2[2] = read_data(2)
                }
         }
         else
         {
            if (equal(team,"TERRORIST"))
            {
               if(t1[0]==1)
                {
                  t1[2] = read_data(2)
                }
               else if(t2[0]==1)
                {
                  t2[2] = read_data(2)
                }
            }
         }
     }
   // end 1st half
      if  (  (match_inprogress == 2) && ((t1[1] + t2[1]) == matchtype2) )
   {
            new hudmsg[512]
            format(hudmsg,511,"--[  1st Half Finished ]--^n^nScore is: %s
   %i   /   %i   %s^nWe  are  going  back  in  warmup.^n^nTeams  Will  be
   Swapped",Team1,t1[1],t2[1],Team2)
            set_hudmessage(200,  200, 200, -1.0, 0.32, 0, 2.0, 15.0, 0.8,
   0.8, 4)
            show_hudmessage(0,hudmsg)
            match_inprogress = 3
            if(t1[0]==1){
               t1[0]=2
               t2[0]=1
            }
            else if (t1[0]==2){
               t1[0]=1
               t2[0]=2
            }
            set_task(5.0,"swap_teams")

            take_screenshot()
            set_task(2.0,"start_warmup")

            if (recdemo == 1)
               set_task(3.0,"stop_demo")
            if (recdemo == 2)
               set_task(3.0,"match_hltv_stop")
         }
   // kniferound
      if (  (match_inprogress == 6) && ((t1[1] == 1) || (t2[1] == 1) )) {

           new hudmsg[512]
           if (t1[1] > t2[1])
               {
                 format(hudmsg,511,"--[  Kniferound  Finished  ]--^n^n %s
   Wins ^nWe are going back in warmup.",Team1)
               }
            else {
               format(hudmsg,511,"--[ Kniferound Finished ]--^n^n %s Wins
   ^nWe are going back in warmup.",Team2)
            }
           set_hudmessage(200,  200,  200,  -1.0, 0.32, 0, 2.0, 8.0, 0.8,
   0.8, 4)
           show_hudmessage(0,hudmsg)
           match_inprogress = 1
           pause("b","switchweapon")
           set_task(2.0,"vote_swapteam")

          }

   //end match
         else {
            if (match_inprogress == 4) { // Playing 2nd half
               if  (  ((t1[2]  + t2[2]) == matchtype2) ) { // 2nd half is
   finished
                  new hudmsg[1024], buffor[512]
                  format(hudmsg,1023,"--[  Match  Finished ]--^n^nAnd the
   winner of the map is...^n")
                  new team1score
                  new team2score
                  team1score = t1[1]+t1[2]
                  team2score = t2[1]+t2[2]
                  if (team1score > team2score) {

                        format(buffor,511,"%s    with    the   score   of
   %i/%i",Team1,team1score,team2score)

                  }
                  else if (team2score > team1score) {
                        format(buffor,511,"%s    with    the   score   of
   %i/%i",Team2,team2score,team1score)
                  }
                  else if (team2score == team1score)
                  {
                        format(buffor,511,"Equality : %s : %i  -  %i : %s
   ",Team1,team1score,team2score,Team2)
                  }

                  add(hudmsg,1023,buffor)
                  set_hudmessage(200, 200, 200, -1.0, 0.32, 0, 2.0, 20.0,
   0.8, 0.8, 4)
                  show_hudmessage(0,hudmsg)
                  match_inprogress = 0
                  take_screenshot()
                  if (recdemo == 1)
                     set_task(3.0,"stop_demo")
                  if (recdemo == 2)
                     set_task(3.0,"match_hltv_stop")
                  set_task(20.0,"back_to_ffa")
              }

          }
      }
      return PLUGIN_CONTINUE
   }
   public plugin_init()
   {
      register_plugin("AMX Match Super Deluxe","1.51","SPiRiT")
      register_concmd("amx_match","start_match",ADMIN_LEVEL_A,"<CT's clan
   tag> <T's clan tag> <mrXX or clXX> <Config filename> [recdemo]")
      register_concmd("amx_matchstop","stop_match",ADMIN_LEVEL_A,"-  Stop
   a match")
      register_concmd("amx_swapteams","swap_teams",ADMIN_LEVEL_A,"-  Swap
   teams")
      register_clcmd("say ready","check_ready")
      register_menucmd(register_menuid("SWAP
   TEAMS?"),(1<<0)|(1<<1),"vote_count")
      register_menucmd(register_menuid("ySelect
   Team:"),(1<<0)|(1<<1)|(1<<2),"set_team")
      register_event("ShowMenu","auto_join","b","4&Team_Select")       /*
   Team_Select - this is from cstrike/titles.txt */
      register_event("VGUIMenu","auto_join","b","1=2","1=26","1=27")
      register_event("TeamScore","new_score","a")
      register_event("ResetHUD", "round_start", "be")
      register_event("CurWeapon","switchweapon","be","1=1","2!29")
      register_cvar("amx_match_deluxe", "1.20",FCVAR_SERVER)
      register_cvar("match_hltv_proxypassword","hltvproxypassword")
      register_cvar("match_hltv_name","HLTV")
      register_cvar("match_pause_on_disconnect","0")
      register_cvar("match_kniferound","0")
      register_cvar("match_vote_time","10")
      register_cvar("match_vote_answers","1")
      register_cvar("match_last_voting","0")

      register_cvar("match_num_tobe_ready","5")

      set_cvar_float("match_last_voting",0.0)
      pause("b","switchweapon")
      return PLUGIN_CONTINUE
   }
