High Scores/Stats Block

Started by Chen Zhen, July 06, 2013, 03:09:31 PM

previous topic - next topic

Chen Zhen

July 06, 2013, 03:09:31 PM Last Edit: July 06, 2013, 03:11:41 PM by underdog
PHP Portal Block Code For SMF Arcade 2.5

Download the attached zip archive named block_pics.zip
...and using your FTP platform - add the graphic files contained in it to:
Themes / default / images / arc_icons


<<<<<<<<<<>>>>>>>>>>

High Scores/Stats PHP Block:

There is an adjustable setting near the start of the block to select if you want to display high scores only:
Code Select

$mydisplays = true;  /* True = Show random display prior to scores, False = Show high scores and only show random display if playing game  */


PHP Block Code:
Code Select

/* High score/stats block for SMF 2.0 Rcx and SMF Arcade v2.5
   Upload a pic called arcade_block.gif (you can use you own gif - just name it arcade_block.gif)
   and upload cup pics... 1.gif, 2.gif, 3.gif, 4.gif, 5.gif, 6.gif, 7.gif, 8.gif, 9.gif, 10.gif
   to your /Themes/default/images/arc_icons/

   -- SETUP EDITS ---   */

$no = 10; /* number of top players to show  */
$no_games = 8; /* Set total number of games to display  */
$icons_per_row = 4;  /*  Set games per row  */
$mydisplays = true;  /* True = Show random display prior to scores, False = Only show random display if playing game  */

/*  If playing a game... Display more game icons while not displaying marquee to improve performance */
$check_game = !empty($_REQUEST['game']) ? (int) $_REQUEST['game'] : 0;
if ($check_game == true) {$no_games = 28;}

// --LANGUAGE EDITS --
$txtplay = "The Top Players";
$txtwin = "Number Of Wins :";
$txtlate = "Latest High Score by ";
$txtwit = "with ";
$txton = "on ";

global $scripturl,$sourcedir,$boardurl,$smcFunc,$modSettings;
require_once($sourcedir.'/ArcadeStats.php');


$gamesUrl = (str_replace($boardurl . '/', '', $modSettings['gamesUrl'])) . '/';     

/* Get newest champ or die */
$sql = "SELECT  game.id_game, game.game_name, game.thumbnail, game.game_directory,
             IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name,'') AS real_name, score.score
        FROM {db_prefix}arcade_scores AS score
           LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = score.id_member)
              JOIN {db_prefix}arcade_games AS game ON (game.id_game = score.id_game)
        ORDER BY `champion_from` DESC
        LIMIT 0,1";
