Oblivion Knight
01-09-2005, 08:57 AM
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):
$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:
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..
$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:
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):
$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:
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..
$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: