
   /*********************************************************************
   ******
   *  amx_ejl_mapcvars.sma
   *   version 2.1        Date: 12/31/2002
   *   Author: Eric Lidman     ejlmozart@hotmail.com
   *   Alias: Ludwig van       Upgrade:
   http://lidmanmusic.com/cs/plugins.html
   *
   *  Plugin  allows  you  set  server cvars that are particular to a map
   using a
   *   file in your ..addons/amx folder called map_cvars.txt. It also has
   an
   *   option  to set and lock cvars for all maps. Normally if you wanted
   a cvar
   *   set a certain way for all maps, you put it in the server.cfg. The
   *   difference  here is that you can lock out changes for that cvar if
   you
   *   choose.  NEW:  Now  you can pause and unpause plugins for specific
   maps
   *   by  using  this  plugin in basically the same way as you use it to
   set
   *   cvars. See below for setup info.
   *
   *
   *  Command:
   *
   *    amx_lockmapcvars  -- turns on and off the locking of cvars listed
   with
   *                         a  "1" in the map_cvars.txt. If no cvars are
   listed
   *                         this  command  has  no  effect. If cvars are
   listed
   *                         with a "1", then they are by default locked
   *                         unless  this command is issued. If they have
   a "0"
   *                         then  this command has no effect. ADMIN_RCON
   access
   *                         is required to use this command.
   *
   *  The  format  of the cvar file: M = map line   C = cvar line   0|1 =
   locked
   *   M  mapname
   *   C  lock0|1  cvar  value
   *
   *   Everytime you give a mapname, you must precced it with "Map". Then
   the
   *   line or lines below must start with "C" indicating you are setting
   a
   *   cvar.  After the "C", leave a space, then put a number "1" or "0".
   "1"
   *   locks  out  any  changes  from votes or by lower admins. Note that
   ADMIN_RCON
   *   level  admins  can  change this value in game for the remainder of
   the map
   *   time using amx_lockmapcvars. The values will not be changed in the
   file
   *   so  next  time this map is player, the value will be that which is
   in the
   *   file.  "0" allows for changes to take place. So a "0" will set the
   default
   *   for  map  start, but leaves the cvar soft and changeable by admins
   or by
   *   voting, a "1" will set the default for a map and keeps it that way
   unless
   *   an  RCON  leve admin changes it. You may have as many cvars as you
   want.
   *   Once  the  next line is "Map" or end of file, you are done setting
   cvars
   *   for that map. You may then continue to repeat the process for each
   map
   *   you  want  to  set special cvars for. Updated. If you want to lock
   cvars for
   *   all  maps,  make  the map name "*allmaps", then list your cvars as
   you would
   *   with  individual maps. All maps lock should be listed first in the
   file.
   *
   *  To  pause/unpause  plugins  for  maps:  M  =  map line   P = plugin
   line   U/P
   *   M  mapname
   *   P  ActionPause/Unpause=P|U    plugin_file_name
   *
   *  If  you  want to keep a plugin paused for most maps, but unpause it
   for one
   *   or  a few maps, pause the plugin using the "Map *allmaps" variable
   and
   *   make  sure  thats the first listing in your map_cvars.txt. Then to
   re-
   *   activate  the plugin for a particular map, ust the "U" variable to
   unpause
   *   the  plugin.  For  all  other  plugin  where you just want them to
   normally
   *   run,  but  for  a  few  maps  want them off, use the "P" variable.
   Remember to
   *   Preceed  the  plugin  line  with  a  "P",  so  to  pause, its "P P
   pluginname.amx"
   *   and  to  unpause  (provedied  you  set pause for all maps for this
   plugin) then
   *   its  "P  U  pluginname.amx".  I  hope  this  was clear enough. See
   example below:
   *
   *  Actual example of the contents of a working map_cvars.txt:
   *
   *   Map  *allmaps
   *   C 1  mp_hostagepenalty 0
   *   P P  amx_ejl_weather.amx
   *   Map  oc_bestjump3
   *   C 1  sv_gravity 1000
   *   P U  amx_ejl_weather.amx
   *   Map  starwars
   *   C 1  sv_gravity 100
   *   C 1  sv_airaccelerate -15
   *   C 1  mp_friendlyfire 0
   *   Map  de_dust
   *   P P  roll_the_dice.amx
   *   C 0  mp_friendlyfire 1
   *
   **********************************************************************
   ******/
   #include <amxmod>
   #include <amxmisc>
   new bool:cvar_lock = true
   new inum_cvars
   new locked_cvar[25][64]
   new locked_value[25][32]
   new locked_yn[25]
   new plugin_p
   new invalid
   public plugin_init() {
       register_plugin("MAP CVARs","2.1","EJL")
       register_concmd("amx_lockmapcvars","lock_unlock",ADMIN_RCON,"amx_l
   ockmapcvars : Locks/unlocks whatever cvars you set in map_cvars.txt")
       set_task(1.0,"set_map_cvars")
       set_task(5.1,"check_map_cvars",1721,"",0,"a", 9999)
       return PLUGIN_CONTINUE
   }
   public set_map_cvars(){
       new ThisMap[33]
       get_mapname(ThisMap, 33)
       new bool:map_on = false
       if(file_exists("addons/amx/map_cvars.txt") == 1){
           new line = 0
           new data[128]
           new stextsize = 0
           new type[4]
           new map_or_lock[32]
           new map_cvar[64]
           new value[32]
           log_message("[AMX][MAPCVARS]  Cvar exec / plugin pause-unpause
   begin")
           while((line=read_file("addons/amx/map_cvars.txt",line,data,128
   ,stextsize))!=0){
               parse(data,type,4,map_or_lock,32,map_cvar,64,value,32)
               if(equali(type,"M",1)){
                   if(map_on == true){
                       map_on = false
                   }
                   if(          (equali(map_or_lock,ThisMap))          ||
   (equali(map_or_lock,"*allmaps")) ){
                       map_on = true
                   }
               }
               else if(equali(type,"C",1)){
                   if(map_on == true){
                       copy(locked_cvar[inum_cvars],64,map_cvar)
                       copy(locked_value[inum_cvars],32,value)
                       if(equal(map_or_lock,"1"))
                           locked_yn[inum_cvars] = 1
                       if(cvar_exists(map_cvar)){
                           server_cmd("%s %s",map_cvar,value)
                           log_message("[AMX][MAPCVARS]     Executed:  %s
   %s",map_cvar,value)
                           inum_cvars +=1
                           if(inum_cvars >= 25){
                               map_on = false
                               log_message("[AMX][MAPCVARS]
   Warning:   Limit of 25 special cvars reached.")
                           }
                       }else{
                           invalid = 1
                           log_message("[AMX][MAPCVARS]   Warning:   Cvar
   ^"%s^" does not exist.", map_cvar)
                       }
                   }
               }
               else if(equali(type,"P",1)){
                   if(map_on == true){
                       if(equali(map_or_lock,"P",1))
                           do_pplugin(0,map_cvar)
                       else if(equali(map_or_lock,"U",1))
                           do_pplugin(1,map_cvar)
                   }
               }
           }
           if((inum_cvars < 1) && (plugin_p == 0)){
               if(invalid)
                   log_message("[AMX][MAPCVARS] map_cvars.txt contains no
   valid info for this map.")
               else
                   log_message("[AMX][MAPCVARS] map_cvars.txt contains no
   info for this map.")
           }
           log_message("[AMX][MAPCVARS]  Cvar exec / plugin pause-unpause
   end.")
       }else{
           write_file("addons/amx/map_cvars.txt","***  MAP CVAR FILE. SEE
   README.  EXAMPLE  BELOW:  M  mapname  ###  C  cvar   0|1  Lock  ###  P
   Plugin  P pause U unpause",-1)
           write_file("addons/amx/map_cvars.txt","Map oc_bestjump3",-1)
           write_file("addons/amx/map_cvars.txt","C 0 sv_gravity 800",-1)
       }
       return PLUGIN_HANDLED
   }
   public check_map_cvars(){
       if(cvar_lock == true){
           for(new i = 0 ;i < inum_cvars; ++i){
               new cvar[64]
               if(strlen(locked_cvar[i]) != 0){
                   get_cvar_string(locked_cvar[i],cvar,64)
                   if(!equal(cvar,locked_value[i])){
                       if(locked_yn[i] == 1){
                           server_cmd("%s
   %s",locked_cvar[i],locked_value[i])
                           log_message("[AMX][MAPCVARS]  Attemped  change
   of locked cvar detected. Returning %s to
   %s",locked_cvar[i],locked_value[i])
                           client_print(0,print_chat,"[AMX]      Attemped
   change     of     locked    cvar    detected.    Returning    %s    to
   %s",locked_cvar[i],locked_value[i])
                       }else{
                           if(locked_yn[i] == 0)
                               log_message("[AMX][MAPCVARS]   Change   of
   locked cvar detected, but change is allowed.")
                           locked_yn[i] = 2
                       }
                   }
               }
           }
       }
       return PLUGIN_CONTINUE
   }
   public lock_unlock(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       if (cvar_lock == true){
           cvar_lock = false
           client_print(id,print_console,"[AMX] Map Cvar lock is OFF.")
       }else    {
           cvar_lock = true
           client_print(id,print_console,"[AMX] Map Cvar lock is ON.")
       }
       return PLUGIN_HANDLED
   }
   do_pplugin(action,pluginfilename[]){
       new nump = get_pluginsnum()
       new filename[64],name[64],version[32],author[32],status[32]
       new success = 0
       for(new i=0;i<nump;++i){
           get_plugin(i,filename,63,name,63,version,31,author,31,status,3
   1)
           if(action == 1){
               if(equal(filename,pluginfilename)){
                   if(equali(status,"running"))
                       success = 1
                   if(equali(status,"paused")){
                       success = 1
                       plugin_p = 1
                       unpause("ac",pluginfilename)
                       log_message("[AMX][MAPCVARS]
   Executed:  UnPausePlugin %s",pluginfilename)
                   }
               }
           }
           else if(action == 0){
               if(equali(filename,pluginfilename)){
                   if(equali(status,"paused"))
                       success = 1
                   if(equali(status,"running")){
                       plugin_p = 1
                       success = 1
                       pause("ac",pluginfilename)
                       log_message("[AMX][MAPCVARS]
   Executed:  PausePlugin %s",pluginfilename)
                   }
               }
           }
       }
       if(!success){
           invalid = 1
           log_message("[AMX][MAPCVARS]      Warning:   Plugin     ^"%s^"
   is",pluginfilename)
           log_message("[AMX][MAPCVARS]            not      loaded     or
   corrupted. Check plugin.")
       }
   }
