Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2005, 08:57 AM
Oblivion Knight's Avatar
Oblivion Knight Oblivion Knight is offline
 
Join Date: May 2002
Location: Sheffield, UK
Posts: 1,757
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help - Creating an Arcade Cache

I'm currently trying to develop a mod that adds a setting in the Game Settings of the Admin CP which allows you to select whether or not you want to enable "Reverse Scoring" for each game. Some games are built that lower scores are actually BETTER than higher ones, and this mod intends to cater for those games..

In order to do this, a cache needs to be built so that the best scores shown on the main Arcade page are shown, whether they're highest or lowest depending on the game's setting. Originally I'd tried a single query on the arcade.php file, like this (for personal bests):

Code:
	$getGames = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "games");

	// Personal bests - returns PB in form of an array, $personalBest[shortname]
	$personalBest = array();
	if ($gamesettings[$getGames[shortname]][scoredir] == 0) {
		$result_pb = $DB_site->query("
			SELECT gamename, MAX(score) AS score FROM " . TABLE_PREFIX . "gamesessions AS gamesessions
			WHERE valid=1 AND $sessionclause
			AND userid=$bbuserinfo[userid] 
			GROUP BY gamename
		");
	} else {
		$result_pb = $DB_site->query("
			SELECT gamename, MIN(score) AS score FROM " . TABLE_PREFIX . "gamesessions AS gamesessions
			WHERE valid=1 AND $sessionclause
			AND userid=$bbuserinfo[userid] 
			GROUP BY gamename
		");
	}
	while ($bestArray = $DB_site->fetch_array($result_pb)) {
		$personalBest[$bestArray[gamename]] = $bestArray[score];
	}
	$DB_site->free_result($result_pb);
But doing that made the entire lowest or highest score setting based on $gameid 1. If $gameid 1 had reverse scoring disabled, all games showed the personal best as highest and if $gameid 1 had reverse scoring enabled, all games showed the personal best as lowest..



This is the cache I tried to build in the functions_arcade.php file:

Code:
function fetch_scoredircache()
{
	global $DB_site, $scoredircache;
	if (!is_array($scoredircache))
	{
		$scoredircache = array();
		$allgames = $DB_site->query("
			SELECT * FROM " . TABLE_PREFIX . "games
		");

		while($gamearray = $DB_site->fetch_array($allgames))
		{
			$scoredircache["$gamearray[shortname]"] = $gamearray;
		}

		$DB_site->free_result($allgames);
	}
}
Though I have no idea how to incorporate this with the arcade.php file.. Here's what I have at the moment that doesn't work..

Code:
	$getGames = fetch_scoredircache($gameid);

	// Personal bests - returns PB in form of an array, $personalBest[shortname]
	$personalBest = array();
	if ($gamesettings[$getGames['scoredir']] == 0) {
		$result_pb = $DB_site->query("
			SELECT gamename, MAX(score) AS score FROM " . TABLE_PREFIX . "gamesessions AS gamesessions
			WHERE valid=1 AND $sessionclause
			AND userid=$bbuserinfo[userid] 
			GROUP BY gamename
		");
	} else {
		$result_pb = $DB_site->query("
			SELECT gamename, MIN(score) AS score FROM " . TABLE_PREFIX . "gamesessions AS gamesessions
			WHERE valid=1 AND $sessionclause
			AND userid=$bbuserinfo[userid] 
			GROUP BY gamename
		");
	}
	while ($bestArray = $DB_site->fetch_array($result_pb)) {
		$personalBest[$bestArray[gamename]] = $bestArray[score];
	}
	$DB_site->free_result($result_pb);
$gameid has been globalized..



If anyone could offer any assistance, it'd be a huge help..
I'm still very much learning this stuff (as you can probably tell). :nervous:
Reply With Quote
  #2  
Old 01-09-2005, 10:07 AM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

not familiar with the hack itself, so i'm just guessing:

add a reverse field to the gamesessions table which will be set to 1 if minimum score should be used, 0 if max.
PHP Code:
$results $DB_site->query("SELECT gamename, MIN(score) AS min, MAX(score) as max, reverse FROM gamesessions WHERE ...");

while(
$result $DB_site->fetch_array($results))
{
   if(
$result['reverse'] == 1)
   {
       
$personalBest[$bestArray[gamename]] = $result['min'];
   }
   else
   {
       
$personalBest[$bestArray[gamename]] = $result['max'];
    }

Reply With Quote
  #3  
Old 01-09-2005, 11:52 AM
Oblivion Knight's Avatar
Oblivion Knight Oblivion Knight is offline
 
Join Date: May 2002
Location: Sheffield, UK
Posts: 1,757
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That sounds like an easier way around than what I've tried..
Thanks for the tip, I'll have a play with it and let you know how it goes!

P.S. Good to see you around again rake!


[high][EDIT][/high]
IT WORKS! Thanks rake..
Reply With Quote
  #4  
Old 01-09-2005, 02:01 PM
Oblivion Knight's Avatar
Oblivion Knight Oblivion Knight is offline
 
Join Date: May 2002
Location: Sheffield, UK
Posts: 1,757
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[high][EDIT][/high]

Nevermind, got this working now also..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03782 seconds
  • Memory Usage 2,197KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete