Page 1 of 1

Can't Battle in Arena?

Posted: Sun Feb 13, 2011 5:04 pm
by Huezzer
Hey, I've got like 2 or 3 problems that I can't figure out!,

*I can't battle Creatures in Arena, I mean kill them :D, it says ''Could not get arena'' all the time, and I've got table in my phpadmin (Creatures), here's my Battle.php and attack.php codes(Linked Bellow), BTW I've changed the Hpoints to Stamina everywhere if you are wondering..,
And once I made it work, don't know what I did. When I do battle a Creature, it dissapear from the table in phpadmin, I don't want to make new one all the time,

*also when I press other things like ''Inn link or Armorshop link'' it says: ''Could not get player stats!'' .. Please...Thanks

Code: Select all

<?php
include_once 'connect.php';
session_start();

include_once 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php

 


if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='index.php'>Login</a>";
  exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

include_once 'statpanel.php';

$pid = $playerinfo3['id'];
$name = $playerinfo3['name'];
$playersm = $playerinfo3['stamina'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];
$pllocation = $playerinfo3['location'];
?>
<div id="table">
<?php

 if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid' AND id ='$pid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}
else
{

$iname = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];
 
 if ($type == "healing")
 {
   $newhp = $statadd + $playerhp;
   if ($newsm > $playerinfo3['maxsm'])
   {
    $newsm = $playerinfo3['maxsm'];
   }
    $updateplayer="update players set stamina='$newsm' where id='$pid'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where id='$pid' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");
   
   $playersm = $newsm;
  
  echo "Used " . $iname . " and recovered " . $statadd . ".<br>";
 }

}}

 
 


$creature = $playerinfo3['creature'];
 if ($creature != 0)
{
 $creatureinfo="SELECT * from creatures where id='$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
////////////////////new for video 20
$areaninfo="SELECT * from locations where location='$pllocation' AND type='arena'";
$areaninfo2=mysql_query($areaninfo) or die("could not get arena");
$areaninfo3=mysql_fetch_array($areaninfo2);
$arenalevel = $areaninfo3['level'];

  $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
$cid = $creatureinfo3['id'];
$updateplayer="update players set creature='$cid' where name='$name'";
  mysql_query($updateplayer) or die("Could not update player");
}

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['stamina'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];



?>
</div>
<div id="player">
<?php
/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Stamina = " . $playersm . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";
?>
</div>
<div id="creature">
<?php
///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Stamina = " . $creaturesm . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php'>Attack</a>";
echo "<br><a href='usemagic.php'>Use Magic</a>";
echo "<br><a href='useitem.php'>Use Item</a>";
echo "<br><a href='game.php'>Exit Arena</a>";


?>
</div>

<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>
Here's my Attack.php

Code: Select all

<?php
include_once 'connect.php';
  session_start();
  include_once 'logo.php';
?>
  
  <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">

<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>
<?php
 $playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
 include_once 'statpanel.php';
$pid = $playerinfo3['id'];
 ?>
</div>
<div id="table">
<?php

 $creature = $playerinfo3['creature'];
 if ($creature != 0)
{
 $creatureinfo="SELECT * from creatures where id='$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("Could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
  echo "<a href='battle.php'>No Creature selected. Go Back!";
  exit;
}

$playersm = $playerinfo3['stamina'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];
$playerpass = 0;

$creature = $creatureinfo3['name'];
$creaturesm = $creatureinfo3['stamina'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];

 ?>
 </div>

 <div id="player">
 <?php
 ///////////////////////players turn////////////////////
  
 echo "<center><u> " . $playerinfo3['name'] . "'s Attack</u><br>";
 if (isset($_GET['sid']))
{
   $sid=$_GET['sid'];
   $spellinfo="SELECT * from playermagic where sid='$sid' AND pid='$pid'";
 $spellinfo2=mysql_query( $spellinfo) or die("Could not get spell!");
 $spellinfo3=mysql_fetch_array( $spellinfo2);
 $sname = $spellinfo3['name'];
if ($spellinfo3['type'] == "combat")
	{
	if ($spellinfo3['scost'] > $playerinfo3['spoints'])
	{
	echo "You do not have enough Spell Points for this spell.<br>";
	 echo "<a href='battle.php'>Go Back";
	exit;
	}
	else
	{
	$spoints = $spellinfo3['scost'];
	$moddamage = $spellinfo3['svalue'] / 10;
	$moddamage = (int)$moddamage;
	$damage =  $spellinfo3['svalue'];
	$randdamage = rand(0, $sdamage);
	$damage = $randdamage + $moddamage;
	
	echo " You Cast " . $sname . " and do " . $damage . " points of damage";
	$playerpass = 1;
	  $updateplayer="update players set spoints=spoints-'$spoints' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");
	}} 
} 




