Message
Author
Board
Date
January 22, 2025, 11:45:46 PM
January 22, 2025, 11:35:09 PM
January 18, 2025, 01:56:06 AM
January 18, 2025, 12:31:57 AM
January 15, 2025, 10:10:06 PM

High Scores/Stats Block (Vertical)

Started by Chen Zhen, September 10, 2024, 03:33:42 AM

Previous topic - Next topic

Chen Zhen

High Scores/Stats PHP Block

Arcade version: SMF Arcade 2.7.0.2+



There is an adjustable setting near the start of the block to select if you want to display high scores only:
$mydisplays = true;
PHP Block Code:
/* High Scores/Stats PHP Block */
/**************************
set $gameTypes
0 = Permission based
1 = Flash/HTML
2 = ROM only
3 = All game types
**************************/
global $settings, $scripturl, $sourcedir, $boardurl, $smcFunc, $arcadeModSettings, $boarddir;
require_once($boarddir . '/ArcadeSources/ArcadeStats.php');

$no = 10; //number of top players to show
$txtplay = "The Top Players"; // change "The Top Players" to your language
$txtwin = "Number Of Wins :";// change "Number Of Wins :" to your language
$txtlate = "Latest High Score by ";// change "Latest High Score set by" to your language
$txtwit = "with ";// change "with" to your language
$txton = "on ";// change "on" to your language
$arcade_icon = 'arcade.jpg';
$gameTypes = 0;

switch($gameTypes) {
case 1:
$where = ' WHERE rom_flag = {int:romflag}';
$romflag = 0;
break;
case 2:
$where = ' WHERE rom_flag = {int:romflag}';
$romflag = 1;
break;
case 3:
$where = '';
$romflag = 0;
break;
default:
$romflag = 0;
if (allowedTo('arcade_view_retro_arch')) {
$where = '';
}
else {
$where = ' WHERE rom_flag = {int:romflag}';
}
}

$no_games = 8;
$icons_per_row = 4;
$mydisplays = true;
$check_game = !empty($_REQUEST['game']) ? (int) $_REQUEST['game'] : 0;
$no_games = !empty($check_game) ? 28 : 12;
$display = RandomArcadeDatum($no, $txtplay, $txtwin, $txtlate, $txtwit, $txton, $arcade_icon, $gameTypes, $no_games, $icons_per_row, $mydisplays, $check_game, $where, $romflag);

function RandomArcadeDatum($no, $txtplay, $txtwin, $txtlate, $txtwit, $txton, $arcade_icon, $gameTypes, $no_games, $icons_per_row, $mydisplays, $check_game, $where, $romflag)
{
global $settings, $scripturl, $sourcedir, $boardurl, $smcFunc, $arcadeModSettings, $boarddir;

if (!allowedTo('arcade_view') && $gameTypes == 0) {
return false;
}

$request = $smcFunc['db_query']('', '
SELECT  game.id_game, game.game_name, game.thumbnail, game.game_directory, game.rom_flag,
IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, {string:rname}) AS player_name, score.score
FROM {db_prefix}arcade_scores AS score
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = score.id_member)
RIGHT JOIN {db_prefix}arcade_games AS game ON (game.id_game = score.id_game)' . (str_replace('rom_flag', 'game.rom_flag', $where)) . '
ORDER BY champion_from DESC
LIMIT 0,1',
array('rname' => '???', 'romflag' => $romflag)
);
if(!$request)
  die("Could not get the newest champ");

$row = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);

if(isset($row['game_directory']))
  $row['game_directory'] = $row['game_directory'];

//newest champ details
$playerid = $row['id_member'];
$player = !empty($row['real_name']) ? $row['real_name'] : $row['player_name'];
$game_id = $row['id_game'];
$game_name = $row['game_name'];
$score = $row['score'];
$game_pic = (!empty($row['rom_flag']) ? $arcadeModSettings['romGamesUrl'] : $arcadeModSettings['gamesUrl']) . '/' . $row['game_directory'] . '/' . $row['thumbnail'];
$arcadePic = file_exists($settings['default_theme_dir'] . '/images/arc_icons/' . $arcade_icon) ? '<img style="border: 0px;height: 3em;width: 8em;" src="' . $settings['default_theme_url'] . '/images/arc_icons/' . $arcade_icon . '" alt="" />' : '<img style="border: 0px;height: 5em;width: 5em;" src="' . $settings['default_theme_url'] . '/images/arc_icons/thearcade.png" alt="" />';
$bp=ArcadeStats_BestPlayers($no);
$bp = !empty($bp) ? $bp : array();
for ($x=1;$x<11;$x++) {
$imgFile = file_exists($settings['default_theme_dir'] . '/images/arc_icons/' . $x . '.gif') ? $settings['default_theme_url'] . '/images/arc_icons/' . $x . '.gif' : $settings['default_theme_url'] . '/images/arc_icons/trophy.png';
$trophy[$x] = '<img src="' . $imgFile . '" border= "0" alt="#' . $x . ' Score" />';
}
$score_poss=0; //players position

