Browser MMO Video #7

Location of the Videos
Post Reply
Mike9730
Posts: 24
Joined: Thu Mar 04, 2010 1:59 am

Re: Video#7

Post by Mike9730 »

whenever i start a battle it says player 1 on the top insted of of the player im logged in as please help
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video#7

Post by Jackolantern »

If you look in your code in that part of your game, you probably still have the placeholder "player1" that was initially added there during the combat test. You would just need to change it to a variable that will replace it with the name of the player from the session variable or from the database.
The indelible lord of tl;dr
Mike9730
Posts: 24
Joined: Thu Mar 04, 2010 1:59 am

Re: Video#7

Post by Mike9730 »

Jackolantern wrote:If you look in your code in that part of your game, you probably still have the placeholder "player1" that was initially added there during the combat test. You would just need to change it to a variable that will replace it with the name of the player from the session variable or from the database.
it dosent say player 1 anywhere

Code: Select all

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

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

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

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

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

$name = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];

if ($type == "healing")
{
   $newhp = $statadd + $playerhp;
   if ($newhp > $playerinfo3['maxhp'])
   {
    $newhp = $playerinfo3['maxhp'];
   }
    $updateplayer="update players set hpoints='$newhp' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

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

}}
////////////////////////////////



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!";

///////////////////new for tutorial 7/////////////////////
echo "<br><a href='useitem.php?creature=$creature'>Use Item";
echo "<br><a href='store.php?creature=$creature'>Go to Store";

?>
thats battle.php
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video#7

Post by Jackolantern »

Have you tracked down which variable is displaying "Player1"?
The indelible lord of tl;dr
ricliv
Posts: 21
Joined: Tue Jul 06, 2010 11:35 am

Re: Video#7

Post by ricliv »

Hey halls, At video 6 you showed how to make the defaults at ConTEXT im getting a pharse error at Line 54 heres my reguser:

Code: Select all

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$pass2=$_POST['pass2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
{
echo "You didn't enter a email address!<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
if ($password==$pass2)
{

$isplayer="SELECT * from players where name='$player'";
$isplayer2=mysql_query($isplayer) or die("Could not query players table");
$isplayer3=mysql_fetch_array($isplayer2);

if(!$_POST['password'] || !$_POST['pass2'])
{
print "You did not enter a password<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
else if($isplayer3 || strlen($player)>21 || strlen($player)<1)
{
print "There is already a player of that name or the name you specified is over 16 letters or less than 1 letter";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$isaddress="SELECT * from players where email='$email'";
$isaddress2=mysql_query($isaddress) or die("not able to query for password");
$isaddress3=mysql_fetch_array($isaddress2);
if($isaddress3)
{
print "There is already a player with that e-mail address";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$password=md5($password);

$SQL = "INSERT into players(name, password, email, level, exper, attack, defense, hpoints, maxhp) VALUES ('$player','$password','$email','1','0','5','5','30','30')";
mysql_query($SQL) or die("could not register");

print "Thank you for registering!";

}
}
}

else
{
print "Your password didn't match or you did not enter a password";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
echo " <A href='login.php'>Login Page</a><br>";
?>
I know $email thing but it still didnt work btw i had red numbers numbers there and you haven't (I mean extremly red numbers) still didnt work i think it took my code to something else :S -Rely

-ZecH^
Rastan
Posts: 126
Joined: Tue Apr 13, 2010 1:48 am

Re: Video#7

Post by Rastan »

Your error looks to be in your $SQL insert. Do you actually have a players table with all of those fields built in it? I didn't see anything wrong right off.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video#7

Post by Jackolantern »

Also remove the 'single-quotes' from any constant numbers in your SQL query. They should only go around strings and PHP variables being used in SQL quries.
The indelible lord of tl;dr
ricliv
Posts: 21
Joined: Tue Jul 06, 2010 11:35 am

Re: Video#7

Post by ricliv »

Ermmm... U know all the numbers in context halls had something else at line (number) 54 how to get that?
ricliv
Posts: 21
Joined: Tue Jul 06, 2010 11:35 am

Re: Video#7

Post by ricliv »

Can anybody paste ur "reguser.php" here i thnik that would be very helpfull..
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

Re: Video#7

Post by Shihonoryu »

The creature wont attack for some reason, the creature attacks turn never executes

Code: Select all

<?php
include 'connect.php';

 session_start();

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='Shihonoryu'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$player = $playerinfo3['name'];
if (isset($_GET['creature']))
{
$creature=$_GET['creature'];
$creatureinfo="SELECT * from creature 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;
}

$playerhp = $playerinfo3['HP'];
$playerattack = $playerinfo3['Attack'];
$playerdefense = $playerinfo3['Defence'];

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


///////////////////////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);
   $newcreaturehp = $creaturehp - $playerdamage;
  echo "For " . $playerdamage . " points of damage. <br>";
   if ($newcreaturehp < 1)
   {
     echo "The " . $creature . " has been killed";
       
        $updatecreature="DELETE from creature where name='$creature' limit 1";
  mysql_query($updatecreature) or die("Could not update creature");
  
  
  ///////////////////lesson 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 gained " . $totalexper . " experiance </br><b><big>" ;
$updateplayer="update players set exper=exper+ '$totalexper' where name = '$player'";
mysql_query($updateplayer) or die("could not update player");



  }
        $updatecreature="update creature set hpoints='$newcreaturehp' where name='$creature' limit 1";
  mysql_query($updatecreature) or die("Could not update creature");


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

}

else
{
   echo $playerinfo3['name'] . " misses!<br>";
}
//////////////////////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);
   $newplayerhp = $playerhp - $creaturedamage;
   echo "For " . $creaturedamage . " points of damage. <br>";
   if ($newplayerhp < 1)
   {
     echo $playerinfo3['name'] . " has been killed<br>";
      echo "<a href='gameover.php'>Continue";
      exit;
   }
  $updateplayer="update player set hpoints='$newplayerhp' where name='player1'";
  mysql_query($updateplayer) or die("Could not update player");
}






else
{
  echo $creature . " misses!";
}
echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
?>
Post Reply

Return to “Older Browser MMO Videos”