vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Help - Creating an Arcade Cache (https://vborg.vbsupport.ru/showthread.php?t=74056)

Oblivion Knight 01-09-2005 08:57 AM

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:

rake 01-09-2005 10:07 AM

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'];
    }



Oblivion Knight 01-09-2005 11:52 AM

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.. :D

Oblivion Knight 01-09-2005 02:01 PM

[high][EDIT][/high]

Nevermind, got this working now also.. :)


All times are GMT. The time now is 06:16 PM.

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.02649 seconds
  • Memory Usage 1,741KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete