Merciless Posted October 25, 2008 Share Posted October 25, 2008 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. <? $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 = "/<tr><td class=\"rank\">(.*)<\/td><td class=\"rank-charname\">(.*)<\/td><td class=\"rank-charlevel\">(.*)<\/td><td class=\"rank-guild\">(.*)<\/td><\/tr>/iU"; 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."<tr>\n"; $rvalue = $rvalue."<td> </td>\n"; $rvalue = $rvalue."<td class=\"guildtd\"><em>(guildless)</em></td>\n"; $rvalue = $rvalue."<td>{$guilds['(guildless)']['top50']}<br /><font>Players: {$guilds['(guildless)']['in50']} ({$guilds['(guildless)']['pt50']}%)</font></td>\n"; $guilds['(guildless)']['top10'] <= 0 ? $rvalue = $rvalue."<td>-</td>\n" : $rvalue = $rvalue."<td>{$guilds['(guildless)']['top10']}<br /><font>Players: {$guilds['(guildless)']['in10']} ({$guilds['(guildless)']['pt10']}%)</font></td>\n"; $guilds['(guildless)']['9x'] <= 0 ? $rvalue = $rvalue."<td>-</td>\n" : $rvalue = $rvalue."<td>{$guilds['(guildless)']['9x']}<br /><font>Average: {$guilds['(guildless)']['avg9x']}</font></td>\n"; $guilds['(guildless)']['10x'] <= 0 ? $rvalue = $rvalue."<td>-</td>\n" : $rvalue = $rvalue."<td>{$guilds['(guildless)']['10x']}<br /><font>Average: {$guilds['(guildless)']['avg10x']}</font></td>\n"; $rvalue = $rvalue."</tr>\n"; } return $rvalue; } $header = <<<HEAD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Unofficial Last Chaos USA Guild Rankings</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <br /> <img src="header.jpg" alt="Guild Rankings" /> <center>Guild rank is determined by added level of top guild members. lvl 90 + lvl 90 = 180pts</center> <br /> <strong>Server:</strong> <a href="#Katar">Katar</a> | <a href="#Cariae">Cariae</a> | <a href="#Sarissa">Sarissa</a> | <a href="#Hatzring">Hatzring</a> <br /> HEAD; $servhead = <<<SERVHEAD <br /> <h1 id="*NAME*">*NAME*</h1> <font>Updated: *DATE*</font> <br /><br /> <table border="0" cellspacing="0" cellpadding="0"> <tr> <th scope="col"> </th> <th scope="col">Guild</th> <th scope="col">Top 50</th> <th scope="col">Top 10</th> <th scope="col">Lvl. 9x</th> <th scope="col">Lvl. 10x</th> </tr> SERVHEAD; $footer = "</body>\n</html>"; $katar = str_replace(array("*NAME*", "*DATE*"), array("Katar", date("Y-m-d H:i:s T")), $servhead).FetchRanks("http://lastchaos.aeriagames.com/community/rankings")."</table><br />\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")."</table><br />\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")."</table><br />\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")."</table><br />\n"; $handle = fopen($output, 'w'); fwrite($handle, $header.$katar.$cariae.$sarissa.$hatzring.$footer); fclose($handle); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.