SimplePortal

Customization => Custom Coding => Topic started by: Nabil on December 05, 2008, 07:06:09 AM

Title: an alternative to smf Arcade Block
Post 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
Code: [Select]
<?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.

 
Title: Re: an alternative to smf Arcade Block
Post by: hot rides on December 05, 2008, 10:48:51 AM
A random selection of games would be very nice, maybe when I'm not feeling lazy I can work on this
Title: Re: an alternative to smf Arcade Block
Post by: Nabil on December 05, 2008, 03:21:14 PM
Quote
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 ..

Code: [Select]
<?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($askMYSQL_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($askMYSQL_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($askMYSQL_ASSOC);
$g2number=$row[ID_GAME];

$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row mysql_fetch_array($askMYSQL_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



Title: Re: an alternative to smf Arcade Block
Post by: hot rides on December 07, 2008, 10:40:59 PM
the db connection is uneeded and the $Dir is invalid if you installed the games with gamepack
Title: Re: an alternative to smf Arcade Block
Post by: Nabil on December 08, 2008, 12:08:30 PM
Quote
the db connection is uneeded

yes if there is a previous DB Connection , which I think there is in settings.php

Quote
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.

Title: Re: an alternative to smf Arcade Block
Post by: hot rides on December 08, 2008, 08:07:32 PM
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.
Title: Re: an alternative to smf Arcade Block
Post by: jb3398 on December 31, 2008, 10:22:10 PM
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.
Title: Re: an alternative to smf Arcade Block
Post by: [SiNaN] on January 01, 2009, 08:51:36 AM
Add $db_prefix to globals and you can use db_query() function in your block codes; no need to re-connect to database.
Title: Re: an alternative to smf Arcade Block
Post by: Nabil on January 01, 2009, 09:12:16 AM
yes you can ignore the first 2 lines in the Code regarding DB Connection .

Code: [Select]
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





Title: Re: an alternative to smf Arcade Block
Post by: jb3398 on January 01, 2009, 12:43:35 PM
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>";

?>

Title: Re: an alternative to smf Arcade Block
Post by: Nabil on January 01, 2009, 01:19:39 PM
you have to remove this
Code: [Select]
//////////// 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
Quote
$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 )
Code: [Select]
$Dir1='Games/'.$game1.'.gif';
$Dir2='Games/'.$game2.'.gif';
$Dir3='Games/'.$game3.'.gif';
Title: Re: an alternative to smf Arcade Block
Post by: jb3398 on January 01, 2009, 01:52:53 PM
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.
Title: Re: an alternative to smf Arcade Block
Post by: Nabil on January 01, 2009, 02:29:27 PM
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' .
Title: Re: an alternative to smf Arcade Block
Post by: jb3398 on January 01, 2009, 02:40:26 PM
no it is a different prefix
Title: Re: an alternative to smf Arcade Block
Post by: Nabil on January 01, 2009, 02:46:31 PM
what is the name of the Table where you games are saved in the Data base ?
Title: Re: an alternative to smf Arcade Block
Post by: Saga on January 02, 2009, 02:50:24 AM
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 ?
Title: Re: an alternative to smf Arcade Block
Post by: Nabil on January 02, 2009, 06:55:32 AM
Quote
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

Code: [Select]
<?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($askMYSQL_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($askMYSQL_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($askMYSQL_ASSOC);
$g2number=$row[ID_GAME];

$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row mysql_fetch_array($askMYSQL_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($askMYSQL_ASSOC); $gameid1=$row[ID_GAME];
$ask1=mysql_query("SELECT rating FROM smf_arcade_rates WHERE ID_GAME='$gameid1'");
$row mysql_fetch_array($ask1MYSQL_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($askMYSQL_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 :
Code: [Select]
<?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($askMYSQL_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($askMYSQL_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($askMYSQL_ASSOC);
$g2number=$row[ID_GAME];

$ask=mysql_query("SELECT ID_GAME FROM smf_arcade_games WHERE internalName='$game3'");
$row mysql_fetch_array($askMYSQL_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($askMYSQL_ASSOC); $gameid1=$row[ID_GAME];
$ask1=mysql_query("SELECT rating FROM smf_arcade_rates WHERE ID_GAME='$gameid1'");
$row mysql_fetch_array($ask1MYSQL_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($askMYSQL_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>"
;

?>

Title: Re: an alternative to smf Arcade Block
Post by: FrizzleFried on April 04, 2012, 03:13:32 PM
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...
Title: Re: an alternative to smf Arcade Block
Post by: Old Fossil on April 04, 2012, 05:50:01 PM
You do realise there is an arcade block already?
SimplePortal 2.3.8 © 2008-2024, SimplePortal