echo '
<script type="text/javascript">
var delayb4scrollx = 2000;
var marqueespeedx = 1;
var pauseitx = 1;
var copyspeedx = marqueespeedx;
var pausespeedx = pauseitx == 0 ? copyspeedx : 0;
var actualheightx = "";

function scrollmarqueex(){
if (parseInt(cross_marqueex.style.top)>(actualheightx*(-1)+8))
cross_marqueex.style.top=parseInt(cross_marqueex.style.top)-copyspeedx+"px"
else
cross_marqueex.style.top=parseInt(marqueeheightx)+8+"px"
}

function initializemarqueex(){
cross_marqueex = document.getElementById("vmarqueex");
cross_marqueex.style.top = 0;
marqueeheightx = document.getElementById("marqueecontainerx").offsetHeight;
actualheightx = cross_marqueex.offsetHeight;
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){
cross_marqueex.style.height = marqueeheightx+"px";
cross_marqueex.style.overflow = "scroll";
return;
}
setTimeout('lefttime=setInterval("scrollmarqueex()",30)', delayb4scrollx);
}

if (window.addEventListener)
window.addEventListener("load", initializemarqueex, false);
else if (window.attachEvent)
window.attachEvent("onload", initializemarqueex);
else
window.onload = initializemarqueex();
</script>
<div style="overflow: hidden;">
<div style="display:table;width: 100%;text-align: center;overflow: hidden;">
<div style="display: table-row;">
<div style="display: table-cell;text-align: center;">
<span style="display: block;line-height: 1em;"></span>
<a href="', $scripturl, '?action=arcade">
', $arcadePic, '
</a>
<span style="display: block;line-height: 2em;"></span>
</div>
</div>
</div>
</div>';
if ($mydisplays == true || $check_game == true) {
/* Start 1 of 4 random stats display above top 10 marquee  */
$random_games_choice = random_int(1,4);
$games_choice = 'games'.$random_games_choice;
$curr_position = 0;
$games_choice($no_games,$curr_position,$icons_per_row, '', $no, $gameTypes, $where, $romflag);
/* END random stats display */
}
if ($check_game == false)
{
echo '
<div class="centertext" style="display: flex;justify-content: center;overflow: hidden;">
<div id="marqueecontainerx" style="position: relative; width: 100%; height:200px; overflow: hidden; border: 0px;" onmouseover="copyspeedx=pausespeedx" onmouseout="copyspeedx=marqueespeedx">
<div id="vmarqueex" style="position: absolute; width: 100%;">
<div class="centertext">
<a href="', $scripturl, '?action=arcade;sa=play;game=', $game_id, '">
<img src="' . $game_pic . '" border="0" alt="' . $game_name . '" style="width: 4em;height: 4em;"/>
</a>
<span style="display: block;line-height: 1em;"></span>', $txtlate, '<span style="display: block;line-height: 1em;"></span>
<a href="', $scripturl, '?action=profile;u=', $playerid, '">', $player, '</a>
<span style="display: block;line-height: 1em;"></span>
', $txtwit, ' ', $score, ' ', $txton, '
<span style="display: block;line-height: 1em;"></span>', $game_name, '
<span style="display: block;line-height: 1em;"></span>
<div style="width: 20%;margin: 0 auto;line-height: 0.2em;"><hr style="border-top: 1px dashed;" /></div>
<span style="display: block;line-height: 1em;"></span>
<span style="font: italic small-caps bold 12px/30px Georgia, serif;padding: 1em;">', $txtplay, '</span>
<span style="display: block;line-height: 2em;"></span>';
foreach ($bp as $out) {
$score_poss++;
if ($score_poss > 10)
$trophy[$score_poss] = '[' . $score_poss . ']';

echo $trophy[$score_poss], '
<span style="display: block;line-height: 1em;"></span>
' . $out['link'] . '
<span style="display: block;line-height: 1em;"></span>
' . $txtwin . ' ' . $out['champions'] . '
<span style="display: block;line-height: 1em;"></span>
<div style="width: 30%;margin: 0 auto;line-height: 0.2em;"><hr style="border-top: 1px dashed;" /></div>
<span style="display: block;line-height: 1em;"></span>';
}
}

