insert("members", "username, email, password", "'$username', '$email', '$password'"); //and make their character //depending on which type they chose, we want to generate random statistics $health = 100; //always start off with full health $speed = characterRandAttribute($type, "speed"); $intelligence = characterRandAttribute($type, "intelligence"); $strength = characterRandAttribute($type, "strength"); $agility = characterRandAttribute($type, "agility"); $magic = characterRandAttribute($type, "magic"); $mapid = 1; //set them to a default map $z = 1; //set them to the first level of the map $x = startPositionX($mapid, $z); $y = startPositionY($mapid, $z); $_SESSION['database']->insert("characters", "memberid, firstname, lastname, type, health, speed, intelligence, strength, agility, magic, mapid, x, y, z", "'$id', '$first', '$last', '$type', '$health', '$speed', '$intelligence', '$strength', '$agility', '$magic', '$mapid', '$x', '$y', '$z'"); //this clears all the form values unset($_POST); //that's it!!! How easy was that?!? return successMsg("Your account has been created. Login to start playing"); } /************** * Return a random value for this type and attribute **************/ function characterRandAttribute($type, $attribute) { global $_SESSION; $table = "character_types"; $where = "WHERE id='$type'"; //if we pass this speed, we want minspeed and maxspeed $minattribute = "min" . $attribute; $maxattribute = "max" . $attribute; $min = $_SESSION['database']->single($minattribute, $table, $where); $max = $_SESSION['database']->single($maxattribute, $table, $where); //now we return a random number generated between min - max return rand($min, $max); } /************** * Checks to see if a username already exists * Returns true if username is found **************/ function usernameExists($username) { global $_SESSION; $found = $_SESSION['database']->single("username", "members", "WHERE username='$username'"); if ($found) return true; return false; } /************** * Checks to see if an email already exists * Returns true if email is found **************/ function emailExists($email) { global $_SESSION; $found = $_SESSION['database']->single("email", "members", "WHERE email='$email'"); if ($found) return true; return false; } /************** * Find and return an object from an array * Note: this will not work for objects that don't have an ID **************/ function findObject($array, $id) { foreach($array as $object) if ($object->id == $id) return $object; } /************** * The width of the array map * MUST HAVE ALREADY CONNECTED TO DATABASE!! **************/ function height($mapid, $level) { global $_SESSION; //select the largest x coordinate $result = $_SESSION['database']->select("x", "mapdata", "WHERE mapid=$mapid and z=$level ORDER BY x DESC LIMIT 1"); return $result['x']; } /************** * The height of the array map * MUST HAVE ALREADY CONNECTED TO DATABASE!! **************/ function width($mapid, $level) { global $_SESSION; //select the largest x coordinate $result = $_SESSION['database']->select("y", "mapdata", "WHERE mapid=$mapid and z=$level ORDER BY y DESC LIMIT 1"); return $result['y']; } /************** * Display the map file on the screen * and the character's position on the map * MUST HAVE ALREADY CONNECTED TO DATABASE!! **************/ function displayMap($mapid, $x, $y, $level, $width, $height) { echo "
"; for ($i = 0; $i <= $width; $i++) { echo " | $i | "; } for ($i = 0; $i <= $height; $i++) { echo "|
$i | "; for ($j = 0; $j <= $width; $j++) { //get the value from the database instead of from the variable $value = getValue($i, $j, $mapid, $level); if ($x == $i && $y == $j) { echo ""; if ($value == "T") echo ""; else echo ""; echo "C | "; } else { echo "" . $value . " | "; } } echo "