if ($playerpass != 1)
{

 $weaponinfo="SELECT * from playerweapons where equip=1 AND pid='$pid'";
$weaponinfo2=mysql_query($weaponinfo) or die("could not get player weapon!");
$weaponinfo3=mysql_fetch_array($weaponinfo2);

$playerattack = rand(1,20) + $playerattack + $weaponinfo3['rating'];
//////////////////////////////////////////////////////
$creaturedefense = rand(1,20) + $creaturedefense;

echo $playerinfo3['name'] . "'s Attack roll is " . $playerattack . "<br>";
echo $creature . "'s defense roll is " . $creaturedefense. "<br>";

if ($playerattack  > $creaturedefense)
{
  echo  $playerinfo3['name'] . " " . $weaponinfo3['hittext'] . " and hits!<br>"; 
  
 
  $weapdamage = $weaponinfo3['damage'];
  $halfdamage = $weaponinfo3['damage'] / 2;
  $playerdamage = rand($halfdamage,$weapdamage);
   $newcreaturesm = $creaturesm - $playerdamage;
  echo "For " . $playerdamage . " points of damage. <br>";
   if ($newcreaturesm < 1)
   {
     echo "The " . $creature . " has been killed";

   $crmaxsm=$creatureinfo3['maxstamina'];
       $updatecreature="update creatures set hpoints='$crmaxsm' where name='$creature' limit 1";
   mysql_query($updatecreature) or die("Could not update creature");



        if ($playerinfo3['level'] > $creatureinfo3['level'])
        {
         $firstmod = $playerinfo3['level'] - $creatureinfo3['level'];
         $secondmod = $firstmod * 10 ;
         if ($secondmod > 90){$secondmod = 90;}
         $thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
         $totalexper =$creatureinfo3['exper'] - $thirdmod;
        }
        else
        {
         $firstmod = $creatureinfo3['level'] - $playerinfo3['level'];
         $secondmod = $firstmod * 10 ;
         if ($secondmod > 90){$secondmod = 90;}
         $thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
         $totalexper =$creatureinfo3['exper'] + $thirdmod;
        }
          $totalexper = (int)$totalexper;

           echo "<br><b><big>You gain " . $totalexper . " experience.</b></big><br>";
      $updateplayer="update players set exper=exper+'$totalexper',creature=0 where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");



      echo "<a href='battle.php'>Go Back";
      exit;
   }

  $updatecreature="update creatures set stamina='$newcreaturesm' where name='$creature' limit 1";
  mysql_query($updatecreature) or die("Could not update creature");
}
else
{
  echo  $playerinfo3['name'] . " " . $weaponinfo3['hittext'] . " and misses!"; 
}}
?>
</div>
<div id="creature">
<?php
 //////////////////////creatures turn //////////////////

echo "<center><u> " . $creature . "'s Attack</u><br>";


 
 ///////hit location//////////////////////////////////////
		$randlocation = rand(0,100);
		if ($randlocation <= 15)
		{$location = "arms";}
		elseif ($randlocation <= 70)
		{$location = "chest";} 
		elseif ($randlocation <= 90)
		{$location = "legs";}
		elseif ($randlocation <= 100)
		{$location  = "head";}
		
   $playerarmor="SELECT * from playerarmor where pid='$pid' AND location='$location' AND equip=1";
   $playerarmor2=mysql_query($playerarmor) or die("Could not get player armmor");
   $playerarmor3=mysql_fetch_array($playerarmor2);
   
   $noarmor = 0;
   
   if(is_null($playerarmor3['rating']))
   {
   $playerarmor3['rating'] = 0;
   $noarmor = 1;
   } 
  
  
   ////////////////////////////////////
$creatureattack = rand(1,20) + $creatureattack;
$playerdefense = rand(1,20) + $playerdefense + $playerarmor3['rating'];

echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";

