functioninn(){// Resting at the inn restores hp/mp/tp.
global$userrow,$townrow;
// Errors.
if($userrow["gold"]<$townrow["innprice"]){err("You do not have enough gold to stay at the inn. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["currenthp"]==$userrow["maxhp"]&&$userrow["currentmp"]==$userrow["maxmp"]&&$userrow["currenttp"]==$userrow["maxtp"]){err("Your HP, MP and TP are already at their maximum levels. You do not need to stay at the Inn tonight.<br /><br /><a href=\"index.php\">Click here</a> to return to the main town screen.");}
if(isset($_POST["submit"])){
// Fill 'er up, my man!
$userrow["currenthp"]=$userrow["maxhp"];
$userrow["currentmp"]=$userrow["maxmp"];
$userrow["currenttp"]=$userrow["maxtp"];
$userrow["gold"]-=$townrow["innprice"];
$query=doquery("UPDATE {{table}} SET currenthp='".$userrow["maxhp"]."', currentmp='".$userrow["maxmp"]."', currenttp='".$userrow["maxtp"]."', gold='".$userrow["gold"]."' WHERE id='".$userrow["id"]."' LIMIT 1","users");
display("Rest at the Inn",gettemplate("town_inn2"));
display("Rest at the Inn",parsetemplate(gettemplate("town_inn1"),$townrow));
}
functionmap(){// Buy maps to towns for the Travel To menu.
global$userrow;
if(isset($_POST["three"])){
$townquery=doquery("SELECT * FROM {{table}} WHERE id='".$_POST["id"]."' LIMIT 1","towns");
$townrow=dorow($townquery);
if($userrow["gold"]<$townrow["mapprice"]){err("You do not have enough gold to buy this map. Please <a href=\"index.php\">go back</a> and try again.");}
if($townrow!=false){
$userrow["townslist"].=",".$townrow["id"];
$userrow["gold"]-=$townrow["mapprice"];
$query=doquery("UPDATE {{table}} SET townslist='".$userrow["townslist"]."', gold='".$userrow["gold"]."' WHERE id='".$userrow["id"]."' LIMIT 1","users");
display("Buy Maps",gettemplate("town_map3"));
}else{
err("Invalid action. Please <a href=\"index.php\">go back</a> and try again.");
}
}elseif(isset($_POST["two"])){
$townquery=doquery("SELECT * FROM {{table}} WHERE name='".$_POST["two"]."' LIMIT 1","towns");
$townrow=dorow($townquery);
if($userrow["gold"]<$townrow["mapprice"]){err("You do not have enough gold to buy this map. Please <a href=\"index.php\">go back</a> and try again.");}
if($newfullitem["requirements"]==false){err("You do not meet one or more of the requirements for this item. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["gold"]<$newfullitem["buycost"]){err("You do not have enough gold in your pocket to buy this item.");}
if($newfullitem["requirements"]==false){err("You do not meet one or more of the requirements for this item. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["gold"]<$newfullitem["buycost"]){err("You do not have enough gold in your pocket to buy this item.");}
$preitemsrow=dorow(doquery("SELECT * FROM {{table}} WHERE reqlevel>='".$townrow["itemminlvl"]."' AND reqlevel<='".$townrow["itemmaxlvl"]."' ORDER BY RAND() LIMIT 10 ","itembase"));
$preprefixrow=dorow(doquery("SELECT * FROM {{table}} WHERE reqlevel<='".$userrow["level"]."'","itemprefixes"));
$presuffixrow=dorow(doquery("SELECT * FROM {{table}} WHERE reqlevel<='".$userrow["level"]."'","itemsuffixes"));
$allitemsrow=dorow(doquery("SELECT * FROM {{table}}","itembase"));
$allprefixrow=dorow(doquery("SELECT * FROM {{table}}","itemprefixes"));
$allsuffixrow=dorow(doquery("SELECT * FROM {{table}}","itemsuffixes"));
$row=dorow(doquery("SELECT * FROM {{table}} WHERE UNIX_TIMESTAMP(onlinetime) >= '".(time()-600)."' AND world='".$userrow["world"]."' AND latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' AND id !='".$userrow["id"]."' ORDER BY id","users"),"id");
$newuserrow=dorow(doquery("SELECT *,UNIX_TIMESTAMP(onlinetime) as fonlinetime FROM {{table}} WHERE id='".$_GET["uid"]."' LIMIT 1","users"));
if($newuserrow==false){err("That user doesn't exist.");}
if($newuserrow["account"]==$userrow["account"]){err("You cannot duel another character on your own account.");}
if($newuserrow["fonlinetime"]<=(time()-600)){err("That user is not online.");}
if($newuserrow["currentaction"]!="In Town"){err("That user is busy.");}
if($newuserrow["latitude"]!=$userrow["latitude"]||$newuserrow["longitude"]!=$userrow["longitude"]){err("That user is not in this town.");}
}else{err("Invalid UID.");}
// No errors, so create the PVP record and update everyone's userrow.
$query=doquery("INSERT INTO {{table}} SET id='',player1id='".$userrow["id"]."',player2id='".$newuserrow["id"]."',player1name='".$userrow["charname"]."',player2name='".$newuserrow["charname"]."',playerturn='".$newuserrow["id"]."',turntime=NOW(),fightrow=''","pvp");
$query2=doquery("UPDATE {{table}} SET currentpvp='".mysql_insert_id()."' WHERE id='".$newuserrow["id"]."' OR id='".$userrow["id"]."' LIMIT 2","users");