Hmm.... ok so is this how I would do it?
Fight.php
//----------------------------------
<?php
include 'connect.php';
include 'header.php';
//Just added------
SESSION_START();
//--------------------
if(!isset($_COOKIE['member_id']))
die('<p>You\'re not logged in, please <a href=main.php>login</a></p>');
$Player=$_COOKIE['member_id'];
$Teleport=$_POST['Teleport'];
$Thespell=$_COOKIE['Spellname'];
$Beast = mysql_fetch_array(mysql_query("Select * From Beasts where Spawner='$Player'"));
$time=date('U');
$offtime=$time-180;
$online="update Users set online='$time' where ID='$Player'";
mysql_query($online) or die("Died");
if(isset($_POST['Attack']))
$Action="attack";
else if(isset($_POST['Cast']))
$Action="magic";
else if(isset($_POST['Run']))
$Action="run";
else if(isset($_POST['Use']))
$Action="use";
else if(isset($_POST['Fight']))
$Fight=$_POST['Fight'];
$Query="SELECT * from Users where ID='$Player'";
$Query2=mysql_query($Query) or die("Could not get user stats");
$User=mysql_fetch_array($Query2);
if(isset($User['Weapon']))
{
$Query="SELECT * from Items where ID='$User[Weapon]'";
$Query2=mysql_query($Query) or die("Could not get user stats");
$Item=mysql_fetch_array($Query2);
$User['WeaponClass']=$Item['ItemClass'];
}
include 'functions.php';
if($User['HP']<=0)
die("<p>You are dead, you cannot fight.Go revive.</p>");
if(isset($Fight)&&!isset($Action))
{
$Name=$_POST['Name'];
$Query="SELECT * from Monsters where Name='$Name'";
$Query2=mysql_query($Query) or die ("Cannot select Monster");
$Monster=mysql_fetch_array($Query2);
if (!$Monster)
echo "There is no monster of that name";
else
{
//Just added--------
$_SESSION['Monstername'] = 0;
//----------------------
setcookie('Monstername',$Monster['Name'],time()+60*60*24);
$Rand=rand(1,100);
if($Rand>=10&&$Rand<=15)
$Special="Enraged";
elseif($Rand>=20&&$Rand<=25)
$Special="Intelligent";
elseif($Rand>=30&&$Rand<=35)
$Special="Extreme";
elseif($Rand>=40&&$Rand<=45)
$Special="Clumsy";
else
$Special="";
$Max=50*$Monster['Level'];
if($Monster['Type']==0)
{
$Monster['HP']=rand(20*$Monster['Level'],35*$Monster['Level']);
$Monster['MP']=0;
$Monster['Strength']=rand($Max/4-$Monster['Level'],$Max/4+$Monster['Level']);
$Monster['Constitution']=rand($Max/4-$Monster['Level'],$Max/4+$Monster['Level']);
$Monster['Dexterity']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
$Monster['Concentration']=rand($Max/6-$Monster['Level'],$Max/6+$Monster['Level']);
$Monster['Intelligence']=rand($Max/6-$Monster['Level'],$Max/6+$Monster['Level']);
}
elseif($Monster['Type']==1)
{
$Monster['HP']=rand(15*$Monster['Level'],20*$Monster['Level']);
$Monster['MP']=rand(15*$Monster['Level'],20*$Monster['Level']);
$Monster['Strength']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
$Monster['Constitution']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
$Monster['Dexterity']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
$Monster['Concentration']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
$Monster['Intelligence']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
}
else
{
$Monster['HP']=rand(10*$Monster['Level'],20*$Monster['Level']);
$Monster['MP']=rand(15*$Monster['Level'],25*$Monster['Level']);
$Monster['Strength']=rand($Max/6-$Monster['Level'],$Max/6+$Monster['Level']);
$Monster['Constitution']=rand($Max/6-$Monster['Level'],$Max/6+$Monster['Level']);
$Monster['Dexterity']=rand($Max/5-$Monster['Level'],$Max/5+$Monster['Level']);
$Monster['Concentration']=rand($Max/4-$Monster['Level'],$Max/4+$Monster['Level']);
$Monster['Intelligence']=rand($Max/4-$Monster['Level'],$Max/4+$Monster['Level']);
}
$Monster['MaxHP']=$Monster['HP'];
$Monster['MaxMP']=$Monster['MP'];
$Monster=Special($Monster,$Special);
mysql_query("Update Users set Fighting='1' where ID='$Player'") or die("Failed");
echo "<p>You startle the $Special $Name<br /></p>";
Table($Monster, $User, $Special);
}
}
elseif(isset($Action) && $User['Fighting'] != 0)
{
$Special=$_POST['Special'];
$Special=str_replace("%20"," ",$Special);
$Monster['Name']=$_POST['Name'];
$Monster['HP']=$_POST['HP'];
$Monster['Type']=$_POST['Type'];
$Monster['Level']=$_POST['Level'];
$Monster['Spell']=$_POST['Spell'];
$Monster['MP']=$_POST['MP'];
$Monster['MaxHP']=$_POST['MaxHP'];
$Monster['MaxMP']=$_POST['MaxMP'];
$Monster['Strength']=$_POST['Strength'];
$Monster['Constitution']=$_POST['Constitution'];
$Monster['Dexterity']=$_POST['Dexterity'];
$Monster['Concentration']=$_POST['Concentration'];
$Monster['Intelligence']=$_POST['Intelligence'];
$RandDexUser=rand($User['Dexterity']-20,$User['Dexterity']+20);
$RandDexMonster=rand($Monster['Dexterity']-20,$Monster['Dexterity']+20);
if(isset($_POST['UserSpell']))
$SpellID = $_POST['UserSpell'];
if($Action=="attack")
{
$type = "Melee";
$hit = "You attack the $Special $Monster[Name]";
$miss = "You attack the $Special $Monster[Name], but it dodges your attack!";
$block = "You attack the $Special $Monster[Name], but you fail to hurt it!";
}
elseif($Action=="magic")
{
$Query="Select * from UserSpells where ID='$SpellID'";
$Query2=mysql_query($Query) or die("Could not get spells for user");
$Spell=mysql_fetch_array($Query2);
$type = "Magic";
$hit = "You blast the $Special $Monster[Name] with $Spell[Name]";
setcookie('Spellname',$Spell['Name'],time()+60*60*24);
setcookie('Spelllevel',$Spell['Level'],time()+60*60*24);
$miss = "You blast the $Special $Monster[Name] with $Spell[Name], but it dodges your attack!";
$block = "You attack the $Special $Monster[Name] with $Spell[Name], but it has no effect!";
}
elseif($Action=="run")
{
$Randomrun=rand(1,2);
if($Randomrun == 1){
echo "You failed to run";
}
else{
mysql_query("Update Users set Fighting='0' where ID='$Player'") or die("Failed");
echo "<p>You escape the clutches of the $Monster[Name]</p>";
die();
}
}
else
echo $miss;
echo "</p>";
mysql_query("Update Users set HP='$User[HP]', MP='$User[MP]' where ID='$Player'") or die("Could not update player stats");
Table($Monster, $User, $Special);
}
else
{
$Chance=$Monster['Level']-$User['Level'];
$Rand=rand(1,100);
echo "<p>";
if($Rand>=$Chance&&$Action!="use")
{
if($type == "Melee")
$Damage = CalcDamage($User, $Monster, "Melee");
elseif($type == "Magic")
{
if($User['MP']<$Spell['Level'])
echo "You do not have enough MP to cast the spell.<br>";
else
$Damage = Spell($Monster, $User, $Spell);
}
$Monster['HP']-=$Damage;
if($Monster['HP']<=0)
win($Monster,$User,$Special);
if($Damage == 0)
echo $block;
else
echo $hit." for $Damage damage!";
}
elseif($Action=="use")
{
$User=Potion($User,$ItemUsed);
mysql_query("Update Items set Amount=Amount-'1' where ID='$ItemUsed'");
}
else
echo $miss;
$User['HP'] = Turn($Monster, $User, $Special);
if($User['HP']<=0)
{
mysql_query("Update Users set Fighting='0', HP='".$User['HP']."' where ID='$Player'") or die("Failed");
echo "<p>The $Special $Monster[Name] killed you!<br />Please revive</p>";
die();
}
echo "</p>";
mysql_query("Update Users set HP='$User[HP]', MP='$User[MP]' where ID='$Player'") or die("Could not update player stats");
Table($Monster, $User, $Special);
}
}
else
{
$Coord=explode(",",$User['coord']);
if(isset($_POST['up'])){
$Coord[1]+=1;
print "<script type=\"text/javascript\">window.location=\"fight.php\"</script>";
}
echo "<p>Name - Level<br /></p>";
echo "<form action='fight.php' method='post'>";
echo "<p><select class=\"select\" name='Name'>";
if($_COOKIE['Monstername'])
{
$Name = $_COOKIE['Monstername'];
$Query = mysql_query("SELECT * from Monsters where Name='$Name' limit 1") or die("ZOMG no cookie monster");
$QMonster = mysql_fetch_array($Query);
}
?>
</body>
</html>
//------------------------------------
Functions.php (When the monster dies)
//------------------------------------
$_SESSION['Monstername']=1;
echo "<table border=\"0\" align=\"center\"><tr>
<td align=\"center\">$Item $Str $Cons $Int $Conc $Dex $Button</td>
<td align=\"center\">Congratulations! You killed the $Special $Monster[Name]!<br />
You gain $Exp experience, and $Gold2 gold<font style=color:yellow>";