Jump to content

zelig

Members
  • Posts

    117
  • Joined

  • Last visited

    Never

Everything posted by zelig

  1. Okay, so I need to pull a second query just on the `created` field to be able to present it in the right format? I have an initial query that pulls everything from the `users` table, as I'm trying to make it so that the administrators can see everything as it relates to that specific user. Here's my whole code. Maybe that will help. function edituser($id) { global $player; if (isset($_POST["submit"])) { extract($_POST); $errors = 0; $errorlist = ""; if ($email == "") { $errors++; $errorlist .= "Email is required.<br />"; } if ($hometown == "") { $errors++; $errorlist .= "Hometown is required.<br />"; } if ($password == "") { $errors++; $errorlist .= "Password is required.<br />"; } if ($race == "") { $errors++; $errorlist .= "Race is required.<br />"; } if ($class == "") { $errors++; $errorlist .= "Class is required.<br />"; } if ($rank == "") { $errors++; $errorlist .= "Rank is required.<br />"; } if ($gender == "") { $errors++; $errorlist .= "Gender is required.<br />"; } if ($eyes == "") { $errors++; $errorlist .= "Eyes is required.<br />"; } if ($hair == "") { $errors++; $errorlist .= "Hair is required.<br />"; } if ($skin == "") { $errors++; $errorlist .= "Skin is required.<br />"; } if ($build == "") { $errors++; $errorlist .= "Build is required.<br />"; } if ($height == "") { $errors++; $errorlist .= "Height is required.<br />"; } if ($gender == "") { $errors++; $errorlist .= "Gender is required.<br />"; } if ($hp == "") { $errors++; $errorlist .= "Current HP is required.<br />"; } if ($mp == "") { $errors++; $errorlist .= "Current MP is required.<br />"; } if ($energy == "") { $errors++; $errorlist .= "Current energy is required.<br />"; } if ($maxhp == "") { $errors++; $errorlist .= "Max HP is required.<br />"; } if ($maxmp == "") { $errors++; $errorlist .= "Max MP is required.<br />"; } if ($maxenergy == "") { $errors++; $errorlist .= "Max energy is required.<br />"; } if (!is_numeric($hp)) { $errors++; $errorlist .= "Current HP must be a number.<br />"; } if (!is_numeric($mp)) { $errors++; $errorlist .= "Current MP must be a number.<br />"; } if (!is_numeric($energy)) { $errors++; $errorlist .= "Current energy must be a number.<br />"; } if (!is_numeric($maxhp)) { $errors++; $errorlist .= "Max HP must be a number.<br />"; } if (!is_numeric($maxmp)) { $errors++; $errorlist .= "Max MP must be a number.<br />"; } if (!is_numeric($maxenergy)) { $errors++; $errorlist .= "Max energy must be a number.<br />"; } if ($errors == 0) { $updatequery = <<<END UPDATE users SET email="$email", admin="$admin", hometown="$hometown", password="$password", race="$race", class="$class", rank="$rank", gender="$gender", eyes="$eyes", hair="$hair", skin="$skin", build="$build", height="$height", spouse="$spouse", fame="$fame", gfame="$gfame", quests="$quests", flags="$flags", gold="$gold", credits="$credits", bank="$bank", hp="$hp", maxhp="$maxhp", energy="$energy", maxenergy="$maxenergy", mp="$mp", maxmp="$maxmp", plevel="$plevel", experience="$experience", strength="$strength", agility="$agility", vitality="$vitality", wisdom="$wisdom", escape="$escape", interest="$interest", minecount="$minecount", stat_bonus="$stat_bonus" WHERE id="$id" END; $query = doquery($updatequery, "users"); admindisplay("User updated.","Edit Users"); } else { admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.", "Edit Users"); } } $query = doquery("SELECT * FROM users WHERE id='$id'", "users"); $row = mysql_fetch_array($query); $iclass = $player->class; global $controlrow; $page = <<<END <b><u>Edit Users</u></b><br /><br /> <form action="admin_panel.php?do=edituser:$id" method="post"> <table width="90%"> <tr><td width="20%">ID:</td><td>{{id}}</td></tr> <tr><td width="20%">Username:</td><td>{{username}}</td></tr> <tr><td width="20%">Email:</td><td><input type="text" name="email" size="30" maxlength="100" value="{{email}}" /></td></tr> <tr><td width="20%">Password:</td><td><input type="text" name="password" size="30" maxlength="8" value="{{password}}" /></td></tr> <tr><td width="20%">Admin Level:</td><td><input type="text" name="admin" size="30" maxlength="30" value="{{admin}}" /></td></tr> <tr><td width="20%">Registered On:</td><td>{{created}}</td></tr> <tr><td width="20%">Last Online:</td><td>{{last_login}}</td></tr> <tr><td width="20%">Last IP:</td><td>{{ip}}</td></tr> <tr><td width="20%">Flags:</td><td><input type="text" name="flags" size="30" maxlength="1055" value="{{flags}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Hometown:</td><td><input type="text" name="hometown" size="15" maxlength="30" value="{{hometown}}" /></td></tr> <tr><td width="20%">Race:</td><td><input type="text" name="race" size="10" maxlength="30" value="{{race}}" /></td></tr> <tr><td width="20%">Class:</td><td><input type="text" name="class" size ="10" maxlength="30" value="{{class}}" /></td></tr> <tr><td width="20%">Rank:</td><td><input type="text" name="rank" size="15" maxlength="15" value="{{rank}}" /></td></tr> <tr><td width="20%">Gender:</td><td><input type="text" name="gender" size="15" maxlength="25" value="{{gender}}" /></td></tr> <tr><td width="20%">Eyes:</td><td><input type="text" name="eyes" size="15" maxlength="30" value="{{eyes}}" /></td></tr> <tr><td width="20%">Hair:</td><td><input type="text" name="hair" size="15" maxlength="30" value="{{hair}}" /></td></tr> <tr><td width="20%">Skin:</td><td><input type="text" name="skin" size="15" maxlength="30" value="{{skin}}" /></td></tr> <tr><td width="20%">Build:</td><td><input type="text" name="build" size="15" maxlength="30" value="{{build}}" /></td></tr> <tr><td width="20%">Height:</td><td><input type="text" name="height" size="15" maxlength="30" value="{{height}}" /></td></tr> <tr><td width="20%">Spouse:</td><td><input type="text" name="spouse" size="15" maxlength="30" value="{{spouse}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Fame:</td><td><input type="text" name="fame" size="5" maxlength="10" value="{{fame}}" /></td></tr> <tr><td width="20%">GFame:</td><td><input type="text" name="gfame" size="5" maxlength="2" value="{{gfame}}" /></td></tr> <tr><td width="20%">Quests:</td><td><input type="text" name="quests" size="5" maxlength="5" value="{{quests}}" /></td></tr> <tr><td width="20%">Gold:</td><td><input type="text" name="gold" size="5" maxlength="6" value="{{gold}}" /></td></tr> <tr><td width="20%">Bank:</td><td><input type="text" name="bank" size="5" maxlength="30" value="{{bank}}" /></td></tr> <tr><td width="20%">Interest:</td><td><input type="text" name="interest" size="5" maxlength="3" value="{{bank}}" /></td></tr> <tr><td width="20%">Credits:</td><td><input type="text" name="credits" size="5" maxlength="3" value="{{credits}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Current Player Level:</td><td><input type="text" name="plevel" size="5" maxlength="6" value="{{plevel}}" /></td></tr> <tr><td width="20%">Current HP:</td><td><input type="text" name="hp" size="5" maxlength="6" value="{{hp}}" /></td></tr> <tr><td width="20%">Max HP:</td><td><input type="text" name="maxhp" size="5" maxlength="6" value="{{maxhp}}" /></td></tr> <tr><td width="20%">Current MP:</td><td><input type="text" name="mp" size="5" maxlength="6" value="{{mp}}" /></td></tr> <tr><td width="20%">Max MP:</td><td><input type="text" name="maxmp" size="5" maxlength="6" value="{{maxmp}}" /></td></tr> <tr><td width="20%">Current Energy:</td><td><input type="text" name="energy" size="5" maxlength="6" value="{{energy}}" /></td></tr> <tr><td width="20%">Max Energy:</td><td><input type="text" name="maxenergy" size="5" maxlength="6" value="{{maxenergy}}" /></td></tr> <tr><td width="20%">Strength:</td><td><input type="text" name="strength" size="5" maxlength="5" value="{{strength}}" /></td></tr> <tr><td width="20%">Agility:</td><td><input type="text" name="agility" size="5" maxlength="5" value="{{agility}}" /></td></tr> <tr><td width="20%">Vitality:</td><td><input type="text" name="vitality" size="5" maxlength="5" value="{{vitality}}" /></td></tr> <tr><td width="20%">Wisdom:</td><td><input type="text" name="wisdom" size="5" maxlength="5" value="{{wisdom}}" /></td></tr> <tr><td width="20%">Escape:</td><td><input type="text" name="escape" size="5" maxlength="5" value="{{escape}}" /></td></tr> <tr><td width="20%">Bonus:</td><td><input type="text" name="stat_bonus" size="5" maxlength="3" value="{{stat_bonus}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Description:</td><td>{{description}}</td></tr> <tr><td width="20%">Weapon:</td><td>{{weapon}}</td></tr> <tr><td width="20%">Head:</td><td>{{head}}</td></tr> <tr><td width="20%">Neck:</td><td>{{neck}}</td></tr> <tr><td width="20%">Body:</td><td>{{body}}</td></tr> <tr><td width="20%">Shield:</td><td>{{shield}}</td></tr> <tr><td width="20%">Shoulders:</td><td>{{shoulders}}</td></tr> <tr><td width="20%">Arms:</td><td>{{arm}}</td></tr> <tr><td width="20%">Hands:</td><td>{{hands}}</td></tr> <tr><td width="20%">Fingers:</td><td>{{finger}}</td></tr> <tr><td width="20%">Wrists:</td><td>{{wrists}}</td></tr> <tr><td width="20%">Legs:</td><td>{{legs}}</td></tr> <tr><td width="20%">Feet:</td><td>{{feet}}</td></tr> <tr><td width="20%">Guild:</td><td>{{guild}}</td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Frozen:</td><td>{{frozen}}</td></tr> <tr><td width="20%">Muted:</td><td>{{muted}}</td></tr> <tr><td width="20%">Deaf:</td><td>{{deaf}}</td></tr> </table> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> END; $page = parsetemplate($page, $row); admindisplay($page, "Edit Users"); }
  2. Okay, I have a field called "created" in my `users` table, and I'd like to be able to view it in-game on an administrator panel. However, it's being captured in a long number format (i.e. 1335076320) which, I believe, has to deal with seconds and such. How can I take that number and convert it to an actual date/time output? Here's how I currently have it coded in my php form: <tr><td width="20%">Registered On:</td><td>{{created}}</td></tr> So, obviously it's not converting it to any format, rather just pulling that 1335076320 number out. Thanks in advance!
  3. Okay, I have a healing spell that allows people to regain stats when it's cast. But, how do I limit it so that they can't go over their maxhp? Here's what I have so far: $db->execute("UPDATE `users` SET `hp`=?, `mp`=?, `energy`=? WHERE `id`=?", array($player->hp + $healspell, $player->mp - $spell['mp'], $player->energy - $spell['energy'], $player->id)); What do I need to do in this to tell it to limit it to the maxhp but never going over it? $healspell is a random number, so it is quite possible to go over the maxhp at the moment. Thank you!
  4. How can I post this variable $healspell when I already have an echo within a php? Here's what I have: echo '<p>You cast Nature\'s Cure (Recovered <?=$healspell?>)</p>'; It's not printing anything out at the moment, obviously, and if I just put $healspell, it just echos out: $healspell. Thanks!
  5. Found the problem. Fixed it. Now, I get this error: qry failed: Unknown column 'admin' in 'where clause' The coordinates I'm are are: x = 1 y = 0 z = admin plane = batai It doesn't like z for some reason... Here's my current code: error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); define("PAGENAME", "Shops"); $player = check_user($secret_key, $db); $x = $player->x; $y1 = $player->y; $z = $player->z; $plane = $player->plane; if($_SESSION['234asdfas']){$y = $_SESSION['234asdfas'];}else{echo 'Error: You do not have a session variable set'; exit;} $query = mysql_query("SELECT * FROM `shop` WHERE `x`=$x AND `y`=$y1 AND `z`=$z AND `plane`=$plane") or die("qry failed: ".mysql_error()); while($row = mysql_fetch_array($query)) { // echo out the contents of each row echo $row['id']."<br />"; echo $row['name']."<br />"; echo $row['location']."<br />"; echo $row['itemslist']."<br />"; echo $row['x']."<br />"; echo $row['y']."<br />"; echo $row['z']."<br />"; echo $row['plane']."<br />"; }
  6. Up above: $player = check_user($secret_key, $db); $x = $player->id; It's pulling the login information and putting it into the $player variable. (I believe that's how you explain it...)
  7. So, why is it placing my username id# into those spots instead of getting the information from the shop table which should be: x = 1 y = 0 z = admin plane = batai
  8. The echo $query pulls: SELECT * FROM `shop` WHERE `x`='9' AND `y`='9' AND `z`='9' AND `plane`='9' So... it's inserting my user id # into those spots... And I have the error reporting stuff in there. Still, just a blank white screen.
  9. Hmm... This just brings up a white screen. $q1 = mysql_query("SELECT * FROM `shop` WHERE `x`='".$x["x"]."' AND `y`='".$x["y"]."' AND `z`='".$x["z"]."' AND `plane`='".$x["plane"]."'") or die("qry failed: ".mysql_error()); while($row = mysql_fetch_array($q1)) { // echo out the contents of each row echo $row['id']."<br />"; echo $row['name']."<br />"; echo $row['x']."<br />"; echo $row['y']."<br />"; echo $row['z']."<br />"; echo $row['plane']."<br />"; }
  10. Okay, so, I'm trying to pull the info from my `shop` table where the `users` table matches at x, y, z, and plane. Instead, I'm getting this: Resource id #22 Where is this coming from? I only have 1 row in my shop table, and it has: id = 7 name = admin shop x = 1 y = 0 z = admin plane = batai I'm standing in the shop right now (as my character, so my users table has the exact same x, y, z, plane)... Any help would be appreciated! $q1 = mysql_query("SELECT * FROM `shop` WHERE `x`='".$x["x"]."' AND `y`='".$x["y"]."' AND `z`='".$x["z"]."' AND `plane`='".$x["plane"]."'") or die("qry failed: ".mysql_error()); Variables: $x = $x = $player->username; (so it's pulling my username, which it is doing correctly ==> i echoed out $x and it came up with my username)
  11. Okay, I have a question. Is there a way to combine three fields within a single table (x, y, z) into a single variable? Something like: x~y~z? (the ~ would be needed)
  12. Crud... Didn't even realize it. *lol* Thanks!
  13. No. This is a specific "shopdisplay" for this file. It isn't in any other file...
  14. I'm not seeing what is causing this: (Fatal error: Cannot redeclare shopdisplay() (previously declared in /home/katarra/public_html/shops.php:11)in /home/katarra/public_html/shops.php on line 21) error... Any help would be appreciated! (This probably isn't the only error, but it's the one that's stopping me from finding the others) Thanks! <?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once('dk_lib.php'); require_once('scripts/dbfunc.s'); include ("debug.php"); include("lib.php"); $player = check_user($secret_key, $db); function shopdisplay($content, $title) { // Finalize page and output to browser. $template = gettemplate("shops"); $finalarray = array( "title"=>$title, "content"=>$content); $page = parsetemplate($template, $finalarray); echo $page; die(); } if (isset($_GET["do"])) { $do = explode(":",$_GET["do"]); if ($do[0] == "buy") { include('shops.php'); buy(); } elseif ($do[0] == "buy2") { include('shops.php'); buy2($do[1]); } elseif ($do[0] == "buy3") { include('shops.php'); buy3($do[1]); } elseif ($do[0] == "sell") { include('shops.php'); sell(); } } else { donothing(); } function donothing() { $page = "Welcome to my shop. What do you want?"; shopdisplay($page, "Shop Home"); } function buy() { // Displays a list of available items for purchase. global $numqueries; $query1 = doquery("SELECT * FROM levels", "levels") or trigger_error("Query failed: ". mysql_error()); $location = mysql_fetch_array($query1); $townquery = doquery("SELECT name,itemslist FROM shop WHERE location=$location", "shop") or trigger_error("Query failed: ". mysql_error()); if (mysql_num_rows($townquery) != 1) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $townrow = mysql_fetch_array($townquery); $itemslist = explode(",",$townrow["itemslist"]); $querystring = ""; foreach($itemslist as $a=>$b) { $querystring .= "id='$b' OR "; } $querystring = rtrim($querystring, " OR "); $itemsquery = doquery("SELECT * FROM items WHERE $querystring ORDER BY id", "items"); $page = "Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.<br /><br />Click an item name to purchase it.<br /><br />The following items are available at this shop:<br /><br />\n"; $page .= "<table width=\"80%\">\n"; while ($itemsrow = mysql_fetch_array($itemsquery)) { if ($itemsrow["type"] == 'weapon') { $attr = "Attack Power:"; } else { $attr = "Defense Power:"; } $page .= "<tr><td width=\"4%\">"; /* if ($userrow["weaponid"] == $itemsrow["id"] || $userrow["armorid"] == $itemsrow["id"] || $userrow["shieldid"] == $itemsrow["id"]) { $page .= "<td width=\"32%\"><span class=\"light\">".$itemsrow["name"]."</span></td><td width=\"32%\"><span class=\"light\">$attrib ".$itemsrow["attribute"]."</span></td><td width=\"32%\"><span class=\"light\">Already purchased</span></td></tr>\n"; } else } */ $page .= "<td width=\"32%\"><b><a href=\"shops.php?do=buy2:".$itemsrow["id"]."\">".$itemsrow["name"]."</a>$</b></td><td width=\"32%\">$attr <b>".$itemsrow["attr"]."</b></td><td width=\"32%\">Price: <b>".$itemsrow["price"]." gold</b></td></tr>\n"; } $page .= "</table><br />\n"; $title = "Buy Items"; shopdisplay($page, $title); } function buy2($id) { // Confirm user's intent to purchase item. global $userrow, $numqueries; $query1 = doquery("SELECT * FROM levels", "levels"); $location = mysql_fetch_array($query1); $townquery = doquery("SELECT name,itemslist FROM shop WHERE location=$location", "shop") or trigger_error("Query failed: ". mysql_error()); if (mysql_num_rows($townquery) != 1) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $townrow = mysql_fetch_array($townquery); $townitems = explode(",",$townrow["itemslist"]); if (! in_array($id, $townitems)) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $itemsquery = doquery("SELECT * FROM items WHERE id='$id'", "items") or trigger_error("Query failed: ". mysql_error()); $itemsrow = mysql_fetch_array($itemsquery); if ($player["gold"] < $itemsrow["price"]) { shopdisplay("You do not have enough gold to buy this item!", "Buy Items"); die(); } if ($itemsrow["type"] == 'weapon') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } elseif ($itemsrow["type"] == 'armor') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } elseif ($itemsrow["type"] == 'item') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } elseif ($itemsrow["type"] == 'pet') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } $title = "Buy Items"; shopdisplay($page, $title); } function buy3($id) { // Update user profile with new item & stats. if (isset($_POST["cancel"])) { header("Location: shops.php"); die(); } global $userrow; $query1 = doquery("SELECT * FROM levels", "levels"); $location = mysql_fetch_array($query1); $townquery = doquery("SELECT name,itemslist FROM shop WHERE location=$location", "shop") or trigger_error("Query failed: ". mysql_error()); if (mysql_num_rows($townquery) != 1) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $townrow = mysql_fetch_array($townquery); $townitems = explode(",",$townrow["itemslist"]); if (! in_array($id, $townitems)) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $itemsquery = doquery("SELECT * FROM items WHERE id='$id'", "items") or trigger_error("Query failed: ". mysql_error()); $itemsrow = mysql_fetch_array($itemsquery); if ($player["gold"] < $itemsrow["price"]) { shopdisplay("You do not have enough gold to buy this item!", "Buy Items"); die(); } $query = mysql_select("select `id`, `name`, `price`, `type`, `slot` from `items` where `id`=?", array($_GET['id'])) or trigger_error("Query failed: ". mysql_error()); $item = $query->fetchrow(); $q1 = mysql_select("select * from `inventory` where `player`=? and item_id=?", array($player->id,$item['id'])) or trigger_error("Query failed: ". mysql_error()); if($q1->recordcount() == 0) { $insert['player'] = $player->id; $insert['quantity'] = '0'; $insert['status'] = 'unequipped'; $insert['item_id'] = $item['id']; $insert['type'] = $item['type']; $insert['slot'] = $item['slot']; $query2 = $db->autoexecute('inventory', $insert, 'INSERT') or trigger_error("Query failed: ". mysql_error()); } $query1 = mysql_select("update `users` set `gold`=? where `id`=?", array($player->gold - $item['price'], $player->id)) or trigger_error("Query failed: ". mysql_error()); $insert['player'] = $player->id; $insert['item_id'] = $item['id']; $q = mysql_select("select * from `inventory` where `player`='".$insert['player']."' and `item_id`='".$item['id']."'") or trigger_error("Query failed: ". mysql_error()); $row = $q->fetchrow(); $query = mysql_select("update `inventory` set `quantity`=? where `item_id`='".$item['id']."' and `player`='".$insert['player']."'", array($row['quantity'] + 1)) or trigger_error("Query failed: ". mysql_error()); if ($query && $query1) //If successful { $player = check_user($secret_key, $db); //Get new user stats echo "<b>Blacksmith:</b><br />\n"; if ($query2){echo "<strong>You purchased a " . ucwords($item['name']) . "!</strong><br />";} echo "<i>Thank you, enjoy your new <b>" . ucwords($item['name']) . "</b>!</i><br /><br />\n"; $q1 = mysql_select("select * from `inventory` where `item_id`='".$_GET['id']."' and `player`='".$insert['player']."'"); $row1 = $q1->fetchrow(); echo "<i>You now have " . $row1['quantity'] . " <b>" . $item['name'] . "(s)</b>!</i><br /><br />\n"; echo "<a href=\"main.php?username=$x&password=$y&doit=inventory\">Return to inventory</a>"; break; } else { //Error logging here } } function sell($id) { if (!$_GET['id']) //No item ID { echo "That item does not exist in your inventory!"; break; } //Select the item from the database $inventitemid = $_GET['id']; $query = mysql_select("select * from `inventory` where inventory.item_id='".$inventitemid."' and inventory.player=?", array($player->id)); //Either item doesn't exist, or item doesn't belong to user if($query->recordcount() == 0){ echo "Sorry, that item does not exist!"; break;} $query = mysql_select("select * from `items` where items.id=?", array($_GET['id'])); $query12 = $db->execute("SELECT `status`, `quantity` FROM `inventory` where inventory.item_id='".$inventitemid."' and inventory.player=?", array($player->id)); $row = $query12->fetchrow(); if($row['status'] == 'equipped') { echo "Unequip this item before trying to sell it!<br>"; echo "<a href=\"main.php?username=$x&password=$y&doit=inventory\">Return to inventory</a><br>"; exit;} //Either item doesn't exist, or item doesn't belong to user if ($query->recordcount() == 0) { echo "Sorry, that item does not exist!"; break; } $sell = $query->fetchrow(); //Get item info //Check to make sure clicking Sell wasn't an accident if (!$_POST['sure']) { echo "Are you sure you want to sell your <b>" . $sell['name'] . "</b> for <b>" . floor($sell['price']/2) . "</b> gold?<br /><br />\n"; echo "<form method=\"post\" action=\"shops.php?act=sell&id=" . $inventitemid . "\">\n"; echo "<input type=\"submit\" name=\"sure\" value=\"Yes, I am sure!\" />\n"; echo "</form>\n"; break; } if ($row['quantity']== 1) { $query = mysql_select("delete from `inventory` where `item_id`=? and `player`=?", array($inventitemid, $player->id)); } elseif($row['quantity'] > 1) { $query = mysql_select("UPDATE `inventory` SET `quantity`=? WHERE `item_id`=? and `player`=?",array($row['quantity'] - 1, $inventitemid, $player->id)); } $query = mysql_select("update `users` set `gold`=? where `id`=?", array($player->gold + floor($sell['price']/2), $player->id)); $player = check_user($secret_key, $db); //Get updated user info echo "You have sold your <b>" . $sell['name'] . "</b> for <b>" . floor($sell['price']/2) . "</b> gold.<br /><br />\n"; echo "<a href=\"main.php?username=$x&password=$y&doit=inventory\">Return to inventory</a>"; break; } ?>
  15. Okay, this is what I have now, but it doesn't like the INTERVAL 20 MINUTE bit... Parse error: syntax error, unexpected T_LNUMBER $query = mysql_select("SELECT * FROM `monsters` WHERE `state`='fighting'"); $result = mysql_fetch_array("$query"); if ($single_mob['battle_time'] > DATE_SUB(NOW(), INTERVAL 20 MINUTE)) { $query = mysql_select("UPDATE `monsters` SET`battle_time`=0, `state`='active'"); exit; }
  16. Okay. *thickhead* (Nevermind... I have a `state` column that I can use for the 'fighting', 'active', or 'dead' bit) I need to add a new column (battle) to the monsters table, make it be a 0 or 1, and then a column for last_update (which will have time). I have reread all of this and I think I get it now. Thanks!
  17. Okay. I could potentially add this to a cron job I already have running every minute that updates dead monsters and turns them back to active once the time > respawn. What would be the type of query I would use? I think I get the JOIN bit, but the INTERVAL part doesn't seem to make sense to me, and doesn't appear to be PHP markup.
  18. I don't have a column for status, that's the issue. Here's how the system works currently: When someone fights a monster, that monster's id, hp and no_exp (it won't let you fight monsters you are too strong for) and the player's id is added to the `battles` table in addition to time(). This makes it so that no other person can fight that monster because it also changes the info in the `monsters` table for that monster to state='fighting'. When either the player or monster wins, the battle is deleted from `battles` and the state goes back to 'active' or 'killed', whichever is appropriate. The issue I am having, however, is if a player "times out" or "leaves" without exiting the battle, thus leaving the monster in the 'fighting' state, nullifying anyone else able to battle it now. It also leaves that info in the `battles` table, and that's why I need it to be deleted out. Another quick question (which I may have to add to a different topic): Is there some way I can change that state to 'active' (if it was the monster that was killed) if that time() >= to what I have is the respawn rate, which is defined for each creature based upon what level it is. I believe a cron would work for this one...
  19. Ah, I get it. Okay, so I have a separate table called "battles" that has a "battle_time" field. I will have that update every action. So, if I add in the 20 minute timeout to it, how would that look? It would delete that battle from the `battles` table... DELETE * FROM `battles` WHERE `mid`= (Monster ID -> unique for every single monster) AND `battle_time` = <Whatever the 20 minute thing is>
  20. Okay, I'm not quite sure how to state this, so I'll try my best. Is it possible to setup some kind of "after so long, it changes the state of something from 'fighting' to 'active'" query or function? What is happening is that people are fighting in my game, then choosing to just close their browser rather than quit the fight, to change the monster's state back to 'active', so other people can fight it. Does that make sense? Any thoughts or could someone point me in the right direction? Thanks!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.