if ($creatureattack  > $playerdefense)
{

  echo $creature . " hits for a strike to the " . $location . "<br>";
   $creaturedamage = rand(1,6);
   $newplayersm = $playersm - $creaturedamage;
   echo "For " . $creaturedamage . " points of damage. <br>";
  if ($noarmor == 1)
  {
  echo "You are not wearing armor on your " . $location . ".<br>";
   $extradamage = rand(1,3);
   echo "You take an additional " . $extradamage . " points of damage.<br>";
  $newplayersm = $newplayersm - $extradamage;
  }
     if ($newplayersm < 1)
   {
     echo $playerinfo3['name'] . " has been killed<br>";
      echo "<a href='gameover.php>Continue'";
      exit;
   }
  $updateplayer="update players set stamina='$newplayersm' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");
}
else
{
  echo $creature . " misses!";
}
 echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
 ?>
 </div>
//Huezzer, Thanks for help!

Re: Can't Battle in Arena?

Posted: Sun Feb 13, 2011 6:47 pm
by PaxBritannia
The error you're getting is sent by this part of the script:

Code: Select all

////////////////////new for video 20
$areaninfo="SELECT * from locations where location='$pllocation' AND type='arena'";
$areaninfo2=mysql_query($areaninfo) or die("could not get arena");
The mysql query is failing and triggering the error. Check to see that your table and column names in the query are correct and that the variable $pllocation is not empty when the script reaches there. The reason the query is failing is probably the same reason why the ''Inn link or Armorshop link'' queries are also failing.

As for your creature rows disappearing, there are two ways to solve it. However, I'm assuming you still want the creatures to die, but just want to not have to enter each entry every time you add a creature.

There are several ways to do this, but for now, adding another column in the table for the number of creatures called 'amount' should be fine. Just alter your script to instead of deleting the row, to decrease the amount by one. When you want to add creatures, all you have to do is increase that number for each row in the creature table.

pax.

Re: Can't Battle in Arena?

Posted: Thu Feb 17, 2011 6:09 pm
by Huezzer
Hey again, My Arena works to join now, but the creature name or stats doesn't show up, also when I press attack it's error...Don't know what's wrong

Re: Can't Battle in Arena?

Posted: Thu Feb 17, 2011 6:59 pm
by PaxBritannia
What exactly is the error?

pax.

Re: Can't Battle in Arena?

Posted: Sat Feb 19, 2011 2:05 am
by Huezzer
The Error that I've is:( ! ) Parse error: syntax error, unexpected '}' in C:\wamp\www\tutorial\battle.php on line 97

And that includes: I can't see what creature I attack and I can't press attack then is says error something

Re: Can't Battle in Arena?

Posted: Sat Feb 19, 2011 6:52 am
by PaxBritannia
May I have the code for battle.php?

pax.

Re: Can't Battle in Arena?

Posted: Sat Feb 19, 2011 9:37 am
by Huezzer
Sure :) Btw I've changed the hpoints to stamina: Can't figure out pllocation don't know that's the problem with all of it? (In the middle of the text) SOmehting like that :P
Battle.php

Code: Select all

<?php
include_once 'connect.php';
session_start();

include_once 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php

 


if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

include_once 'statpanel.php';

$pid = $playerinfo3['id'];
$name = $playerinfo3['name'];
$playerstamina = $playerinfo3['stamina'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

?>
<div id="table">
<?php

 if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid' AND id ='$pid'";
$iteminfo2=mysql_query($iteminfo) or die("Could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}
else
{

$iname = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];
 
 if ($type == "healing")
 {
   $newstamina = $statadd + $playerstamina;
   if ($newstamina > $playerinfo3['maxsm'])
   {
    $newstamina = $playerinfo3['maxsm'];
   }
    $updateplayer="update players set stamina='$newstamina' where id='$pid'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where id='$pid' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");
   
   $playerstamina = $newstamina;
  
  echo "Used " . $iname . " and recovered " . $statadd . ".<br>";
 }

}}





