Pages: [1]
Author Topic: controls - game information  (Read 1442 times)
Customers
Jr. Member
*

Karma: 3
Posts: 15


on: Jan 28, 09, 10:56 AM

Hi there,

i wanted to inform the users what kind of control ( mouse / keyboard / what keys etc ) the game needs to be played so i created a little mod for this and i'm sharing it ... because sharing is caring Smiley

let's start:

first let's alter the !PREFIX!_games table in the database ( where !PREFIX! is your prefix to tables - default is pas, so the table looks like pas_games ) with a new field that will store our information:

Code:
ALTER TABLE `pas_games` ADD `controls` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `keywords` ;

now open the content.php file under the admin\ directory and around line 259

Code:
"GAMEKEYWORDS" => $_REQUEST["keywords"],

add below our new line:

Code:
/* game controls mod var */
"GAMECONTROLS" => $_REQUEST["controls"],
/* game controls mod var */

after this find the line:

Code:
$sKeywords = get_magic_quotes_gpc() ? $_POST["keywords"] : mysql_escape_string($_POST["keywords"]);

and after it add the following line:

Code:
$sControls = get_magic_quotes_gpc() ? $_POST["controls"] : mysql_escape_string($_POST["controls"]);

now in the same file find the line:

Code:
$query = 'INSERT DELAYED INTO '.$cMain['dbPrefix'].'games SET category_id='.$_POST['cat'].', added='.time()
.', active='.$nActive.', title="'.$sTitle.'", latin_title="'.$sLatinTitle.'", file="'.$sFile
.'", thumbnail="'.$_FILES['thumbnail']['name'].'", keywords="'.$sKeywords.'", description="'.$sDescr.'", width='.$width.', height='.$height.', featured='.$nFeatured;

and replace the whole line with:

Code:
$query = 'INSERT DELAYED INTO '.$cMain['dbPrefix'].'games SET category_id='.$_POST['cat'].', added='.time()
.', active='.$nActive.', title="'.$sTitle.'", latin_title="'.$sLatinTitle.'", file="'.$sFile
.'", thumbnail="'.$_FILES['thumbnail']['name'].'", keywords="'.$sKeywords.'", controls="'.$sControls.'",
description="'.$sDescr.'", width='.$width.', height='.$height.', featured='.$nFeatured;

