
   /*********************************************************************
   *******
   *  amx_ejl_searchmaps.sma      version  1.1               November 28,
   2002
   *   by Eric Lidman      ejlmozart@hotmail.com
   *   Upgrade: http://lidmanmusic.com/cs/plugins.html
   *
   *  Updated: For use with amx version 0.9.3 or higher only!
   *
   *  This  plugin  allows  users  to  search  thru  all the maps on your
   server.
   *   In  this  latest version you no longer need the tmaps.txt file you
   had if
   *   you  used  previous  versions. Instead the server searches through
   its maps
   *   folder and lists them from there. To cut down on the lag casued by
   file
   *   actions,  the maps are loaded into memory at the start of each map
   and
   *   searched from there while games are in progress. Thus if you add a
   map
   *   to  your  server, it wont show up in the search until you load the
   next
   *   map.
   *
   *  Commands:
   *
   *    mapsearch  <target>   returns up to 20 maps containing the search
   target
   *
   *  Maps  are  listed  in  the hud to the player who requests them. The
   command
   *   command  can  be  issued  from  the  chat mode as well as from the
   console.
   *
   **********************************************************************
   *****/
   #include <amxmod>
   new numword
   new T_LMaps[1000][32]
   public handle_say(id) {
       new Speech[192]
       read_args(Speech,192)
       remove_quotes(Speech)
       if(equal(Speech,"mapsearch",9)){
           search_engine(id,Speech[10])
       }
       return PLUGIN_CONTINUE
   }
   public admin_mapsearch(id) {
       new argx[32]
       read_argv(1,argx,32)
       search_engine(id,argx)
       return PLUGIN_HANDLED
   }
   search_engine(id,argx[]){
       new LMaps[20][32]
       new b
       for(new a = 0; a < numword; a++) {
           if (containi(T_LMaps[a],argx) != -1) {
               if(b < 20){
                   copy(LMaps[b], 32, T_LMaps[a])
                   replace(LMaps[b],32,".bsp","    ")
                   b++
               }
           }
       }
       new msg[800]
       if(b > 0){
           format(msg,800,"We    have    %d    maps.^nHere   are   search
   results,^nonly 1st 20
   shown:^n^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %
   s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %
   s^n   %s^n",numword, LMaps[0],LMaps[1],LMaps[2],LMaps[3],
           LMaps[4],LMaps[5],LMaps[6],LMaps[7],LMaps[8],LMaps[9],LMaps[10
   ],LMaps[11],LMaps[12],LMaps[13],LMaps[14],LMaps[15],
           LMaps[16],LMaps[17],LMaps[18],LMaps[19])
           set_hudmessage(10,100,150,  0.75,  0.10,  2, 0.02, 14.0, 0.01,
   0.1, 4)
           show_hudmessage(id,"%s",msg)
           client_print(id,print_chat,"[AMX]  Map   search  results:  See
   right side of screen.")
       }else{
           set_hudmessage(10,100,150,  0.75,  0.10,  2,  0.02, 9.0, 0.01,
   0.1, 4)
           show_hudmessage(id,"No  match  to your search,^nbut we have %d
   maps.^n^nUsage:^nmapsearch map",numword)
           client_print(id,print_chat,"[AMX]  Map   search  results:  See
   right side of screen.")
       }
       return PLUGIN_CONTINUE
   }
   public plugin_init() {
       register_plugin("Search Maps Plugin","0.9.3","EJL")
       register_clcmd("mapsearch","admin_mapsearch",ADMIN_USER,"mapsearch
   <target>: Lists available maps with target in their name")
       register_clcmd("say","handle_say")
       new data[32],temp
       for(new a=1 ; read_dir("maps",a,data,31,temp) ; a++) {
           if(contain(data,".bsp") != -1) {
               if(numword < 1000){
                   numword++
                   copy(T_LMaps[numword], 32, data)
               }else{
                   write_file("addons/amx/mapsearch_error.log", "You have
   exceeded 1000 maps. You need to make modifications to the plugin to do
   more.", -1)
               }
           }
       }
       return PLUGIN_CONTINUE
   }
