Beispiel #1
0
 /** Balances teams.
  * This function balances the teams according to the arrival order of the players. 
  * It is executed on new connections and when a player changes team (if AutoTeams is enabled in plugin config).
  * It only changes the team of new players. 
  * 
  * \param $player The player who send the command. (if is player has send command)
  * 	 
  * \return Nothing.
  */
 private function _balance($player = null)
 {
     //We take player count of each team.
     $teams_count = Server::getTeamCount();
     if ($teams_count[Server::TEAM_RED] >= $teams_count[Server::TEAM_BLUE] + 2) {
         $too_many_player = floor(($teams_count[Server::TEAM_RED] - $teams_count[Server::TEAM_BLUE]) / 2);
         $src_team = Server::TEAM_RED;
         $dest_team = strtolower(Server::getTeamName(Server::TEAM_BLUE));
         $balance = TRUE;
     } elseif ($teams_count[Server::TEAM_BLUE] >= $teams_count[Server::TEAM_RED] + 2) {
         $too_many_player = floor(($teams_count[Server::TEAM_BLUE] - $teams_count[Server::TEAM_RED]) / 2);
         $src_team = Server::TEAM_BLUE;
         $dest_team = strtolower(Server::getTeamName(Server::TEAM_RED));
         $balance = TRUE;
     } else {
         $balance = FALSE;
     }
     //If the teams are unbalanced
     if ($balance) {
         //We get player list
         $players = Server::getPlayerList($src_team);
         $last = array();
         foreach ($players as $player) {
             $last[$player->time] = $player->id;
         }
         //We sorts the players of the team by time spent on the server.
         krsort($last);
         //Processing loop
         while ($too_many_player > 0) {
             //We take the last player of the team
             $player = array_shift($last);
             //Add on ClientUserinfoChanged ignore list
             $this->_ClientUserinfoChangedIgnore[$player] = $player;
             //We change the team of the player
             RCon::forceteam($player, $dest_team);
             --$too_many_player;
         }
         RCon::say('Teams are now balanced');
     } else {
         if ($player !== NULL) {
             RCon::tell($player, 'Teams are already balanced');
         }
     }
 }
Beispiel #2
0
 /** Forceteam command. Force a player in a team.
  * This function is bound to the !force command. Forces a player to join a defined team. Available teams are : red, blue, spectator.
  * 	 
  * \param $id The game ID of the player who executed the command.
  * \param $command The command parameters.
  * 
  * \return Nothing.
  */
 public function CommandForce($id, $command)
 {
     if (!empty($command[0]) && !empty($command[1])) {
         $target = Server::searchPlayer($command[0]);
         if ($target === FALSE) {
             RCon::tell($id, "No player found.");
         } elseif (is_array($target)) {
             $players = array();
             foreach ($target as $p) {
                 $players[] = Server::getPlayer($p)->name;
             }
             RCon::tell($id, 'Multiple players found : $0', array(join(', ', $players)));
         } else {
             if (in_array($command[1], array('spec', 'spect'))) {
                 $command[1] = 'spectator';
             }
             if (in_array($command[1], array('red', 'blue', 'spectator'))) {
                 RCon::forceteam($target . ' ' . $command[1]);
             } else {
                 Rcon::tell($id, 'Invalid parameter. Available teams : red, blue, spectator.');
             }
         }
     } else {
         Rcon::tell($id, 'Missing parameters.');
     }
 }