Page 1 of 1

1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 8:24 pm
by n04h
Alright so I just figured out my whole password thing and was getting back into the game when I ran into this

No Creature selected. Go Back!

I understand that this has something to do with a query that went wrong, and I think it my have happened when I accidentally deleted my id under my "creatures" section. Any insight on this?

Re: 1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 8:31 pm
by Torniquet
code and database layout if you please?

Re: 1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 8:41 pm
by n04h
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;
}

$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];
$playerpass = 0;

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$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;
	$sdamage =  $spellinfo3['svalue'];
	$randdamage = rand(0, $sdamage);
	$sdamage = $randdamage + $moddamage; 
	
	echo " You Cast " . $sname . " and do " . $sdamage . " 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);
   $newcreaturehp = $creaturehp - $playerdamage;
  echo "For " . $playerdamage . " points of damage. <br>";
   if ($newcreaturehp < 1)
   {
     echo "The " . $creature . " has been killed";

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


///////////////////////////video 6/////////////////////////////////////////////////////////////
        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 hpoints='$newcreaturehp' 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);
   $newplayerhp = $playerhp - $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>";
  $newplayerhp = $newplayerhp - $extradamage;
  }
     if ($newplayerhp < 1)
   {
     echo $playerinfo3['name'] . " has been killed<br>";
      echo "<a href='gameover.php>Continue'";
      exit;
   }
  $updateplayer="update players set hpoints='$newplayerhp' 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>

Battle.php:

Code: Select all

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

?>
 <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);

$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

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
{
  $creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}

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

/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Hit points = " . $playerhp . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";

///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Hit points = " . $creaturehp . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php?creature=$creature'>Attack!";

?>

Re: 1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 8:49 pm
by n04h
I just realized that the code I used for attack was ahead of where I am right now does anyone have the code for video 5?

Re: 1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 8:54 pm
by PaxBritannia
The error's triggering at the beginning of attack.php:

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
{
  echo "<a href='battle.php'>No Creature selected. Go Back!";
  exit;
}
I would replace

Code: Select all

"if ($creature != 0)"
with

Code: Select all

"if(isset($creature)&&$creature!='')"
In addition to that, battle.php never actually writes to the player's table in the database for the creature so when attack.php tries to read it, it can't.

In regards to the code to video 5, I'm afraid I can't help you find it. Maybe try searching the forums?

pax.

Re: 1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 9:05 pm
by n04h
Now I am getting no response at all when I attack the creature, it just returns as a blank page.

Re: 1'st actual question for this thread :P

Posted: Sun Feb 13, 2011 9:23 pm
by PaxBritannia
Sounds like a parse error.

Check your line endings for semicolons and for unclosed brackets, etc.

If you haven't already, you should ideally add this to the top of every page during development:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
It will turn all error reporting on, and you'll be able to see which lines have the errors.

pax.

Re: 1'st actual question for this thread :P

Posted: Mon Feb 14, 2011 1:14 am
by hallsofvallhalla
DO NOT CHANGE
I would replace
CODE: SELECT ALL
"if ($creature != 0)"
with
CODE: SELECT ALL
"if(isset($creature)&&$creature!='')"
there is a reason for it. Change it back. The reason you are having this error is because creature field under player = 0. If you deleted the creature ID then add it back. To assure you have a creature change the id in the player field to 1 or wherever you have a creature.

Re: 1'st actual question for this thread :P

Posted: Mon Feb 14, 2011 5:48 am
by PaxBritannia
Ok Halls, thanks for the correction. :)

Sorry about that, but I've never went through the tutorials from start to finish, so I don't know how everything fits together.

pax.

Re: 1'st actual question for this thread :P

Posted: Mon Feb 14, 2011 5:03 pm
by hallsofvallhalla
not a problem, your answer wasn't exactly wrong, it is just not how I did it in that tutorial so I do not want to confuse him. I appreciate you helping.