
   /* AMX Mod script.
   *
   * (c) Copyright 2002-2003, OLO
   * This file is provided as is (no warranties).
   *
   * Mapcycle immune to manual map changes and map votes.
   *
   * Cvars:
   * amx_nextmap < mapname > - sets nextmap
   *
   * Commands:
   * say nextmap - dispalys the nextmap (available for all clients)
   */
   #include <amxmod>
   new g_NextMap[64]
   new g_MapCycle[64]
   new g_currentPost
   public plugin_init() {
       register_plugin("NextMap II","0.9.4","default")
       register_event( "30" , "forceMap", "a" )
       register_clcmd("say nextmap","sayNextMap",0,"- displays nextmap")
       register_cvar("amx_nextmap","",FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPO
   NLY)
       findNextmap()
       return PLUGIN_CONTINUE
   }
   getNextMap(szArg[],iMax){
       get_cvar_string("amx_nextmap",szArg,iMax)
       if ( is_map_valid(szArg) ) return
       copy(szArg,iMax,g_NextMap)
       set_cvar_string("amx_nextmap",g_NextMap)
   }
   public delayedSayInfo(text[])
       client_print(0,print_chat,text)
   public sayNextMap(){
       new szArg[96]
       getNextMap(szArg,63)
       new iLen = format(szArg,95,"* The next map:   %s",szArg)
       set_task(0.1,"delayedSayInfo",0,szArg,  iLen + 1 )
       return PLUGIN_CONTINUE
   }
   public delayedMapChange() {
       new szArg[64]
       getNextMap(szArg, 63)
       server_cmd("changelevel %s",szArg)
   }
   public forceMap(){
       new szString[128]
       format( szString , 127, "%s %d", g_MapCycle , g_currentPost  )
       set_localinfo( "lastmapcycle", szString )
       set_cvar_float("mp_chattime", 1.9 )
       set_task(1.8,"delayedMapChange")
   }
   isAlpha(c)
       return ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) )
   readMapCycle(szFileName[], szNext[], iNext, iPos )
   {
       new iLen
       new i = 0
       new iMaps = 0
       new szBuffor[64]
       new szFirst[64]

       while( read_file( szFileName , i++ , szBuffor , 63 , iLen ) )
       {
           if  (  !isAlpha(  szBuffor[0] ) || !is_map_valid( szBuffor ) )
   continue

           if ( !iMaps )    copy( szFirst, 63, szBuffor )
           if ( ++iMaps > iPos )    {
               copy( szNext , iNext , szBuffor  )
               return iMaps
           }
       }

       if ( !iMaps ) get_mapname( szFirst , 63 )

       copy( szNext , iNext , szFirst  )
       return iPos ? 1 : 0
   }
   findNextmap() {
       new szString[128], szString2[64], szString3[8]
       get_localinfo( "lastmapcycle", szString , 127 )
       parse( szString, szString2, 63, szString3 , 7 )
       g_currentPost = strtonum( szString3 )
       get_cvar_string( "mapcyclefile" , g_MapCycle , 63 )

       if ( !equal( g_MapCycle ,  szString2  )  )
           g_currentPost  = 0 // mapcycle file has been changed - go from
   first

       g_currentPost  =  readMapCycle(  g_MapCycle  ,  g_NextMap  ,  63 ,
   g_currentPost )
       set_cvar_string( "amx_nextmap", g_NextMap )
   }