echo '
</div>
</div>
</div>
</div>';
return true;
}

/* START - Display Functions */
function games3($no_games,$curr_position,$icons_per_row, $gamesUrl, $no, $gameTypes, $where, $romflag)
{
    //show the latest games
    global $smcFunc, $scripturl, $arcadeModSettings;

    echo '
    <div style="width: 100%;margin: 0 auto;text-align: center;overflow: hidden;">Latest Games
        <span style="display: block;line-height: 1em;"></span>
        <div style="display: table;border-spacing: 5px;margin: 0 auto;">
            <div style="display: table-row;">';

    $result = $smcFunc['db_query']('', '
        SELECT id_game, game_name, thumbnail, game_directory, rom_flag
        FROM {db_prefix}arcade_games' . $where . '
        ORDER BY id_game DESC, game_name DESC
        LIMIT 0,{int:no}',
        array(
            'no' => $no_games, 'romflag' => $romflag
        )
    );

    while ($game = $smcFunc['db_fetch_assoc']($result))
    {
$path = str_replace('', '/', (!empty($game['rom_flag']) ? $arcadeModSettings['romGamesDirectory'] : $arcadeModSettings['gamesDirectory']));
$filepath = rtrim($path, '/');
$gamesUrl = !empty($game['rom_flag']) ? $arcadeModSettings['romGamesUrl'] : $arcadeModSettings['gamesUrl'];
$action = !empty($game['rom_flag']) ? 'retro_arch' : 'arcade';
        $game_thumb = $gamesUrl . '/' . $game['game_directory'] . '/' . $game['thumbnail'];
        if($curr_position == $icons_per_row)
        {
            echo '
                </div>
                <div style="display: table-row;">';
            $curr_position=0;
        }
        echo'
                <div style="display: table-cell;padding: 2px;">
                    <a href="'.$scripturl.'?action=' . $action . ';sa=play;game='.$game['id_game'].'">
                    <img src="'.$game_thumb.'" alt="'.$game['game_name'].'" style="border: 0px;width: 30px;height: 30px;" title="Play '.$game['game_name'].'" /></a>
                </div>';
      $curr_position++;
  }
  $smcFunc['db_free_result']($result);

  echo '
            </div>
        </div>
    </div>';
}

function games1($no_games,$curr_position,$icons_per_row, $gamesUrl, $no, $gameTypes, $where, $romflag)
{
    //show most played games (one score version only)
    global $smcFunc, $scripturl, $arcadeModSettings;

    echo '
    <div style="width: 100%;margin: 0 auto;text-align: center;overflow: hidden;">Most Played
        <span style="display: block;line-height: 1em;"></span>
        <div style="display: table;border-spacing: 5px;margin: 0 auto;">
            <div style="display: table-row;">';

    $result = $smcFunc['db_query']('', '
        SELECT id_game, game_name, thumbnail, game_directory, rom_flag, num_plays
        FROM {db_prefix}arcade_games' . $where . '
        ORDER BY num_plays DESC , game_name ASC
        LIMIT 0,{int:no}',
        array(
            'no' => $no_games, 'romflag' => $romflag,
        )
    );

    while ($game = $smcFunc['db_fetch_assoc']($result))
    {
$path = str_replace('', '/', (!empty($game['rom_flag']) ? $arcadeModSettings['romGamesDirectory'] : $arcadeModSettings['gamesDirectory']));
$filepath = rtrim($path, '/');
$gamesUrl = !empty($game['rom_flag']) ? $arcadeModSettings['romGamesUrl'] : $arcadeModSettings['gamesUrl'];
$action = !empty($game['rom_flag']) ? 'retro_arch' : 'arcade';
        $game_thumb = $gamesUrl . '/' . $game['game_directory'] . '/' . $game['thumbnail'];
        if($curr_position == $icons_per_row)
        {
            echo '
                </div>
                <div style="display: table-row;">';
            $curr_position=0;
        }
        echo'
                <div style="display: table-cell;padding: 2px;">
                    <a href="'.$scripturl.'?action=' . $action . ';sa=play;game='.$game['id_game'].'">
                    <img src="'.$game_thumb.'" alt="'.$game['game_name'].'" style="border: 0px;width: 30px;height: 30px;" title="Play '.$game['game_name'].'" /></a>
                </div>';
        $curr_position++;
    }

    $smcFunc['db_free_result']($result);

  echo '
            </div>
        </div>
    </div>';
}

