Im now hosting a script for an online game. It’s a rank script to show the rank of entire guilds by polling the online game’s individual player rank. I spent some time getting it working, and trobleshooting everything.
It’s online at http://merciless.pcriot.com
What I want to do now is add a top 5 players list, that will show the top 5 players from ALL of the sub groups. As you can tell from the code, there is 4 sub groups. I would also like to switch Katar and Cariae on the site… So that Cariae comes before Katar.
Here’s the code.
[code]<?
$output = “/home/merciles/public_html/index.html”;
function FetchRanks($url) {
$filepointer = fopen($url,“r”);
if($filepointer){
while(!feof($filepointer)){
$buffer = fgets($filepointer, 4096);
$file .= $buffer;
}
fclose($filepointer);
} else {
die(“Could not create a connection to the Last Chaos website.”);
}
$pattern = “/
preg_match_all($pattern, $file, $players, PREG_SET_ORDER);
$guilds = array();
foreach ($players as $player) {
//Catch guidless
$player[4] == '' ? $player[4] = "(guildless)" : 0;
//Top 10.
$player[1] <= 10 ? $tmptop = $player[3] : $tmptop = 0;
$player[1] <= 10 ? $tmpin = 1 : $tmpin = 0;
//9x or 10x
$player[3] >= 90 && $player[3] <= 99 ? $tmp9x = 1 : $tmp9x = 0;
$player[3] >= 100 ? $tmp10x = 1 : $tmp10x = 0;
//9x & 10x totals
$player[3] >= 90 && $player[3] <= 99 ? $tmp9xtot = $player[3] : $tmp9xtot = 0;
$player[3] >= 100 ? $tmp10xtot = $player[3] : $tmp10xtot = 0;
//New guild, add to array
if ($player[4] != '' && !array_key_exists($player[4], $guilds)) {
$guilds[$player[4]] = array("top50" => $player[3], "top10" => $tmptop, "in50" => 1, "in10" => $tmpin, "9x" => $tmp9x, "10x" => $tmp10x, "9xtot" => $tmp9xtot, "10xtot" => $tmp10xtot);
//Guild already in array, add player stats to guild array
} elseif ($player[4] != '') {
$guilds[$player[4]]['top50'] = $guilds[$player[4]]['top50'] + $player[3];
$guilds[$player[4]]['in50'] = $guilds[$player[4]]['in50'] + 1;
$guilds[$player[4]]['top10'] = $guilds[$player[4]]['top10'] + $tmptop;
$guilds[$player[4]]['in10'] = $guilds[$player[4]]['in10'] + $tmpin;
$guilds[$player[4]]['9x'] = $guilds[$player[4]]['9x'] + $tmp9x;
$guilds[$player[4]]['9xtot'] = $guilds[$player[4]]['9xtot'] + $tmp9xtot;
$guilds[$player[4]]['10x'] = $guilds[$player[4]]['10x'] + $tmp10x;
$guilds[$player[4]]['10xtot'] = $guilds[$player[4]]['10xtot'] + $tmp10xtot;
}
}
foreach ($guilds as $key => $row) {
$row[‘9xtot’] != 0 ? ($guilds[$key][‘avg9x’] = round($row[‘9xtot’] / $row[‘9x’])) : 0;
$row[‘10xtot’] != 0 ? ($guilds[$key][‘avg10x’] = round($row[‘10xtot’] / $row[‘10x’])) : 0;
$guilds[$key][‘pt50’] = round(($row[‘in50’] / 300) * 100, 2);
$guilds[$key][‘pt10’] = round(($row[‘in10’] / 60) * 100, 2);
}
foreach ($guilds as $key => $row) {
$top50[$key] = $row[‘top50’];
$top10[$key] = $row[‘top10’];
}
array_multisort($top50, SORT_DESC, $top10, SORT_DESC, $guilds);
//Build table
$pos = 0;
$rvalue = ‘’;
foreach ($guilds as $guild => $data) {
if ($guild != '(guildless)') {
$pos++;
$rvalue = $rvalue."<tr>n";
$rvalue = $rvalue."<td>{$pos}</td>n";
$rvalue = $rvalue."<td class="guildtd">{$guild}</td>n";
$rvalue = $rvalue."<td>{$data['top50']}<br /><font>Players: {$data['in50']} ({$data['pt50']}%)</font></td>n";
$data['top10'] <= 0 ? $rvalue = $rvalue."<td>-</td>n" : $rvalue = $rvalue."<td>{$data['top10']}<br /><font>Players: {$data['in10']} ({$data['pt10']}%)</font></td>n";
$data['9x'] <= 0 ? $rvalue = $rvalue."<td>-</td>n" : $rvalue = $rvalue."<td>{$data['9x']}<br /><font>Average: {$data['avg9x']}</font></td>n";
$data['10x'] <= 0 ? $rvalue = $rvalue."<td>-</td>n" : $rvalue = $rvalue."<td>{$data['10x']}<br /><font>Average: {$data['avg10x']}</font></td>n";
$rvalue = $rvalue."</tr>n";
}
}
if (array_key_exists(’(guildless)’, $guilds)) {
$rvalue = $rvalue.“
$rvalue = $rvalue."
$rvalue = $rvalue."
$rvalue = $rvalue."
Players: {$guilds[’(guildless)’][‘in50’]} ({$guilds[’(guildless)’][‘pt50’]}%)
$guilds[’(guildless)’][‘top10’] <= 0 ? $rvalue = $rvalue."
Players: {$guilds[’(guildless)’][‘in10’]} ({$guilds[’(guildless)’][‘pt10’]}%)
$guilds[’(guildless)’][‘9x’] <= 0 ? $rvalue = $rvalue."
Average: {$guilds[’(guildless)’][‘avg9x’]}
$guilds[’(guildless)’][‘10x’] <= 0 ? $rvalue = $rvalue."
Average: {$guilds[’(guildless)’][‘avg10x’]}
$rvalue = $rvalue.“
}
return $rvalue;
}
$header = <<<HEAD
Unofficial Last Chaos USA Guild RankingsGuild rank is determined by added level of top guild members. lvl 90 + lvl 90 = 180pts
Server: Katar | Cariae | Sarissa | Hatzring
HEAD;
$servhead = <<<SERVHEAD
*NAME*
Updated: *DATE*Guild | Top 50 | Top 10 | Lvl. 9x | Lvl. 10x |
---|
n”;
$cariae = str_replace(array(“NAME”, “DATE”), array(“Cariae”, date(“Y-m-d H:i:s T”)), $servhead).FetchRanks(“http://lastchaos.aeriagames.com/community/rankings/active/Cariae")."
n”;
$sarissa = str_replace(array(“NAME”, “DATE”), array(“Sarissa”, date(“Y-m-d H:i:s T”)), $servhead).FetchRanks(“http://lastchaos.aeriagames.com/community/rankings/active/Sarissa")."
n”;
$hatzring = str_replace(array(“NAME”, “DATE”), array(“Hatzring”, date(“Y-m-d H:i:s T”)), $servhead).FetchRanks(“http://lastchaos.aeriagames.com/community/rankings/active/Hatzring")."
n”;
$handle = fopen($output, ‘w’);
fwrite($handle, $header.$katar.$cariae.$sarissa.$hatzring.$footer);
fclose($handle);
?>[/code]