if(!($request = $smcFunc['db_query']('', $sql)))
{
   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 = $row['real_name'];
$game_id = $row['id_game'];
$game_name = $row['game_name'];
$score = $row['score'];
$game_pic = $boardurl.'/'.$gamesUrl.$row['game_directory'].$row['thumbnail'];
if ($score == 1e+06)
{ $score = 1000000; }
$bp=ArcadeStats_BestPlayers($no);
if ($check_game == false)
{
$trophy[1] = '<img src="'.$boardurl. '/Themes/default/images/arc_icons/1.gif" border= "0" alt="Gold" />';
$trophy[2]= '<img src="'.$boardurl.'/Themes/default/images/arc_icons/2.gif" border= "0" alt="Silver" />';
$trophy[3] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/3.gif" border= "0" alt="Bronze" />';
$trophy[4] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/4.gif" border= "0" alt="Fourth Place" />';
$trophy[5] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/5.gif" border= "0" alt="Fifth Place" />';
$trophy[6] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/6.gif" border= "0" alt="Sixth Place" />';
$trophy[7] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/7.gif" border= "0" alt="Seventh Place" />';
$trophy[8] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/8.gif" border= "0" alt="Eighth Place" />';
$trophy[9] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/9.gif" border= "0" alt="Ninth Place" />';
$trophy[10] = '<img src="'.$boardurl.'/Themes/default/images/arc_icons/10.gif" border= "0" alt="Tenth Place" />';
$score_poss=0; //players position

?>

<script type="text/javascript">

/***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scrollx=2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeedx=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseitx=1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

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){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
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 if (document.getElementById)
window.onload=initializemarqueex

</script>
<?php
}
echo 
'<table summary="arcspblock1" width="100%"><tr><td align="center"><a href="',$scripturl,'?action=arcade"><img src="',$boardurl,'/Themes/default/images/arc_icons/arcade_block.gif" border= "0" alt="Arcade" /></a>
               <br />
            </td>
         </tr>
      </table>'
;

if (
$mydisplays == true || $check_game == true)
{
/* Start 1 of 4 random stats display above top 10 marquee  */
$random_games_choice rand(1,4);
$games_choice 'games'.$random_games_choice;
$curr_position 0;
$games_choice($no_games,$curr_position,$icons_per_row$gamesUrl,$no);
/* END random stats display */ 
}
if (
$check_game == false)
{
echo 
'

      <div id="marqueecontainerx" style="position: relative; width: 95%; height:200px; overflow: hidden; border: 0px; padding: 2px; padding-left: 4px;" onmouseover="copyspeedx=pausespeedx" onmouseout="copyspeedx=marqueespeedx">
         <div id="vmarqueex" style="position: absolute; width: 98%;">
            <div align="center">
               <a href="'
,$scripturl,'?action=arcade;sa=play;game=',$game_id,'"><img src="' $game_pic '" border="0" alt="',$game_name,'" width="60" height="60"/></a>
               <br />'
,$txtlate,'<br />
               <a href="'
,$scripturl,'?action=profile;u=',$playerid,'">',$player,'</a>
               <br/>'
,$txtwit,' ',$score,' ',$txton,'<br />',$game_name,'
               <br />------------------<br />'
,$txtplay,'<br /><br />';
               foreach (
$bp as $out)
               {
                  
$score_poss++;
                 if (
$score_poss 10)
                    {               
                       
$trophy[$score_poss] ='['.$score_poss.']';
                    }
                  echo 
''.$trophy[$score_poss].'<br />'.$out['link'].'<br />'.$txtwin.' '.$out['champions'].'
                       <br /><br />'
;
               };
   echo 
'</div>
         </div>
      </div>'
;
}
/* START - Display Functions */
Function games3($no_games,$curr_position,$icons_per_row$gamesUrl,$no)
{
   global 
$smcFunc$scripturl;
   
//show the latest games
   
echo '<div align="center">Latest Games<br />
   <table cellpadding="2" cellspacing="5">
   <tr>'
;
   
      
$result $smcFunc['db_query']('''
      SELECT id_game, game_name, thumbnail, game_directory
      FROM {db_prefix}arcade_games
      ORDER BY id_game DESC, game_name DESC
      LIMIT 0,{int:no}'
,
         array(
         
'no' => $no_games,
         )
      );
      
      while (
$game $smcFunc['db_fetch_assoc']($result))
      {

      
$game_thumb $boardurl '/' $gamesUrl.$game['game_directory']."/".$game['thumbnail'];
      if(
$curr_position == $icons_per_row)
      {
         echo 
'</tr><tr>';
         
$curr_position=0;
      }
      echo
'
      <td>
      <a href="'
.$scripturl.'?action=arcade;sa=play;game='.$game['id_game'].'">
      <img src="'
.$game_thumb.'" border="0" alt="'.$game['game_name'].'" width="30" height="30" title="Play '.$game['game_name'].'" /></a>
      </td>'
;
      
$curr_position++;
   }
   
$smcFunc['db_free_result']($result);

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

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

   echo 
'<div align="center">Most Played<br />
   <table cellpadding="2" cellspacing="5">
   <tr>'
;

    
$result $smcFunc['db_query']('''
      SELECT id_game, game_name, thumbnail, game_directory, num_plays
      FROM {db_prefix}arcade_games
      ORDER BY num_plays DESC , game_name ASC
      LIMIT 0,{int:no}'
,
         array(
         
'no' => $no_games,
         )
      );
      
      while (
$game $smcFunc['db_fetch_assoc']($result))
      {
      
$game_thumb $boardurl '/' $gamesUrl.$game['game_directory']."/".$game['thumbnail'];
      if(
$curr_position == $icons_per_row)
      {
         echo 
'</tr><tr>';
         
$curr_position=0;
      }
      echo
'
      <td>
      <a href="'
.$scripturl.'?action=arcade;sa=play;game='.$game['id_game'].'">
      <img src="'
.$game_thumb.'" border="0" alt="'.$game['game_name'].'" width="30" height="30" title="Play '.$game['game_name'].'" /></a>
      </td>'
;
      
$curr_position++;
   }
   
$smcFunc['db_free_result']($result);

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


Function 
games4($no_games,$curr_position,$icons_per_row$gamesUrl,$no)
{
   
//show least played games (one score version only)
   
global $smcFunc$scripturl;
   echo 
'<div align="center">Least Played<br />
   <table cellpadding="2" cellspacing="5">
   <tr>'
;

    
$result $smcFunc['db_query']('''
      SELECT id_game, game_name, thumbnail, game_directory, num_plays
      FROM {db_prefix}arcade_games
      ORDER BY num_plays ASC , game_name ASC
      LIMIT 0,{int:no}'
,
         array(
         
'no' => $no_games,
         )
      );
      
      while (
$game $smcFunc['db_fetch_assoc']($result))
      {
      
$game_thumb $boardurl '/' $gamesUrl.$game['game_directory']."/".$game['thumbnail'];
      if(
$curr_position == $icons_per_row)
      {
         echo 
'</tr><tr>';
         
$curr_position=0;
      }
      echo
'
      <td>
      <a href="'
.$scripturl.'?action=arcade;sa=play;game='.$game['id_game'].'">
      <img src="'
.$game_thumb.'" border="0" alt="'.$game['game_name'].'" width="30" height="30" title="Play '.$game['game_name'].'" /></a>
      </td>'
;
      
$curr_position++;
   }
     
$smcFunc['db_free_result']($result);

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


Function 
games2($no_games,$curr_position,$icons_per_row$gamesUrl,$no)
{
   
//show best rated games
    
global $smcFunc$scripturl;
   echo 
'<div align="center">Top Rated<br />
   <table cellpadding="2" cellspacing="5">
   <tr>'
;

    
$result $smcFunc['db_query']('''
      SELECT id_game, game_name, thumbnail, game_directory, game_rating
      FROM {db_prefix}arcade_games
      ORDER BY game_rating DESC , game_name ASC
      LIMIT 0,{int:no}'
,
         array(
         
'no' => $no_games,
         )
      );
      
      while (
$game $smcFunc['db_fetch_assoc']($result))
      {
      
$game_thumb $boardurl '/' $gamesUrl.$game['game_directory']."/".$game['thumbnail'];
      if(
$curr_position == $icons_per_row)
      {
         echo 
'</tr><tr>';
         
$curr_position=0;
      }
      echo
'
      <td>
      <a href="'
.$scripturl.'?action=arcade;sa=play;game='.$game['id_game'].'">
      <img src="'
.$game_thumb.'" border="0" alt="'.$game['game_name'].'" width="30" height="30" title="Play '.$game['game_name'].'" /></a>
      </td>'
;
      
$curr_position++;
   }
   
$smcFunc['db_free_result']($result);

   echo 
'
   </tr>
   </table></div>'
;
}
/* END - Display Functions  */      
/* END - High Score/Stats Block For SMF 2.0 Rcx */


If there is an issue with the block code provided in the code tags shown above, download the block code text file & use its contents.