/*********************************************************
 *Bugblatter Natural Selection Round End Extension - V3.1*
 *********************************************************
 *                                                       *
 * This plug-in is linux & win32 friendly.               *
 *                                                       *
 * Version 3.1:                                          *
 *                                                       *
 *  -  Initial Version.                                  *
 *********************************************************
 */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
#include <plugin>
 
#define MAX_MOVED 8
 
new g_Version[] = "3.1";
 
 
new g_Start=0;
 
forward BBLogdTeamScore(HLCommand,HLData,HLUserName,UserIndex);
forward MoveSomeMore(Timer,Repeat,HLUserName,HLParam);
forward MoveEvenMore(Timer,Repeat,HLUserName,HLParam);
 
/*
 *********************************************************
 *                  PLUGIN INITIALISATION                *
 *********************************************************
*/
 
 
public plugin_init() {
 
  plugin_registerinfo("Bugblatter's NS End of round Plugin","Stops NS crashing at the end of round",g_Version);
 
  plugin_registercmd("bbnsend_logdts","BBLogdTeamScore",131072,"");
  exec("logd_reg 65 admin_command bbnsend_logdts",0);
 
  plugin_message("Plugin initialisation complete.");
 
 
  return PLUGIN_CONTINUE;
}
 
 
 
public BBLogdTeamScore(HLCommand,HLData,HLUserName,UserIndex) {
  new Data[MAX_DATA_LENGTH];
  convert_string(HLData,Data,MAX_DATA_LENGTH);
 
  if (Data[0] == '1') {
    g_Start=1;
    if (MoveSome()==0) {
      set_timer("MoveSomeMore",1,1,"");
    }
  }
}
 
public MoveSomeMore(Timer,Repeat,HLUserName,HLParam) {
  log("move more");
  if (MoveSome()==0) {
    set_timer("MoveEvenMore",1,1,"");
  }
}
 
public MoveEvenMore(Timer,Repeat,HLUserName,HLParam) {
  log("move even more");
  MoveSome();
}
 
MoveSome() {
 
  new userid = 0;
  new wonid=0;
  new AuthID[MAX_AUTHID_LENGTH];
  new team = 0;
  new username[200];
  new x = 0;
  new dead=0;
  new nCount=0;
 
  x = maxplayercount();
  while (g_Start<=x) {
    if (playerinfo(g_Start, username, 200, userid, wonid,team,dead,AuthID)==1) {
      if ((team == 1) || (team == 2)) {
        log("moving");
        log(username);
        execclient(username, "readyroom");
        nCount++;
        if (nCount==MAX_MOVED) {
          g_Start++;
          return 0;
        }
      }
    }
    g_Start++;
  }
  return 1;
}