
   /* AMX Mod script.
   *
   * (c) Copyright 2003, OLO
   * This file is provided as is (no warranties).
   *
   */
   #include <amxmod>
   #include <amxmisc>
   new maskname[32]
   new masklen
   new maskmode
   public plugin_init()
   {
       register_plugin("Mapcycle Generator","0.1","default")
       register_concmd("amx_genmapcycle","mapCycleGen",ADMIN_RCON,"<filen
   ame> <mask> or <map> [map] ... - generates mapcycle")
       return PLUGIN_CONTINUE
   }
   /*
   *  0 - *foo*
   *  1 - foo*
   *  2 - *foo
   *  3 - none
   */
   set_maskfile(text[])
   {
       new len = strlen(text)
       maskmode = 0
       if ( text[0] == '*' )    {
           if ( !text[1] ) return maskmode = 4
           copyc(maskname,31,text[1],'*')
           maskmode |= 1
       }
       else
           copyc(maskname,31,text,'*')
       masklen = strlen(maskname)
       if ( text[len-1] == '*' )
           maskmode |= 2
       return maskmode = ((maskmode & 3) ^ 3)
   }
   bool:match_maskfile(text[])
   {
       switch(maskmode) {
           case 4: return true // *
           //case 3: return equali(text,maskname) ? true : false // none
           case 1: return equali(text,maskname,masklen) ? true : false //
   foo*
           case  0:  return  (contain(  text , maskname ) != -1) ? true :
   false // *foo*
       }
       new a = strlen(text) - masklen // *foo
       if ( a < 0 ) return false
       return equali(text[a],maskname) ? true : false
   }
   public mapCycleGen(id,level,cid)
   {
       if (!cmd_access(id,level,cid,3))
           return PLUGIN_HANDLED

       new szFilename[32], szMask[32], szLine[256]
       read_argv(1,szFilename,31)

       if ( file_exists( szFilename ) )
       {
           delete_file(  szFilename )
       }

       get_user_name(id,szMask,31)

       format( szLine,255,"// Map cycle generated by %s^n// with Mapcycle
   Generator Plugin^n", szMask)

       if ( write_file( szFilename, szLine ) == 0 )
       {
           console_print(id, "Couldn't write to ^"%s^" file!", szFilename
   )

           return PLUGIN_HANDLED
       }

       read_argv(2,szMask,31)

       new len, mapsnum = 0, pos = 0

       if ( set_maskfile(szMask) == 3 )
       {
           new argc = read_argc()

           for(new a = 2; a < argc; ++a)
           {
               read_argv(a,szLine,31)

               if ( is_map_valid(  szLine  ) )
               {
                   write_file( szFilename , szLine )
                   mapsnum++
               }

           }

       }
       else
       {
           while ( read_dir( "maps" ,pos++ ,szLine,255,len) )
           {
               len -= 4
               if (len > 0)
               {
                   if ( !equali( szLine[len] , ".bsp" ) )
                       continue // skip non map files
                   szLine[len] = 0 // remove .bsp
               }
               if  ( is_map_valid(  szLine  ) && match_maskfile( szLine )
   )
               {
                   write_file( szFilename , szLine )
                   mapsnum++
               }
           }
       }

       console_print(id,   "Generated  ^"%s^"  mapcycle  with  %d  maps",
   szFilename, mapsnum )

       return PLUGIN_HANDLED
   }
