RMX_OS TOP ten best players in the game

Started by edwardthefma, April 06, 2010, 11:42:39 pm

Previous topic - Next topic

edwardthefma

April 06, 2010, 11:42:39 pm Last Edit: April 06, 2010, 11:52:53 pm by edwardthefma
RMX-OS top ten best
Authors: edwardthefma drummer
Type: php script



Introduction
top ten best players buy level



Features


  • a top ten listing




Screenshots
N/A
Demo
http://ssh.shellium.org/~edwardthefma/Eris%20online%20/topten.php



Script
Spoiler: ShowHide
  <html>

     <body>

     <?php

     class user {
 
             public $name;
 
             public $lv;
 
             public $exp;
 
     
 
             function __construct($name, $lv, $exp) {
 
                     $this->name = trim($name, '"');
 
                     $this->lv = $lv;
 
                     $this->exp = $exp;
 
             }
 
     }
 
     
 
     $mysql_access = mysql_connect("sqlhostname", "username", "password");
 
     mysql_select_db("databasename", $mysql_access);
 
     
 
     if(!$mysql_access) {
 
             echo "can't connect to db<br>\r\n";
 
     }

     else {
 
             $users = array();
 
             $users[0] = new user("nobody", 0, 0);
 
             $topsize = 10; // change this value to chage the number of users displayed ny the top list (i.e. 10 for top10, 5 for top5 etc)
 
             $top = array_fill(0, $topsize, array(0));
 
             $result = mysql_query("SELECT user_id FROM users");
 
            $count = mysql_num_rows($result);
 
             if($topsize > $count) $topsize = $count;
 
             $clistsize = $topsize;
 
             for($i=0; $i<$count; $i++) {
 
                     $row = mysql_fetch_assoc($result);
 
                     $userid = $row['user_id'];
 
                     $res = mysql_query("SELECT data_value FROM save_data WHERE user_id=$userid and data_name='Game_Actors/@data[1]/Game_Actor'");
 
                     $aux = mysql_fetch_assoc($res);
 
                     $stat = explode(",", trim($aux['data_value']," []"));
 
                     $users[$userid] = new user($stat[1], $stat[10], $stat[11]);
 
                     $aux = array();
 
                    $ctrl = true;
 
                     foreach($top as $ids) {
 
                             $add = false;
 
                             if($ctrl) {
 
                                     $id = $ids[0];
 
                                     $r1 = $users[$userid]->lv - $users[$id]->lv;
 
                                     $r2 = $users[$userid]->exp - $users[$id]->exp;
 
                                    if(($r1 > 0) || ($r1 == 0) && ($r2 > 0)) {
 
                                             $aux[] = array($userid);
 
                                             $ctrl = false;
 
                                     }
 
                                     elseif(($r1 == 0) && ($r2 == 0)) {
 
                                             $aux2 = $ids;
 
                                             $aux2[] = $userid;
 
                                             sort($aux2, SORT_NUMERIC);
 
                                             $aux[] = $aux2;
 
                                             $ctrl = false;
 
                                             $add = true;
 
                                     }
 
                             }
 
                             if (!$add) $aux[] = $ids;
 
                     }

                     $top = array_slice($aux, 0, $topsize);

             }
 
             echo "<table align='center' cellpadding=2 cellspacing=1 border=1 width='40%'>\r\n";

             echo "<colgroup span=4 align='center' width='15%'>\r\n";
 
             echo "<col>\r\n";
 
             echo "<col width='55%'>\r\n";

             echo "<col span=2>\r\n";

             echo "</colgroup>\r\n";

             echo "<tr><th colspan=4 bgcolor='#01A8FF'>Top$topsize players</th></tr>\r\n";
      echo "<tr align='center' bgcolor='01C0FF'><th>Position</th><th>Name</th><th>Level</th><th>Exp</th></tr>\r\n";

     

             foreach($top as $p1 => $ids) {

                     $i = 0;

                     $p = $p1 + 1;

                     $bgcolor = ($i % 2) ? "01C0FF" : "01A8FF";

                     foreach($ids as $k => $id) {

                             echo "<tr bgcolor='#$bgcolor'>";
 
                             $i++;

                             if($k==0) echo "<td rowspan=" . count($ids) . ">$p</td>";

                             echo "<td><a href='search.php?username=" . $users[$id]->name . "'>" . $users[$id]->name . " ($id)</a></td><td>" . $users[$id]->lv . "</td><td>" . $users[$id]->exp . "</td></tr>\r\n";

                     }
 
             }
 
             echo "</table>\r\n";
 
     }
   ?>
 
     </body>
 
     </html>





Instructions
you will need to make shur you have edited the script to read the data from your games mysql database



Compatibility
works with any ver of rmx-os this needs the rmx-os profiles script


Credits and Thanks

    drummer thanks for the help




Author's Notes
you might want to read up on basic php

That's it! N-Joy! =D
i am the lead dev for the shellium mmorpg project
http://wiki.shellium.org/w/Mmorpg
shellium.org :) free linux shells pm me and i will gladly
help you get 1