Scrambling Descriptions
Most RPG games require object descriptions be scrambled each game. This makes playing the game over and over far more interesting as a red potion in one game will not have the same effect in another game. But not only do I want to scramble them for each game, I want to scramble them for each player. That means I need to store the descriptions in a row (in a table) associated with the player. Here's how this is easily achieved.
First, we define a constant that holds all possible descriptions. In this example, we're creating _AMU_DESC which will hold a long string of descriptions for amulets. Notice each description is delimited by a colon. When a player starts a new game, I load the list into a work array, shuffle it up and then save it into a table and associate with the player.
The substr reformat removes the trailing colon. This code would be executed at the start of a new game... I would recommend creating the descriptions and then performing a single update to the database...
define("_AMU_DESC","circular:spherical:oval:triangular:pyramidal:square:concave:hexagonal:octogonal");
$work = explode(":",_AMU_DESC);
shuffle($work);
for ($x=0;$x<count($work);$x++) {
$amu_desc .= $work[$x] . ":";
}
$amu_desc = substr($amu_desc,0,strlen($amu_desc)-1);
$sql = "UPDATE " . _TBL_GAME . " SET amu_desc = '" . $amu_desc . "' WHERE playerid = " . $playerid;
$rc = msql_query($sql);