
   /* AMX Mod script.
   *
   * (c) Copyright 2002, OLO
   * This file is provided as is (no warranties).
   *
   */
   /*
   Controls  sv_maxupdaterate  (be  wise with usage or you will get pings
   worse).
   cvars:
   amx_ctrlupdaterate <value> - when players is more than that value then
                                                               server
   starts to lowering sv_udpdaterate
   amx_maxupdaterate   <value>  -      this  is  what  you  want  maximum
   sv_updaterate to be
   amx_minupdaterate   <value>  -      this  is  what  you  want  minimum
   sv_updaterate to be
   */
   #include <amxmod>
   new low = 0
   new udl = 0
   new bool:calculate = true
   public client_putinserver(id)
   {
       if (calculate)
       {
           calculate = false

           new maxupd = get_cvar_num("amx_maxupdaterate")
           new minupd = get_cvar_num("amx_minupdaterate")

           new divv = get_maxplayers() -
   get_cvar_num("amx_ctrlupdaterate")

           if (divv < 1)
               divv = 1

           low = (maxupd - minupd) / divv
           udl = maxupd

           set_cvar_num("sv_maxupdaterate",udl)
           /*server_print("sv_maxupdaterate set to %d",udl)*/
       }

       if ( get_playersnum() > get_cvar_num("amx_ctrlupdaterate") )
       {
           udl -= low
           set_cvar_num("sv_maxupdaterate",udl)
           /*server_print("sv_maxupdaterate set to %d",udl)*/
       }

       return PLUGIN_CONTINUE
   }
   public client_disconnect(id)
   {
       /* get_playersnum still includes this id */
       if ( get_playersnum() >= get_cvar_num("amx_ctrlupdaterate") )
       {
           udl += low
           set_cvar_num("sv_maxupdaterate",udl)
           /*server_print("sv_maxupdaterate set to %d",udl)*/
       }

       return PLUGIN_CONTINUE
   }
   public plugin_init()
   {
       register_plugin("Bandwidth Control","0.8.7","default")
       register_cvar("amx_ctrlupdaterate","8")
       register_cvar("amx_maxupdaterate","60")
       register_cvar("amx_minupdaterate","45")
       return PLUGIN_CONTINUE
   }
