
   #include <amxmod>
   new oldaliverate
   new olddeadrate
   public split_rate(){
       set_task(5.0,"split_rate")
       if (get_cvar_num("rate_force")==0)
           return PLUGIN_HANDLED
       new players[32]
       new numofplayers
       new aliveplayers
       new deadplayers
       new aliverate
       new deadrate
       new id
       new i
       new ping
       new loss
       new Float:temp1
       new Float:temp2
       new totalrate = get_cvar_num("rate_max")
       new Float:ratio = get_cvar_float("rate_ratio")
       get_players(players, deadplayers, "bc")
       get_players(players, numofplayers, "c")
       if (numofplayers==0)
           return PLUGIN_HANDLED
       aliveplayers = numofplayers - deadplayers
       for (i=0; i<numofplayers; ++i){
           id = players[i]
           get_user_ping(id, ping, loss)
           if (ping <= get_cvar_float("rate_localping")){
               if (is_user_alive(id))
                   --aliveplayers
               else
                   --deadplayers
           }
       }
       aliverate =
   floatround(float(totalrate)/(float(aliveplayers)+(ratio*float(deadplay
   ers))))
       deadrate =
   floatround((float(totalrate)-float(aliveplayers)*float(aliverate))/flo
   at(deadplayers))
       if (aliveplayers==0)
           aliverate=0
       if (deadplayers==0)
           deadrate=0
       if (aliverate==oldaliverate && deadrate == olddeadrate)
           return PLUGIN_HANDLED
       else{
           oldaliverate=aliverate
           olddeadrate=deadrate
       }
       for (i=0; i<numofplayers; ++i){
           id = players[i]
           get_user_ping(id, ping, loss)
           new command[32]
           if (ping > get_cvar_float("rate_localping")){
               if (is_user_alive(id))
                   format(command,31,"rate %d", aliverate)
               else
                   format(command,31,"rate %d", deadrate)
               client_cmd(id, command)
           }
       }
       if (get_cvar_num("rate_showmessage")){
           new msg[256]
           format(msg,255,"Players  Alive: %d, Dead: %d - Rate for Alive:
   %d, Dead: %d", aliveplayers, deadplayers, aliverate, deadrate)
           console_print(0,msg)
       }
       return PLUGIN_HANDLED
   }
   public plugin_init()
   {
       register_plugin("Client Rate","1.0","SpaceDude")
       register_cvar("rate_max","16000")        // bandwidth*1024/8
       register_cvar("rate_ratio","0.5")
       register_cvar("rate_force","1")
       register_cvar("rate_showmessage","0")
       register_cvar("rate_localping","0")
       set_task(5.0,"split_rate")
       return PLUGIN_CONTINUE
   }