( actually i've added only: , controls="'.$sControls.'", in that query )

then find line:

Code:
case "doeditgame":

and a few line lower:

Code:
"GAMEKEYWORDS" => $res["keywords"],

below that line add:

Code:
/* game controls mod */
"GAMECONTROLS"    => $res["controls"],
/* game controls mod */

then a few lines lower find:

Code:
$sKeywords = get_magic_quotes_gpc() ? $_POST["keywords"] : mysql_escape_string($_POST["keywords"]);

and after it add:

Code:
/* game controls mod */
$sControls = get_magic_quotes_gpc() ? $_POST["controls"] : mysql_escape_string($_POST["controls"]);
/* game controls mod */

and again a few line lower find the line:

Code:
$query .= ', keywords="' . $sKeywords . '", description="' . $sDescr . '", featured=' . $nFeatured;

and replace with:

Code:
/* game controls modified query -> added $sControls */
$query .= ', keywords="' . $sKeywords . '", controls="'.$sControls.'", description="' . $sDescr . '", featured=' . $nFeatured;
/* game controls modified query -> added $sControls */

now you can save and close content.php
!!! REMEMBER !!! ALWAYS BACKUP YOUR ORIGINAL FILES !!!

now open the page_addgame.html file under admin\templates\ and find

Code:
<div class="Right">

and below add:

Code:
<!-- game controls mod block -->
<div class="Block">
<div class="Title">Controls</div>
<div><textarea class="Text Med" rows="3" name="controls">!GAMECONTROLS!</textarea></div>
</div>
<!-- game controls mod block -->

and save and close

now open game.php file under the root directory and find

Code:
'GAMEFILE'    => substr($gameres['file'], 0, 7) == 'http://' ? $gameres['file'] : $cSite['sSiteRoot'] . 'content/swf/' . $gameres['file'],

and after it add:

Code:
/* game controls mod */
"GAMECONTROLS" => $gameres["controls"],
/* game controls mod */

and save and close

now open page_game.html file under the templates\Toys directory and find:

Code:
!RELATED!

above it add:

Code:
<!-- game controls mod  -->
<font class="Title">Controls: !GAMECONTROLS!</font>
<!-- game controls mod  -->

and save and close

and at last open styles.css under templates\Toys\images\ and at the end of the file add:

Code:
.Title{ margin-bottom:4px; color: #F86401;  font-size: 13px;  font-weight: bold;  text-transform: uppercase;  font-family: Tahoma, Arial, Helvetica, sans-serif;  letter-spacing: -0.005em;               }

that's all
in the end you should have the option to added control information in your admin tool and display the
information in you game page

see attached files Wink



* addgame_controls.jpg (20.2 KB, 783x215 - viewed 108 times.)

* game_page_controls.jpg (5.44 KB, 689x55 - viewed 106 times.)
« Last Edit: Jan 28, 09, 11:01 AM by darkplague » Logged
Administrator
Sr. Member
*

Karma: 7
Posts: 486


Email
Reply #1 on: Jan 28, 09, 04:52 PM

That's cool, but there is a serious problem with this mod... once you have implemented it on your site, you will not be able to install PAS gamepacks because they are sensitive to the "__games" table's structure.

But there is a workaround - you can store your data in a separate table and connect it with the games table using SQL... or (better) take the game's ID which is known at the point where the core starts loading pageblocks, and execute a separate query to your table. So it will be a page block 100% separate from the core. And every PAS site owner will keep the possibility to update his/her script to the new versions without a problem.
Logged
Customers
Jr. Member
*

Karma: 3
Posts: 15


Reply #2 on: Jan 29, 09, 08:38 AM

on your suggestion Sergey i made a little change ... so this is what i've got:

please note: this modifications are written to be used on the original versions of script files

First undo the PREFIX_games table modification ( default prefix is pas_ ):

Code:
ALTER TABLE `pas_games` DROP `controls`

new we create a new table to store the information:

Code:
CREATE TABLE IF NOT EXISTS `pas_games_controls` (
  `game_id` int(10) NOT NULL auto_increment,
  `game_title` varchar(255) NOT NULL,
  `controls` varchar(255) NOT NULL,
  UNIQUE KEY `game_id` (`game_id`),
  KEY `game_title` (`game_title`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

now open the admin\content.php file and find:

Code:
case "doaddgame":

and inside this action search for:

Code:
"GAMEKEYWORDS" => $_REQUEST["keywords"],

after it insert:

Code:
/* game controls mod var */
"GAMECONTROLS" => $_REQUEST["controls"],
/* game controls mod var */

now find this long line:

Code:
$query = 'INSERT DELAYED INTO '.$cMain['dbPrefix'].'games SET category_id='.$_POST['cat'].', added='.time().', active='.$nActive.', title="'.$sTitle.'", latin_title="'.$sLatinTitle.'", file="'.$sFile.'",
thumbnail="'.$_FILES['thumbnail']['name'].'", keywords="'.$sKeywords.'", description="'.$sDescr.'", width='.$width.', height='.$height.', featured='.$nFeatured;

and after it add:

Code:
/* game controls added query */
$query_controls = 'INSERT DELAYED INTO '.$cMain['dbPrefix'].'games_controls SET game_title="'.$sTitle.'", controls="'.$sControls.'"';
/* game controls added query */

and a few lines lower find:

Code:
$db->query( $query );

and after it add:

Code:
/* game controls added query */
$db->query( $query_controls );
/* game controls added query */

now find the followind action:

Code:
case "doeditgame":

find the query:

Code:
$res = $db->super_query( "SELECT * FROM ".$cMain["dbPrefix"]."games WHERE id=".$_REQUEST["id"]." LIMIT 1", false );

and after it add:

Code:
/* game controls mod */
$query = ' SELECT * FROM '.$cMain["dbPrefix"].'games_controls WHERE game_title="'.$res["title"].'" LIMIT 1';
$ctrl = $db->super_query( $query );
if (!$ctrl)
{
$query_controls = 'INSERT DELAYED INTO '.$cMain['dbPrefix'].'games_controls SET game_title="'.$res["title"].'", controls=""';
$db->query ( $query_controls );
}
/* game controls mod */

and a few lines lower find:

Code:
"GAMEKEYWORDS" => $res["keywords"],

and after it add:

Code:
/* game controls mod */
"GAMECONTROLS"    => $ctrl["controls"],
/* game controls mod */

now a few lines lower find:

Code:
$sKeywords = get_magic_quotes_gpc() ? $_POST["keywords"] : mysql_escape_string($_POST["keywords"]);
      
and after it add:

Code:
/* game controls mod */
$sControls = get_magic_quotes_gpc() ? $_POST["controls"] : mysql_escape_string($_POST["controls"]);
/* game controls mod */
      

and again a few lines lower find:

Code:
$query .= ', keywords="' . $sKeywords . '", description="' . $sDescr . '", featured=' . $nFeatured;

after it add:

Code:
/* game controls query  */
$query_ctrl = 'UPDATE '.$cMain['dbPrefix'].'games_controls SET game_title="'.$sTitle.'", controls="'.$sControls.'" WHERE game_title="'.$res["title"].'" LIMIT 1';
/* game controls query */

and a few lines lower find:

Code:
$db->query( $query );

after it add:

Code:
/* game controls query */
$db->query( $query_ctrl );
/* game controls query */

now find the following line:

Code:
case "dodelgame":

and a few lines lower find:

Code:
$db->query( "DELETE FROM ".$cMain["dbPrefix"]."games WHERE id=".$_REQUEST["id"]." LIMIT 1" );

after it add:

Code:
/* game controls mod */
$db->query( "DELETE FROM ".$cMain["dbPrefix"]."games_controls WHERE game_title='".$res["title"]."' LIMIT 1");
/* game controls mod */

now save and close the content.php file

remember that always backup your original files

now open game.php file and find the following comment:

Code:
// In case we have an uploaded game or a direct URL to the game's file, use template.

above it ( between the line and { sign ) insert:

Code:
/* added query for game controls */
$query = 'SELECT * FROM ' . $cMain['dbPrefix'] . 'games_controls WHERE game_title="'.$gameres["title"].'" LIMIT 1';
$ctrl = $db->super_query( $query, false );
/* added query for game controls */

so that it will look like

Code:
{
/* added query for game controls */
$query = 'SELECT * FROM ' . $cMain['dbPrefix'] . 'games_controls WHERE game_title="'.$gameres["title"].'" LIMIT 1';
$ctrl = $db->super_query( $query, false );
/* added query for game controls */
   // In case we have an uploaded game or a direct URL to the game's file, use template.

and now a few lines lower find:

Code:
'GAMEFILE'    => substr($gameres['file'], 0, 7) == 'http://' ? $gameres['file'] : $cSite['sSiteRoot'] . 'content/swf/' . $gameres['file'],

and below it add:

Code:
/* game controls mod */
"GAMECONTROLS" => $ctrl["controls"],
/* game controls mod */

hope that this will hit your suggestion Sergey
« Last Edit: Jan 29, 09, 08:25 PM by darkplague » Logged
Jr. Member
**

Karma: 0
Posts: 23


Reply #3 on: Jan 29, 09, 06:39 PM

That's a great mod darkplague, thanks alot.

I will be sure to test it out.
Logged
Pages: [1]
 
Jump to: