rswildy Posted August 9, 2007 Share Posted August 9, 2007 Okay, About a month ago Justsomeguy helped me make this code: <html> <head> <title>Scores</title> </head> <body> <div> Enter a name:<br /> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="get"> <input type="text" name="name" value="<?php echo $_GET['name']?>" /> <input type="submit" value="Go" /> </form> </div> <br /><?phpif (isset($_GET['name'])){ $skill_list = array("Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction"); $contents = ""; $handle = fopen("http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=".urlencode($_GET['name']),"r"); if($handle) { while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); } echo "<table cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr>"; echo "<td style=\"border-bottom: 1px solid black;\">Skill</td>"; echo "<td style=\"border-bottom: 1px solid black;\">Rank</td>"; echo "<td style=\"border-bottom: 1px solid black;\">Level</td>"; echo "<td style=\"border-bottom: 1px solid black;\">XP</td>"; echo "</tr>"; $bg = false; $found_skills = array(); $skills = parse($contents); foreach ($skills as $info) { if ($bg) echo "<tr style=\"background: #D0D0D0;\">"; else echo "<tr>"; echo "<td>{$info['skill']}</td>"; echo "<td>{$info['rank']}</td>"; echo "<td>{$info['level']}</td>"; echo "<td>{$info['xp']}</td>"; echo "</tr>"; $found_skills[] = $info['skill']; $bg = !$bg; } $missing_skills = array_diff($skill_list, $found_skills); foreach($missing_skills as $skill) { if ($bg) echo "<tr style=\"background: #D0D0D0;\">"; else echo "<tr>"; echo "<td>{$skill}</td>"; echo "<td>--</td>"; echo "<td>--</td>"; echo "<td>--</td>"; echo "</tr>"; $bg = !$bg; } echo "</table>";}function parse($contents){ $matches = array(); $pattern = "@<tr>\\s<td.*><img.*></td>\\s<td.*><a.*>\\s([^<]+)\\s</a></td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s</tr>@imsU"; $nr_matches = preg_match_all($pattern, $contents, $matches); $retval = array(); $i = 0; for ($i = 0; $i < count($matches[1]); $i++) { $retval[$i]['skill'] = $matches[1][$i]; $retval[$i]['rank'] = $matches[2][$i]; $retval[$i]['level'] = $matches[3][$i]; $retval[$i]['xp'] = $matches[4][$i]; } return $retval;}?> </body></html> Now, There is a simpler way to do it.A url like http://hiscore.runescape.com/index_lite.ws?player=zezima will output the information needed there is no hard pattern there to follow if you view source all you see is: 150428,1415,4037971522322,97,10898487314013,70,8028399026,99,1384247931308,93,7462750540406,61,303112302969,52,127902189247,75,1215797290926,70,799013226383,77,1564695331916,67,570241-1,53,149747444482,53,147105221470,59,268820880553,48,89152-1,49,96146381279,34,20768316572,50,10634645451,66,51623780514,64,421439200002,37,27566629474,32,1771614082,72,903162252300,37,28196 Can you show me how to make a script (like the old one) But using the new method. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 9, 2007 Share Posted August 9, 2007 That's a lot easier, it's just CSV data. Do you know which order everything is in? And what does -1 indicate? Link to comment Share on other sites More sharing options...
rswildy Posted August 13, 2007 Author Share Posted August 13, 2007 the order is ("Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction"); -1 indicates unranked, the example i gave before was bad.You should try this one. 20035,1768,1747253801790,99,21800510-1,45,61861338,99,250214692706,99,205859471672,99,1536484633,99,1668910673,99,230992213232,99,1449951912294,94,839384610523,99,1322103679304,80,200956842697,75,12272941930,90,563342918496,76,1368207205653,70,73841130227,66,54608050226,65,45628942925,67,55156437975,72,91232034482,62,334129648767,32,17109-1,1,01496,81,2193619 if it start with -1 it shouldnt get ranked. Link to comment Share on other sites More sharing options...
rswildy Posted August 13, 2007 Author Share Posted August 13, 2007 if you could also explain how if you make this script simpler what would be the easiest way for me to edit the stats to 1 stats lets say "Woodcutting", Then how can i make a calculator for example. * Enter username* Get stats Display level currently* then they can for example choose a certain thing lets say willow tree and lets say it gave 50xp (ill work out real values), If they put they are going to cut 1000 x willow trees or something how could i make it calculate the level after, Once again ill work out all XP values...I just need a genral explination for this part. Thanks, Rswildy. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2007 Share Posted August 13, 2007 Well, first off you need to focus on getting the data, once you have the data you can do whatever you want with it.You listed 23 skills, and there are 24 lines in the CSV. The first one might be overall. Anyway, this code will assume there are the same number of lines as there are entries in the skills array, and in the same order. So you need to update the skills array to reflect what the real order is of the CSV data. <html> <head> <title>Scores</title> </head> <body> <div> Enter a name:<br /> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="get"> <input type="text" name="name" value="<?php echo $_GET['name']?>" /> <input type="submit" value="Go" /> </form> </div> <br /><?phpif (isset($_GET['name'])){ $skill_list = array("Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction"); $skills = array(); $contents = ""; $handle = fopen("http://hiscore.runescape.com/index_lite.ws?player=".urlencode($_GET['name']),"r"); if($handle) { while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); } $lines = explode("\n", trim($contents)); for ($i = 0; $i < count($lines); $i++) { $skill = array(); $chunks = explode(",", trim($lines[$i])); $skill['skill'] = $skill_list[$i]; $skill['rank'] = $chunks[0]; $skill['level'] = $chunks[1]; $skill['xp'] = $chunks[2]; $skills[$skill_list[$i]] = $skill; } echo "<table cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr>"; echo "<td style=\"border-bottom: 1px solid black;\">Skill</td>"; echo "<td style=\"border-bottom: 1px solid black;\">Rank</td>"; echo "<td style=\"border-bottom: 1px solid black;\">Level</td>"; echo "<td style=\"border-bottom: 1px solid black;\">XP</td>"; echo "</tr>"; $bg = false; foreach ($skills as $skill => $info) { if ($bg) echo "<tr style=\"background: #D0D0D0;\">"; else echo "<tr>"; echo "<td>{$info['skill']}</td>"; echo "<td>{$info['rank']}</td>"; echo "<td>{$info['level']}</td>"; echo "<td>{$info['xp']}</td>"; echo "</tr>"; $bg = !$bg; } echo "</table>";}?> </body></html> Link to comment Share on other sites More sharing options...
rswildy Posted August 18, 2007 Author Share Posted August 18, 2007 now what if i want to get say, woodcutting LEVEL. 150428,1415,4037971522322,97,10898487314013,70,8028399026,99,1384247931308,93,7462750540406,61,303112302969,52,127902189247,75,1215797290926,70,799013226383,77,1564695 << Woodcutting 77 Is the level331916,67,570241-1,53,149747444482,53,147105221470,59,268820880553,48,89152-1,49,96146381279,34,20768316572,50,10634645451,66,51623780514,64,421439200002,37,27566629474,32,1771614082,72,903162252300,37,28196 How do i then store that in a var.Can you show me by storing into a var named $wclvlThis way, I can add values to the original var, making a calculator from it. Link to comment Share on other sites More sharing options...
alex Posted August 19, 2007 Share Posted August 19, 2007 lol play runescape eh?add alex2974 my list is always on Link to comment Share on other sites More sharing options...
rswildy Posted August 19, 2007 Author Share Posted August 19, 2007 I don't play much, I just run a fansite. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 20, 2007 Share Posted August 20, 2007 All of the skills are stored in the $skills array, it gets built here: for ($i = 0; $i < count($lines); $i++) { $skill = array(); $chunks = explode(",", trim($lines[$i])); $skill['skill'] = $skill_list[$i]; $skill['rank'] = $chunks[0]; $skill['level'] = $chunks[1]; $skill['xp'] = $chunks[2]; $skills[$skill_list[$i]] = $skill; } So $skills['Woodcutting']['level'] is the woodcutting level. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.