Browser MMO Tutorial

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Watcher
Posts: 6
Joined: Thu Feb 17, 2011 2:55 am

Browser MMO Tutorial

Post by Watcher »

I just finished Video's 7 a,b,c; I have been fine up till now, but I buy and item from store and goto try and use it and it says nothing in inventory.
Any help would be appreciated.

Watcher
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Browser MMO Tutorial

Post by hallsofvallhalla »

it could be anything, you need to post your store.php and any related scripts so we can look for errors. Also this goes in the mmo tutorial topic so I will move this shortly.
Watcher
Posts: 6
Joined: Thu Feb 17, 2011 2:55 am

Re: Browser MMO Tutorial

Post by Watcher »

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

  $creature=$_GET['creature'];
$counter = 0;

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

echo "<small>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $invinfo="SELECT * from store where amount > 0";
      $invinfo2=mysql_query($invinfo) or die("could not select anything from the store.");
      print "<table border='1' bordercolor='white' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</td><td>Stat<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td>Price<font color='ffffff'>______</td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      $counter = 1;
      print "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td>$invinfo3[price]</td><td><A href='buyitem.php?randid=$invinfo3[randid]&creature=$creature'>Buy Item</td></tr>";

      }

      print "</table>";
      print "</td></tr></table>";
      print "</center>";
      echo "</small>";

      if ($counter == 0)
      {
            echo "<center>There is nothing in the store at this time.<br>";
            echo "<a href='battle.php?creature=$creature'>Go Back</center>";
            exit;
      }
  echo "<center><a href='battle.php?creature=$creature'>NeverMind</center>";
  
  ?>
Watcher
Posts: 6
Joined: Thu Feb 17, 2011 2:55 am

Re: Browser MMO Tutorial

Post by Watcher »

oops, firsts one was store.php

this one is buyitem.php

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

?>
Watcher
Posts: 6
Joined: Thu Feb 17, 2011 2:55 am

Re: Browser MMO Tutorial

Post by Watcher »

this is useitem.php

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

$creature=$_GET['creature'];

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

$playerid = $playerinfo3['id'];

$counter = 0;
echo "<small>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $invinfo="SELECT * from inventory where id='$playerid'";
      $invinfo2=mysql_query($invinfo) or die("could not select player inventory");
      print "<table border='1' bordercolor='white' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</font></td><td>Stat<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td><font color='ffffff'>________________</td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      print "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td><A href='battle.php?randid=$invinfo3[randid]&creature=$creature'>Use Item</td></tr>";
       $counter = 1;

      }

      print "</table>";
      print "</td></tr></table>";
      print "</center>";
       echo "</small>";

      if ($counter == 0)
      {
            echo "<center>You have Nothing in your inventory!<br>";
            echo "<a href='battle.php?creature=$creature'>Go Back</center>";
            exit;
      }

    echo "<center><a href='battle.php?creature=$creature'>NeverMind</center>";
    
    ?>
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Browser MMO Tutorial

Post by Jackolantern »

Remember to put your code into code tags so it is properly formatted. I edited your posts to code the scripts.
The indelible lord of tl;dr
Klown
Posts: 90
Joined: Tue Feb 22, 2011 5:59 am

Re: Browser MMO Tutorial

Post by Klown »

I could be wrong but the following code:

while($invinfo3=mysql_fetch_array($invinfo2))
{
$counter = 1;
print "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td>$invinfo3[price]</td><td><A href='buyitem.php?randid=$invinfo3[randid]&creature=$creature'>Buy Item</td></tr>";

}

should be written with single quotes inside the array variables like this:

while($invinfo3=mysql_fetch_array($invinfo2))
{
$counter = 1;
print "<tr><td>$invinfo3['name']</td><td>$invinfo3[stats]</td><td>$invinfo3['statadd']</td><td>$invinfo3['type']</td><td>$invinfo3['price']</td><td><A href='buyitem.php?randid=$invinfo3['randid']&creature=$creature'>Buy Item</td></tr>";

}


not sure if this will help but you could give it a try... i havent downloaded any of the tutorials scripts so im not sure if this was how it was intended.

-klown
if( $myGames != "Crap" ) {
  • please_donate( $money );
} else {
  • just_enjoy();
}
Watcher
Posts: 6
Joined: Thu Feb 17, 2011 2:55 am

Re: Browser MMO Tutorial

Post by Watcher »

This is the error message I got after adding the single quotes, thanks for trying, I copied all codes directly from where the videos are.

( ! ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\tutorial\store.php on line 35
User avatar
janiksxxl
Posts: 16
Joined: Sun Feb 28, 2010 8:02 pm

Re: Browser MMO Tutorial

Post by janiksxxl »

I haven't seen all these video, but as much as i can understand in buyitem.php i didn't found place where you put item in your backpack/inventory table. Specific mysql insert query etc code.
Image
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Browser MMO Tutorial

Post by Baseball435 »

Where it says $Invinfo3[name] , and $invinfo3[stats] , and $invinfo3[randid] change them to $invinfo3['name'] , and $invinfo3['stats'] , and $invinfo3['randid']
Post Reply

Return to “Beginner Help and Support”