• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Help with higshcores!

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,782
Solutions
25
Reaction score
491
Location
Sweden
I'm using Nicaws AAC.

A friend have helped me add so frags stores in my database. Now I want to make them able to view as an option in highscores!

I don't know how to edit this so I'm asking for help :P

In database: player_frags: killerid and killedid

also in players there is a column called frags... anyway, here is the script!

PHP:
<?php 
/*
    Copyright (C) 2007 - 2009  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include ("include.inc.php");
$ptitle="Highscores - $cfg[server_name]";
include ("header.inc.php");

$SQL = AAC::$SQL;
?>
<div id="content">
    <div class="top">Highscores</div>
    <div class="mid">
        <select name="sort" onchange="self.location.href=this.value">
            <?php
            if (empty($_GET['sort'])) $_GET['sort'] = 'census';

            $options = array_merge(array('census', 'level', 'maglevel'), $cfg['skill_names']);

            foreach ($options as $skill) {
                if ($skill == $_GET['sort'])
                    $selected = ' selected="selected"';
                else
                    $selected = '';
                echo '<option value="ranks.php?sort='.$skill.'"'.$selected.'>'.ucfirst($skill).'</option>';
            }
            echo '</select>';

            if (!isset($_GET['page']) || $_GET['page'] < 0) $p = 0;
            else $p = (int) $_GET['page'];

            if ($_GET['sort'] == 'level' || $_GET['sort'] == 'maglevel') {
                if($SQL->isTable('groups')) {
                    $query = 'SELECT groups.access, groups.id, players.name, players.level, players.maglevel, players.experience FROM players LEFT OUTER JOIN groups ON players.group_id = groups.id ORDER BY `'.mysql_escape_string($_GET['sort']).'` DESC LIMIT '.$cfg['ranks_per_page']*$p.', '.$cfg['ranks_per_page'].';';
                } else {
                    $query = 'SELECT 0 AS access, players.name, players.level, players.maglevel, players.experience FROM players ORDER BY `'.mysql_escape_string($_GET['sort']).'` DESC LIMIT '.$cfg['ranks_per_page']*$p.', '.$cfg['ranks_per_page'].';';
                }
                $key = $_GET['sort'];
            }elseif (in_array($_GET['sort'],$cfg['skill_names'])) {
                if($SQL->isTable('groups')) {
                    $query = 'SELECT groups.access, a1.* FROM (SELECT players.group_id, players.name, player_skills.value FROM players, player_skills WHERE players.id = player_skills.player_id AND player_skills.skillid = '.array_search($_GET['sort'], $cfg['skill_names']) .') AS a1 LEFT OUTER JOIN groups ON a1.group_id = groups.id ORDER BY `value` DESC LIMIT '.$cfg['ranks_per_page']*$p.', '.$cfg['ranks_per_page'].';';
                } else {
                    $query = 'SELECT 0 AS access, a1.* FROM (SELECT players.group_id, players.name, player_skills.value FROM players, player_skills WHERE players.id = player_skills.player_id AND player_skills.skillid = '.array_search($_GET['sort'], $cfg['skill_names']) .') AS a1 ORDER BY `value` DESC LIMIT '.$cfg['ranks_per_page']*$p.', '.$cfg['ranks_per_page'].';';
                }
                $key = 'value';
            }elseif ($_GET['sort'] == 'census') {
                $SQL->myQuery('SELECT players.sex, COUNT(players.id) as number FROM `players` GROUP BY players.sex');
                $total = 0;
                while ($a = $SQL->fetch_array()) {
                    $genders[$a['sex']] = $a['number'];
                    $total += $a['number'];
                }
                $gender_names = array(0 => 'Female',1 => 'Male');
                echo '<p><h2>Sex</h2>';
                echo '<table style="font-weight: bold">';
                foreach (array_keys($genders) as $gender)
                    echo '<tr><td>'.$gender_names[$gender].'</td><td>'.percent_bar($genders[$gender],$total).'</td><td>('.$genders[$gender].')</td></tr>';
                echo '</table></p>';
                $SQL->myQuery('SELECT players.vocation, COUNT(players.id) as number FROM `players` GROUP BY players.vocation');
                $total = 0;
                while ($a = $SQL->fetch_array()) {
                    $vocations[$a['vocation']] = $a['number'];
                    $total += $a['number'];
                }
                echo '<p><h2>Profession</h2>';
                echo '<table style="font-weight: bold">';
                foreach (array_keys($vocations) as $vocation)
                    echo '<tr><td>'.$cfg['vocations'][$vocation]['name'].'</td><td>'.percent_bar($vocations[$vocation],$total).'</td><td>('.$vocations[$vocation].')</td></tr>';
                echo '</table></p>';

            }else {$error = "Invalid sort argument";}

            if (isset($query)) {
                ?>
            <input type="button" value="&lt;&lt;" onclick="self.window.location.href='ranks.php?sort=<?php echo urlencode($_GET['sort'])?>&amp;page=<?php echo $p-1?>'"/>
            <b>Statistics page: <?php echo $p+1?></b>
            <input type="button" value="&gt;&gt;" onclick="self.window.location.href='ranks.php?sort=<?php echo urlencode($_GET['sort'])?>&amp;page=<?php echo $p+1?>'"/>
            <table>
                <tr class="color0"><td style="width:30px">#</td><td style="width:150px"><b>Name</b></td><td style="width:60px"><b><?php echo htmlspecialchars(ucfirst($_GET['sort']))?></b></td></tr>
                    <?php
                    $SQL->myQuery($query);

                    $i = $cfg['ranks_per_page']*$p;
                    while($a = $SQL->fetch_array())
                        if ($a['access'] < $cfg['ranks_access']) {
                            $i++;
                            echo '<tr '.getStyle($i).'><td>'.$i.'</td><td><a href="characters.php?player_name='.urlencode($a['name']).'">'.htmlspecialchars($a['name']).'</a></td><td>'.$a[$key].'</td></tr>'."\n";
                        }

                }
                ?>
            </table>
    </div>
    <div class="bot"></div>
</div>
<?php include('footer.inc.php');?>
 
PHP:
           //frags list by Xampy 
             
            $frags_limit = 10; // frags limit to show? // default: 10 
            $player_frags = $SQL->query('SELECT `player_deaths`.*, `players`.`name`, `killers`.`unjustified` FROM `player_deaths` LEFT JOIN `killers` ON `killers`.`death_id` = `player_deaths`.`id` LEFT JOIN `player_killers` ON `player_killers`.`kill_id` = `killers`.`id` LEFT JOIN `players` ON `players`.`id` = `player_deaths`.`player_id` WHERE `player_killers`.`player_id` = '.$player->getId().' ORDER BY `date` DESC LIMIT 0,'.$frags_limit.';'); 
            if(count($player_frags)) 
            { 
                $frags = 0; 
                $frag_add_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><br><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=2 CLASS=white><B>Frags</B></TD></TR>'; 
                foreach($player_frags as $frag) 
                { 
                $frags++; 
                    if(is_int($number_of_rows / 2)) $bgcolor = $config['site']['darkborder']; else $bgcolor = $config['site']['lightborder']; 
                    $number_of_rows++; 
                    $frag_add_content .= "<tr bgcolor=\"".$bgcolor."\"> 
                    <td width=\"20%\" align=\"center\">".date("j M Y, H:i", $frag['date'])."</td> 
                    <td>".(($player->getSex() == 0) ? 'She' : 'He')." fragged <a href=\"index.php?subtopic=characters&name=".$frag[name]."\">".$frag[name]."</a> at level ".$frag[level].""; 

                    $frag_add_content .= ". (".(($frag[unjustified] == 0) ? "<font size=\"1\" color=\"green\">Justified</font>" : "<font size=\"1\" color=\"red\">Unjustified</font>").")</td></tr>"; 
                } 
            if($frags >= 1) 
                $main_content .= $frag_add_content . '</TABLE>'; 
            } 
            // end of frags list by Xampy

so?
 
Thanks for respond, but I was thinking more like an highscore! :P

and if that is what you've done, cud you help me implent it in my current script?
 
Back
Top