$creature = $playerinfo3['creature'];
 if ($creature != 0)
{
 $creatureinfo="SELECT * from creatures where id='$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}
else
{
////////////////////new for video 20
if (isset($_GET['pllocation']))

$playerinfo3=$_GET['pllocation'];
$arenainfo="SELECT * from locations where location='$pllocation' AND type='arena'";
$arenainfo2=mysql_query($arenainfo) or die("Could not get arena");
$areaninfo3=mysql_fetch_array($arenainfo2);
$arenalevel = $areaninfo3['level'];

  $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("Could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
$cid = $creatureinfo3['id'];
$updateplayer="update players set creature='$cid' where name='$name'";
  mysql_query($updateplayer) or die("Could not update player");
{

$creature = $creatureinfo3['name'];
$creaturestamina = $creatureinfo3['stamina'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];



?>
</div>
<div id="player">
<?php
/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Stamina = " . $playerstamina . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";
?>
</div>
<div id="creature">
<?php
///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Stamina = " . $creaturestamina . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php'>Attack</a>";
echo "<br><a href='usemagic.php'>Use Magic</a>";
echo "<br><a href='useitem.php'>Use Item</a>";
echo "<br><a href='index.php'>Exit Arena</a>";


?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>
Thanks, Huezzer. ;)

Re: Can't Battle in Arena?

Posted: Sat Feb 19, 2011 1:02 pm
by PaxBritannia
The code was missing some closing brackets and had an extra opening bracket.

I'm not sure with the logic of the code, so I don't know where to insert the missing brackets. :D

But I've read through it, and as far as I can tell, change this:

Code: Select all

    $creature = $playerinfo3['creature'];
    if ($creature != 0)
    {
    $creatureinfo="SELECT * from creatures where id='$creature'";
    $creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    }
    else
    {
    ////////////////////new for video 20
    if (isset($_GET['pllocation']))

    $playerinfo3=$_GET['pllocation'];
    $arenainfo="SELECT * from locations where location='$pllocation' AND type='arena'";
    $arenainfo2=mysql_query($arenainfo) or die("Could not get arena");
    $areaninfo3=mysql_fetch_array($arenainfo2);
    $arenalevel = $areaninfo3['level'];

      $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
    $creatureinfo2=mysql_query($creatureinfo) or die("Could get a creature!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    $cid = $creatureinfo3['id'];
    $updateplayer="update players set creature='$cid' where name='$name'";
      mysql_query($updateplayer) or die("Could not update player");
    {

    $creature = $creatureinfo3['name'];
    $creaturestamina = $creatureinfo3['stamina'];
    $creatureattack = $creatureinfo3['attack'];
    $creaturedefense = $creatureinfo3['defense'];
to this:

Code: Select all

    $creature = $playerinfo3['creature'];
    if ($creature != 0)
    {
    $creatureinfo="SELECT * from creatures where id='$creature'";
    $creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    }
    else
    {
    ////////////////////new for video 20
    if (isset($_GET['pllocation'])){

    $playerinfo3=$_GET['pllocation'];
    $arenainfo="SELECT * from locations where location='$pllocation' AND type='arena'";
    $arenainfo2=mysql_query($arenainfo) or die("Could not get arena");
    $areaninfo3=mysql_fetch_array($arenainfo2);
    $arenalevel = $areaninfo3['level'];
    }

      $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
    $creatureinfo2=mysql_query($creatureinfo) or die("Could get a creature!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    $cid = $creatureinfo3['id'];
    $updateplayer="update players set creature='$cid' where name='$name'";
      mysql_query($updateplayer) or die("Could not update player");
    }

    $creature = $creatureinfo3['name'];
    $creaturestamina = $creatureinfo3['stamina'];
    $creatureattack = $creatureinfo3['attack'];
    $creaturedefense = $creatureinfo3['defense'];
Does that fix it?

pax.

Re: Can't Battle in Arena?

Posted: Sat Feb 19, 2011 2:28 pm
by Huezzer
Yes the other thing but now since I changed it: ( ! ) Notice Undefined variable: arenalevel in C:/wamp/www/tutorial/battle.php on line 103

Also when I press attack inside it says: ( ! ) Parse error: syntax error, unexpected ';', expecting '{' in C:\wamp\www\tutorial\attack.php on line 164

I'll link both my codes: First battle.php then attack.php

Battle.php

Code: Select all

<?php
include_once 'connect.php';
session_start();

include_once 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php

 


if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

include_once 'statpanel.php';

$pid = $playerinfo3['id'];
$name = $playerinfo3['name'];
$playerstamina = $playerinfo3['stamina'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

?>
<div id="table">
<?php

 if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid' AND id ='$pid'";
$iteminfo2=mysql_query($iteminfo) or die("Could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}
else
{

$iname = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];
 
 if ($type == "healing")
 {
   $newstamina = $statadd + $playerstamina;
   if ($newstamina > $playerinfo3['maxsm'])
   {
    $newstamina = $playerinfo3['maxsm'];
   }
    $updateplayer="update players set stamina='$newstamina' where id='$pid'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where id='$pid' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");
   
   $playerstamina = $newstamina;
  
  echo "Used " . $iname . " and recovered " . $statadd . ".<br>";
 }

}}



$creature = $playerinfo3['creature'];
    if ($creature != 0)
    {
    $creatureinfo="SELECT * from creatures where id='$creature'";
    $creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    }
    else
    {
    ////////////////////new for video 20
    if (isset($_GET['pllocation'])){

    $playerinfo3=$_GET['pllocation'];
    $arenainfo="SELECT * from locations where location='$pllocation' AND type='arena'";
    $arenainfo2=mysql_query($arenainfo) or die("Could not get arena");
    $arenainfo3=mysql_fetch_array($arenainfo2);
    $arenalevel = $arenainfo3['level'];
    }

      $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
    $creatureinfo2=mysql_query($creatureinfo) or die("Could get a creature!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    $cid = $creatureinfo3['id'];
    $updateplayer="update players set creature='$cid' where name='$name'";
      mysql_query($updateplayer) or die("Could not update player");
    }

    $creature = $creatureinfo3['name'];
    $creaturestamina = $creatureinfo3['stamina'];
    $creatureattack = $creatureinfo3['attack'];
    $creaturedefense = $creatureinfo3['defense'];



?>
</div>
<div id="player">
<?php
/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Stamina = " . $playerstamina . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";
?>
</div>
<div id="creature">
<?php
///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Stamina = " . $creaturestamina . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php'>Attack</a>";
echo "<br><a href='usemagic.php'>Use Magic</a>";
echo "<br><a href='useitem.php'>Use Item</a>";
echo "<br><a href='index.php'>Exit Arena</a>";


?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>
Attack.php

Code: Select all

<?php
    include_once 'connect.php';
      session_start();
      ///new for video 8/////////////
    include_once 'logo.php';
    ?>
     
      <link href="style.css" rel="stylesheet" type="text/css" />
    <div id="login2" div align="center">

    <?php
    if (isset($_SESSION['player']))
    {
      $player=$_SESSION['player'];
    }
    else
    {
      echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
      exit;
    }




    $playerinfo="SELECT * from players where name='$player'";
    $playerinfo2=mysql_query($playerinfo) or die("Could not get player stats!");
    $playerinfo3=mysql_fetch_array($playerinfo2);

    if (isset($_GET['creature']))
    {
    $creature=$_GET['creature'];
    $creatureinfo="SELECT * from creatures where name = '$creature'";
    $creatureinfo2=mysql_query($creatureinfo) or die("Could not get the creature you were fighting!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
	

    }
    else
    {
      echo "<a href='battle.php'>No Creature selected. Go Back!";
      exit;
    }

    $playersm = $playerinfo3['stamina'];
    $playerattack = $playerinfo3['attack'];
    $playerdefense = $playerinfo3['defense'];

    $creature = $creatureinfo3['name'];
    $creatureid = $creatureinfo3['id'];
    $creaturelvl = $creatureinfo3['level'];
    $creatureexp = $creatureinfo3['exper'];
    $creaturesm = $creatureinfo3['stamina'];
    $creatureattack = $creatureinfo3['attack'];
    $creaturedefense = $creatureinfo3['defense'];
    $creaturegold = $creatureinfo['gold'];
	$creatureloot = $creatureinfo['loot'];
	$hasloot = $creatureinfo['isloot'];
   
    ?>
    </div>
    
    <div id="player">
    <?php
    ///////////////////////players turn////////////////////

    echo "<u> " . $playerinfo3['name'] . "'s Attack</u><br>";
    $playerattack = rand(1,20) + $playerattack;
    $creaturedefense = rand(1,20) + $creaturedefense;

    echo $playerinfo3['name'] . "'s Attack roll is " . $playerattack . "<br>";
    echo $creature . "'s defense roll is " . $creaturedefense. "<br>";

    if ($playerattack  > $creaturedefense)
    {
      echo $playerinfo3['name'] . " hits! <br>";
      $playerdamage = rand(1,6);
       $newcreaturestamina = $creaturestamina - $playerdamage;
      echo "For " . $playerdamage . " points of damage. <br>";
       if ($newcreaturestamina < 1)
       {
         echo "The " . $creature . " has been killed";

        $crmaxsm=creatureinfo3['maxstamina'];
        $updatecreature="update creatures set stamina='$crmaxsm where name'$creature' limit 1";
            mysql_query($updatecreature) or die("Could not update creature");
			
			//////////
			/////////
			////////////
 creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature);

///////

           if ($playerinfo3['level'] > $creatureinfo3['level'])
            {
             $firstmod = $playerinfo3['level'] - $creatureinfo3['level'];
             $secondmod = $firstmod * 10 ;
             if ($secondmod > 90){$secondmod = 90;}
             $thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
             $totalexper =$creatureinfo3['exper'] - $thirdmod;
            }
            else
            {
             $firstmod = $creatureinfo3['level'] - $playerinfo3['level'];
             $secondmod = $firstmod * 10 ;
             if ($secondmod > 90){$secondmod = 90;}
             $thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
             $totalexper =$creatureinfo3['exper'] + $thirdmod;
            }
              $totalexper = (int)$totalexper;

               echo "<br><b><big>You gain " . $totalexper . " experience.</b></big><br>";
          $updateplayer="update players set exper=exper+'$totalexper' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");



          echo "<a href='battle.php'>Go Back";
          exit;
       }

      $updatecreature="update creatures set stamina='$newcreaturestamina' where name='$creature' limit 1";
      mysql_query($updatecreature) or die("Could not update creature");
    }
    else
    {
       echo $playerinfo3['name'] . " misses!<br>";
    }
    ?>
    </div>
    <div id="creature">
    <?php
    //////////////////////creatures turn //////////////////

    echo "<u> " . $creature . "'s Attack</u><br>";
    $creatureattack = rand(1,20) + $creatureattack;
    $playerdefense = rand(1,20) + $playerdefense;

    echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
    echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";

    if ($creatureattack  > $playerdefense)
    {
      echo $creature . " hits! <br>";
      $creaturedamage = rand(1,6);
       $newplayerstamina = $playerstamina - $creaturedamage;
       echo "For " . $creaturedamage . " points of damage. <br>";
       if ($newplayerstamina < 1)
       {
         echo $playerinfo3['name'] . " has been killed<br>";
          echo "<a href='gameover.php>Continue'";
          exit;
       }
      $updateplayer="update players set stamina='$newplayerstamina' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");
    }
    else
    {
      echo $creature . " misses!";
    }
    echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
    
	//////First Function/////
	function creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature);
	{
	$isloot = rand(0,$creaturegold);
	$isloot = rand(0,100);
   
	
	echo "You Loot " . $isgold . " gold pieces.<br>";
	
	$updateplayer="update players set gold=gold-'$isgold' where id='$player'";
  mysql_query($updateplayer) or die("Could not update player");
  
   
           if($isloot < $hasloot)
		   {
		   echo "You loot " . $creatureloot . " on the ". $creature . ".<br>";
		   ///////////////////////////////////Pull The items info:
		     $critem="SELECT * from store where name='$creatureloot'";
			$critem2=mysql_query($critem) or die("Could not get beast item");
			$critem3=mysql_fetch_array($critem2);
			//////////////////////Give it to player
			randid4 = rand(999,9999999);
			$itembought = "INSERT into inventory(id, name, stats, statadd, randid, type) VALUES
			('$pid','$critem3[name]','$critem3[stats]','$critem3[statadd]','$randid4','$critem3[type]')";
			      mysql_query($itembought) or die("Could not insert item into backpack");
				  
				  }
				  else
				  {
				  echo "You find no items of value on the beast!.<br>";
	}
	return $hasloot;
	}
	
	
	?>
    </div>
  
	
	
	
	
	
	
	?>
    </div>
Thanks, Huezzer :)

Re: Can't Battle in Arena?

Posted: Sun Feb 20, 2011 12:37 pm
by PaxBritannia
The missing variable is $arena level. We could just remove the variable in this case, but instead, we'll add in an else clause, so if the location is set then it will filter the creatures by level.

Change this:

Code: Select all

       $arenalevel = $arenainfo3['level'];
        }

          $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
        $creatureinfo2=mysql_query($creatureinfo) or die("Could get a creature!");
To this:

Code: Select all

        $arenalevel = $arenainfo3['level'];
        $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
        }else{
        $creatureinfo="SELECT * from creatures order by rand() limit 1";
        }      
        $creatureinfo2=mysql_query($creatureinfo) or die("Could get a creature!");
The error on attack.php is due to an extra semi-colon :lol:

Code: Select all

       
       //////First Function/////
       function creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature);
       {
       $isloot = rand(0,$creaturegold);
       $isloot = rand(0,100);
there shouldn't be a semicolon between the function and the opening brackets:

Code: Select all

       
       //////First Function/////
       function creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature)
       {
       $isloot = rand(0,$creaturegold);
       $isloot = rand(0,100);
Let us know how it goes. :)

pax.