SimplePortal
Customization => Custom Coding => Topic started by: Nabil on December 05, 2008, 07:06:09 AM
-
This is just a simple php code in which you can use to display some Games in the Arcade
we have to give the Names and Numbers of the Games wished to be displayed in the Block, I have chosen 3 games , but the code can be changed of course to display more games.
just add a php Block ,give it the name you wish and include the following Code
<?php
//// PROVIDE NAMES AND NUMBERS OF THE GAMES //////
$game1="Warehouse"; $g1number=23;
$game2="Poux"; $g2number=28;
$game3="zz_3_Foot_Ninja"; $g3number=21;
/////////////// END //////////////////////////////
$directory=dir("Games") or die ("Error");
echo "<div style='margin-top:10px' align='center'>";
while($datei=$directory->read()){
if ($datei=="." || $datei==".."){ continue; };
$directory2=dir('Games/'.$datei) or die ("Error");
while($datei2=$directory2->read()){
if ($datei2=="." || $datei2==".."){ continue; };
if (preg_match('/.gif/',$datei2)){
$subfolder="Games"."/".$datei."/".$datei2;
$data=substr($datei2,0,-4);
$swfdata="Games"."/".$data."/".$data.".swf";
if ($data==$game1 || $data==$game2 || $data==$game3){
$counter+=1;
if ($data==$game1) { $gnumber=$g1number; };
if ($data==$game2) { $gnumber=$g2number; };
if ($data==$game3) { $gnumber=$g3number; };
echo "<div style='margin:5px'><a href='index.php?action=arcade;sa=play;game=$gnumber' >
<img src='$subfolder' ><br>$data</a></div>";
} else { continue; }
}
}
}
echo "</div>";
?>
the Names and Numbers of the Games written above in the code should be changed according to your Games Names and Numbers , the Code is based on the fact that the
Games are stored in the 'Games' Folder , and it should have an swf data (flash File) and
also an image of the game with same Name in 'gif' .
if Someone clicks on the Games , it will be played or not played according to your Settings , for Guests and Members.
-
A random selection of games would be very nice, maybe when I'm not feeling lazy I can work on this
-
A random selection of games would be very nice, maybe when I'm not feeling lazy I can work on this
Here is a Random Selection , which I have finished Today ..
<?php
//////////// CONNECTION TO DATABASE ////////////////////////
mysql_connect("localhost or Server ID","User ID ","Password") or die("Could not connect : ".mysql_error());
mysql_select_db("Database Name") or die("could not select database");
/////////// FINDING HOW MANY GAMES STORED //////////////////
$query = mysql_query("SELECT * FROM smf_arcade_games");
$numberOfGames=mysql_num_rows($query);
$numberOfGames=$numberOfGames-1;
/*echo 'Number of Games are : '.$numberOfGames."<br><br>"; */
/////////////////// RANDOM NUMBERS ACCORDING TO NUMBER OF GAMES ////////
srand(time());
$random1 = (rand()%$numberOfGames);
while(1){
$random2 = (rand()%$numberOfGames);
if ($random2!=$random1 ){
break;
}
};
while(1){
$random3 = (rand()%$numberOfGames);
if ($random3!=$random1 && $random3!=$random2 ){
break;
}
};
$i=-1; $count1=0;
$ask=mysql_query("SELECT internalName FROM smf_arcade_games");
while($row = mysql_fetch_array($ask, MYSQL_ASSOC)){
$i+=1;
if ($i==$random1){
$game1=$row[internalName]; $count1+=1;
}
if ($i==$random2){
$game2=$row[internalName]; $count1+=1;
}
if ($i==$random3){
$game3=$row[internalName]; $count1+=1;
}
if ($count1==3){
break;
}
};
/////////////// GET THE GAMES IDs //////////////////
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game1'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC) or die (mysql_error());
$g1number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game2'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g2number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g3number=$row[ID_GAME];
//// Finding The Games in The Directory And Displaying Them /////////
$directory=dir("Games") or die ("Error");
echo "<div style='margin-top:10px' align='center'>";
$Dir1='Games/'.$game1.'/'.$game1.'.gif';
$Dir2='Games/'.$game2.'/'.$game2.'.gif';
$Dir3='Games/'.$game3.'/'.$game3.'.gif';
echo "<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g1number'>
<img src='$Dir1' ><br>$game1</a></div>
<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g2number'>
<img src='$Dir2' ><br>$game2</a></div>
<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g3number'>
<img src='$Dir3' ><br>$game3</a></div></div>";
?>
Dont Forget to Insert The Server ID , User ID , Password and Database Name Above
-
the db connection is uneeded and the $Dir is invalid if you installed the games with gamepack
-
the db connection is uneeded
yes if there is a previous DB Connection , which I think there is in settings.php
the $Dir is invalid if you installed the games with gamepack
I'm supposing that every game has its own folder inside the 'Games' folder which is Standard I think , because if you use the Upload Possibility within the Mod it will move the Game's zip data into the 'Games' Folder and unpack it there creating a normal folder of the Game inside the Games folder.
-
I understand that but I took the fast route and downloaded all the games from the arcade website in the gamepacks which installed 5-10 games at a time and created individual folders inside of a folder for each gamepack. Some how the standard arcade block with simpleportal can handle this. I will figure it out when I get on my other computer with the files.
-
I couldnt get the first php code to work. I renamed the games, however it the numbers i dont get. I checked my forum for game numbers and there is none.
-
Add $db_prefix to globals and you can use db_query() function in your block codes; no need to re-connect to database.
-
yes you can ignore the first 2 lines in the Code regarding DB Connection .
i dont get. I checked my forum for game numbers and there is none.
Every game has a Number but it is saved in the Data Base.
in order to let the above Code work you should customise the Code to suit your Directory where the games are stored , if the files are stored directly in the game's folder change :
$Dir1='Games/'.$game1.'/'.$game1.'.gif';
$Dir2='Games/'.$game2.'/'.$game2.'.gif';
$Dir3='Games/'.$game3.'/'.$game3.'.gif';
to
$Dir1='Games/'.$game1.'.gif';
$Dir2='Games/'.$game2.'.gif';
$Dir3='Games/'.$game3.'.gif';
the above Code is based on the fact that every Game has a .gif file with the same name as the .swf file.
3 games will be chosen randomly
-
I applied the changes you stated, buy something went wrong, because the board message stated could not connect. Im assuming to the database! In addition my entire portal home page only had the one arcade block. (as if the dimensions were so large it pushed or removed all other blocks.)
Can you check the following to see if I left something undone or incomplete.
<?php
//////////// CONNECTION TO DATABASE ////////////////////////
mysql_connect("localhost or Server ID","User ID ","Password") or die("Could not connect : ".mysql_error());
mysql_select_db("Database Name") or die("could not select database");
/////////// FINDING HOW MANY GAMES STORED //////////////////
$query = mysql_query("SELECT * FROM smf_arcade_games");
$numberOfGames=mysql_num_rows($query);
$numberOfGames=$numberOfGames-1;
/*echo 'Number of Games are : '.$numberOfGames."<br><br>"; */
/////////////////// RANDOM NUMBERS ACCORDING TO NUMBER OF GAMES ////////
srand(time());
$random1 = (rand()%$numberOfGames);
while(1){
$random2 = (rand()%$numberOfGames);
if ($random2!=$random1 ){
break;
}
};
while(1){
$random3 = (rand()%$numberOfGames);
if ($random3!=$random1 && $random3!=$random2 ){
break;
}
};
$i=-1; $count1=0;
$ask=mysql_query("SELECT internalName FROM smf_arcade_games");
while($row = mysql_fetch_array($ask, MYSQL_ASSOC)){
$i+=1;
if ($i==$random1){
$game1=$row[internalName]; $count1+=1;
}
if ($i==$random2){
$game2=$row[internalName]; $count1+=1;
}
if ($i==$random3){
$game3=$row[internalName]; $count1+=1;
}
if ($count1==3){
break;
}
};
/////////////// GET THE GAMES IDs //////////////////
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game1'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC) or die (mysql_error());
$g1number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game2'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g2number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g3number=$row[ID_GAME];
//// Finding The Games in The Directory And Displaying Them /////////
$directory=dir("Games") or die ("Error");
echo "<div style='margin-top:10px' align='center'>";
$Dir1='Games/'.$donkeykong.'.gif';
$Dir2='Games/'.$duckhunt.'.gif';
$Dir3='Games/'.$invaders.'.gif';
echo "<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g1number'>
<img src='$Dir1' ><br>$game1</a></div>
<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g2number'>
<img src='$Dir2' ><br>$game2</a></div>
<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g3number'>
<img src='$Dir3' ><br>$game3</a></div></div>";
?>
-
you have to remove this
//////////// CONNECTION TO DATABASE ////////////////////////
mysql_connect("localhost or Server ID","User ID ","Password") or die("Could not connect : ".mysql_error());
mysql_select_db("Database Name") or die("could not select database");
and also you should not write this
$Dir1='Games/'.$donkeykong.'.gif';
$Dir2='Games/'.$duckhunt.'.gif';
$Dir3='Games/'.$invaders.'.gif';
but this (if the games gif files were directly saved in the Game's Directory )
$Dir1='Games/'.$game1.'.gif';
$Dir2='Games/'.$game2.'.gif';
$Dir3='Games/'.$game3.'.gif';
-
I followed your instructions and used that block and it kills my home page. It might be my theme that I am using. But when I apply that php block with the code following your instructions it doenst work. The arcade block wont show and all other blocks vanish.
-
now we have to ask the following questions :
are you sure that there are Games Installed? , if yes are they saved in the table smf_arcade_games of your Database ?
'smf_arcade_games' is the Standard name where game's Names are stored .
if you have givin your smf prefix another name than the Standard prefix (smf_ ) then this Code wont work
look in your Data base and see if there is a table with the name 'smf_arcade_games' .
-
no it is a different prefix
-
what is the name of the Table where you games are saved in the Data base ?
-
Thanks for this block !!
i've made some little change but it's working
is it possible to have more info in Arcade Block ?
top rated Games ?
last added Games ?
-
is it possible to have more info in Arcade Block ?
top rated Games ?
last added Games ?
use this Code to add Total Games, Top Rated Game , Latest Game
<?php
/////////// FINDING HOW MANY GAMES STORED //////////////////
$query = mysql_query("SELECT * FROM smf_arcade_games");
$numberOfGames=mysql_num_rows($query);
$numberOfGames=$numberOfGames-1;
/*echo 'Number of Games are : '.$numberOfGames."<br><br>"; */
/////////////////// RANDOM NUMBERS ACCORDING TO NUMBER OF GAMES ////////
srand(time());
$random1 = (rand()%$numberOfGames);
while(1){
$random2 = (rand()%$numberOfGames);
if ($random2!=$random1 ){
break;
}
};
while(1){
$random3 = (rand()%$numberOfGames);
if ($random3!=$random1 && $random3!=$random2 ){
break;
}
};
$i=-1; $count1=0;
$ask=mysql_query("SELECT internalName FROM smf_arcade_games");
while($row = mysql_fetch_array($ask, MYSQL_ASSOC)){
$i+=1;
if ($i==$random1){
$game1=$row[internalName]; $count1+=1;
}
if ($i==$random2){
$game2=$row[internalName]; $count1+=1;
}
if ($i==$random3){
$game3=$row[internalName]; $count1+=1;
}
if ($count1==3){
break;
}
};
/////////////// GET THE GAMES IDs //////////////////
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game1'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC) or die (mysql_error());
$g1number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game2'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g2number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g3number=$row[ID_GAME];
//// Finding The Games in The Directory And Displaying Them /////////
$directory=dir("Games") or die ("Error");
echo "<div style='margin-top:10px' align='center'>";
$Dir1='Games/'.$game1.'.gif';
$Dir2='Games/'.$game2.'.gif';
$Dir3='Games/'.$game3.'.gif';
//////////// Which one is Highly Rated /////////////////////
$searchedGame=""; $rated=0;
$gamesdir1=opendir("Games");
while($file2=readdir($gamesdir1)){
if (substr($file2,-3)!='swf') { continue; };
$thegame=substr($file2,0,-4);
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$thegame'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC); $gameid1=$row[ID_GAME];
$ask1=mysql_query("SELECT rating FROM smf_arcade_rates WHERE ID_GAME='$gameid1'");
$row = mysql_fetch_array($ask1, MYSQL_ASSOC); $theRate=$row[rating];
if ($rated<$theRate){$rated=$theRate; $ratedGame1=$thegame; $searchedGameid=$gameid1; }
};
closedir($gamesdir1); $Dir4='Games/'.$ratedGame1.'.gif';
/// The Last Game Added is in the Last Row of the Table ////////
$totalgames=$numberOfGames+1;
$ask=mysql_query("SELECT ID_GAME,internalName FROM smf_arcade_games LIMIT $numberOfGames,1");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$latestGname=$row[internalName]; $latestGid=$row[ID_GAME];
$Dir5='Games/'.$latestGname.'.gif';
echo "<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g1number'>
<img src='$Dir1' ><br>$game1</a></div>
<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g2number'>
<img src='$Dir2' ><br>$game2</a></div>
<div style='margin:10px'><a href='index.php?action=arcade;sa=play;game=$g3number'>
<img src='$Dir3' ><br>$game3</a></div>
<hr width='90%'>
<div style='margin:10px'>
<b>Total Games</b><br>
$totalgames</div>
<div style='margin:10px'>
<b>Top Rated Game</b><br>
<a href='index.php?action=arcade;sa=play;game=$searchedGameid'>
<img src='$Dir4' style='margin-top:5px'><br>$ratedGame1</a></div>
<div style='margin:10px'>
<b>Latest Game</b><br>
<a href='index.php?action=arcade;sa=play;game=$latestGid'>
<img src='$Dir5' style='margin-top:5px'><br>$latestGname</a></div>
</div>";
?>
if you want to display only the 3 information above then use this Code :
<?php
/////////// FINDING HOW MANY GAMES STORED //////////////////
$query = mysql_query("SELECT * FROM smf_arcade_games");
$numberOfGames=mysql_num_rows($query);
$numberOfGames=$numberOfGames-1;
/*echo 'Number of Games are : '.$numberOfGames."<br><br>"; */
/////////////////// RANDOM NUMBERS ACCORDING TO NUMBER OF GAMES ////////
srand(time());
$random1 = (rand()%$numberOfGames);
while(1){
$random2 = (rand()%$numberOfGames);
if ($random2!=$random1 ){
break;
}
};
while(1){
$random3 = (rand()%$numberOfGames);
if ($random3!=$random1 && $random3!=$random2 ){
break;
}
};
$i=-1; $count1=0;
$ask=mysql_query("SELECT internalName FROM smf_arcade_games");
while($row = mysql_fetch_array($ask, MYSQL_ASSOC)){
$i+=1;
if ($i==$random1){
$game1=$row[internalName]; $count1+=1;
}
if ($i==$random2){
$game2=$row[internalName]; $count1+=1;
}
if ($i==$random3){
$game3=$row[internalName]; $count1+=1;
}
if ($count1==3){
break;
}
};
/////////////// GET THE GAMES IDs //////////////////
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game1'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC) or die (mysql_error());
$g1number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game2'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g2number=$row[ID_GAME];
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$g3number=$row[ID_GAME];
//// Finding The Games in The Directory And Displaying Them /////////
$directory=dir("Games") or die ("Error");
echo "<div style='margin-top:10px' align='center'>";
$Dir1='Games/'.$game1.'.gif';
$Dir2='Games/'.$game2.'.gif';
$Dir3='Games/'.$game3.'.gif';
//////////// Which one is Highly Rated /////////////////////
$searchedGame=""; $rated=0;
$gamesdir1=opendir("Games");
while($file2=readdir($gamesdir1)){
if (substr($file2,-3)!='swf') { continue; };
$thegame=substr($file2,0,-4);
$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$thegame'");
$row = mysql_fetch_array($ask, MYSQL_ASSOC); $gameid1=$row[ID_GAME];
$ask1=mysql_query("SELECT rating FROM smf_arcade_rates WHERE ID_GAME='$gameid1'");
$row = mysql_fetch_array($ask1, MYSQL_ASSOC); $theRate=$row[rating];
if ($rated<$theRate){$rated=$theRate; $ratedGame1=$thegame; $searchedGameid=$gameid1; }
};
closedir($gamesdir1); $Dir4='Games/'.$ratedGame1.'.gif';
/// The Last Game Added is in the Last Row of the Table ////////
$totalgames=$numberOfGames+1;
$ask=mysql_query("SELECT ID_GAME,internalName FROM smf_arcade_games LIMIT $numberOfGames,1");
$row = mysql_fetch_array($ask, MYSQL_ASSOC);
$latestGname=$row[internalName]; $latestGid=$row[ID_GAME];
$Dir5='Games/'.$latestGname.'.gif';
echo "
<div style='margin-top:-2px'>
<b>Total Games</b><br>
$totalgames</div>
<div style='margin:10px'>
<b>Top Rated Game</b><br>
<a href='index.php?action=arcade;sa=play;game=$searchedGameid'>
<img src='$Dir4' style='margin-top:5px'><br>$ratedGame1</a></div>
<div style='margin:10px'>
<b>Latest Game</b><br>
<a href='index.php?action=arcade;sa=play;game=$latestGid'>
<img src='$Dir5' style='margin-top:5px'><br>$latestGname</a></div>
</div>";
?>
-
I hate to bump such an old topic but the code in the final reply appears to be for SMF 1.x? It does not work in 2.0.2... would love to find something that does...
-
You do realise there is an arcade block already?