function games4($no_games,$curr_position,$icons_per_row, $gamesUrl, $no, $gameTypes, $where, $romflag)
{
  //show least played games (one score version only)
  global $smcFunc, $scripturl, $arcadeModSettings;

  echo '
    <div style="width: 100%;margin: 0 auto;text-align: center;overflow: hidden;">Least Played
        <span style="display: block;line-height: 1em;"></span>
        <div style="display: table;border-spacing: 5px;margin: 0 auto;">
            <div style="display: table-row;">';

    $result = $smcFunc['db_query']('', '
        SELECT id_game, game_name, thumbnail, game_directory, num_plays, rom_flag
        FROM {db_prefix}arcade_games' . $where . '
        ORDER BY num_plays ASC , game_name ASC
        LIMIT 0,{int:no}',
        array(
            'no' => $no_games, 'romflag' => $romflag,
        )
    );

    while ($game = $smcFunc['db_fetch_assoc']($result))
    {
$path = str_replace('', '/', (!empty($game['rom_flag']) ? $arcadeModSettings['romGamesDirectory'] : $arcadeModSettings['gamesDirectory']));
$filepath = rtrim($path, '/');
$gamesUrl = !empty($game['rom_flag']) ? $arcadeModSettings['romGamesUrl'] : $arcadeModSettings['gamesUrl'];
$action = !empty($game['rom_flag']) ? 'retro_arch' : 'arcade';
        $game_thumb = $gamesUrl . '/' . $game['game_directory'] . '/' . $game['thumbnail'];
        if($curr_position == $icons_per_row)
        {
            echo '
                </div>
                <div style="display: table-row;">';
            $curr_position=0;
        }
        echo '
                <div style="display: table-cell;padding: 2px;">
                    <a href="'.$scripturl.'?action=' . $action . ';sa=play;game='.$game['id_game'].'">
                    <img src="'.$game_thumb.'" alt="'.$game['game_name'].'" style="border: 0px;width: 30px;height: 30px;" title="Play '.$game['game_name'].'" /></a>
                </div>';
        $curr_position++;
    }
    $smcFunc['db_free_result']($result);

  echo '
            </div>
        </div>
    </div>';
}

function games2($no_games,$curr_position,$icons_per_row, $gamesUrl, $no, $gameTypes, $where, $romflag)
{
    //show best rated games
    global $smcFunc, $scripturl, $arcadeModSettings;

    echo '
    <div style="width: 100%;margin: 0 auto;text-align: center;overflow: hidden;">Top Rated
    <span style="display: block;line-height: 1em;"></span>
        <div style="display: table;border-spacing: 5px;margin: 0 auto;">
            <div style="display: table-row;">';

    $result = $smcFunc['db_query']('', '
        SELECT id_game, game_name, thumbnail, game_directory, game_rating, rom_flag
        FROM {db_prefix}arcade_games' . $where . '
        ORDER BY game_rating DESC , game_name ASC
        LIMIT 0,{int:no}',
        array(
            'no' => $no_games, 'romflag' => $romflag,
        )
    );

    while ($game = $smcFunc['db_fetch_assoc']($result))
    {
$path = str_replace('', '/', (!empty($game['rom_flag']) ? $arcadeModSettings['romGamesDirectory'] : $arcadeModSettings['gamesDirectory']));
$filepath = rtrim($path, '/');
$gamesUrl = !empty($game['rom_flag']) ? $arcadeModSettings['romGamesUrl'] : $arcadeModSettings['gamesUrl'];
$action = !empty($game['rom_flag']) ? 'retro_arch' : 'arcade';
        $game_thumb = $gamesUrl . '/' . $game['game_directory'] . '/' . $game['thumbnail'];
        if($curr_position == $icons_per_row)
        {
            echo '</div><div style="display: table-row;">';
            $curr_position=0;
        }
        echo'
                <div style="display: table-cell;padding: 2px;">
                    <a href="'.$scripturl.'?action=' . $action . ';sa=play;game='.$game['id_game'].'">
                    <img src="'.$game_thumb.'" alt="'.$game['game_name'].'" style="border: 0px;width: 30px;height: 30px;" title="Play '.$game['game_name'].'" /></a>
                </div>';
        $curr_position++;
    }

    $smcFunc['db_free_result']($result);

  echo '
            </div>
        </div>
    </div>';
}

Dave

#1
Thanks very much Chen. Nice touch also to only have high scores and to allow changing the type of games showing.
If you want play quizzes or games click below


Click me to play Quizland Radio