Browser MMO Video#11

Location of the Videos
rafalsa
Posts: 1
Joined: Thu Jul 26, 2012 11:51 pm

Re: Browser MMO Video#11

Post by rafalsa »

Hey guys. I know the videos are old but I'm still gonna ask. My startpanel.php isn't working properly. I'm receiving error for Undefined variable: playerinfo3 on lines:3,7,8 and 12. I rewrited the code from the video cuz I couldn't download the .zip file. I can't find any mistake :/. Here's my code:

Code: Select all

<div id="lpanel">
<?php
echo "<u><b> " . $playerinfo3['name'] . "</b></u><br>";



echo "Attack = " . $playerinfo3['attack'] . "<br>";
echo "Defense = " . $playerinfo3['defense'] . "<br>";
echo "Hit Points<br>";
echo "Spell Point<br><br>";
echo "<b><big><u>Gold</u></big></b>";
echo $playerinfo3['gold'];
?>
</div>

<div id="hpointsback">
<?php
echo "<img src='images/barback.jpg'>";
?>
</div>

<div id="hpoints">
<php?
    $width = ($playerinfo3['hpoints'] / $playerinfo3['maxhp']) * 100;
echo "<img src='imgaes/hpoints.jpg' width='$width' height='15' >";
?>
</div>

<div id="spointsback">
<?php
echo "<img src='images/barback.jpg'>";
?>
</div>

<div id="spoints">
<php?
$width = ($playerinfo['spoints'] / $playerinfo3['maxspoints']) * 100;
echo "<img src='imgaes/spoints.jpg' width='$width' height='15' >";
?>
</div>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Browser MMO Video#11

Post by Jackolantern »

Where is the rest of the script? As it stands, you are not defining what exactly is supposed to be in $playerinfo3.
The indelible lord of tl;dr
Hotke
Posts: 19
Joined: Fri Jul 02, 2010 12:58 pm

Re: Browser MMO Video#11

Post by Hotke »

Code: Select all

echo "<img src='imgaes/hpoints.jpg' width='$width' height='15' >";

Code: Select all

echo "<img src='imgaes/spoints.jpg' width='$width' height='15' >";
</div>
Typo in images, probably not your biggest problem, but worth to change
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Browser MMO Video#11

Post by OldRod »

Been a while since I did that tutorial... I think playerinfo3 is defined in another file and is from the result of a query. That file is included in the one you partially posted. Check to make sure that include is OK. Otherwise, we need to see where playerinfo3 is being loaded/defined.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Browser MMO Video#11

Post by hallsofvallhalla »

correct that array is built from the first query run on index page.
espe
Posts: 32
Joined: Sat Jul 14, 2012 12:46 pm

Re: Browser MMO Video#11

Post by espe »

Thanks for this tutorial. Im watching all videos day for day and this is the first code i used for now (much has to follow :o ).

Image

Edit: Wops, made a better rework. Wish I could just program better :lol:
Image
Skippy1300
Posts: 12
Joined: Thu Aug 01, 2013 10:55 pm

Re: Browser MMO Video#11

Post by Skippy1300 »

So I've followed this tutorial but when I go to fight an enemy, it all looks fine but as soon as I refresh the page, the enemies name, hit points, attack, and defense all disappear.
This is what it looks like:
bob2
Hit points = 11
Attack = 6
Defense = 7



Hit points =
Attack =
Defense =


Attack!
Use Item
Run

This is my battle.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['strength'];
$playerdefense = $playerinfo3['defense'];

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 . " hit points.<br>";
}
}}

$enemies = $playerinfo3['enemies'];
if ($enemies != 0)
{
$enemiesinfo="SELECT * from enemies where name = '$enemies'";
$enemiesinfo2=mysql_query($enemiesinfo) or die("could not get the enemies you were fighting!");
$enemiesinfo3=mysql_fetch_array($enemiesinfo2);
}
else
{
$enemiesinfo="SELECT * from enemies order by rand() limit 1";
$enemiesinfo2=mysql_query($enemiesinfo) or die("could get an enemy!");
$enemiesinfo3=mysql_fetch_array($enemiesinfo2);
$cid=$enemiesinfo3['id'];
$updateplayer="update players set enemies='$cid' where name='$player'";
mysql_query($updateplayer) or die("Could not update player");
}

$enemies = $enemiesinfo3['name'];
$enemieshp = $enemiesinfo3['hpoints'];
$enemiesattack = $enemiesinfo3['attack'];
$enemiesdefense = $enemiesinfo3['defense'];

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

////enemies info////
echo "<u> " . $enemiesinfo3['name'] . "</u><br>";
echo "Hit points = " . $enemieshp . "<br>";
echo "Attack = " . $enemiesattack . "<br>";
echo "Defense = " . $enemiesdefense . "<br><br><br>";

echo "<A href='attack.php?enemies=$enemies'>Attack!";

echo "<br><a href='useitem.php?enemies=$enemies'>Use Item";
echo "<br><a href='index.php?'>Run";

?>
This is my attack.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);

$enemies = $playerinfo3['enemies'];
if ($enemies !=0)
{
$enemiesinfo="SELECT * from enemies where name = '$enemies'";
$enemiesinfo2=mysql_query($enemiesinfo) or die("could not get the enemies you were fighting!");
$enemiesinfo3=mysql_fetch_array($enemiesinfo2);
}
else
{
echo "<a href='battle.php'>No Enemies selected. Go Back!";
exit;
}

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

$enemies = $enemiesinfo3['name'];
$enemieshp = $enemiesinfo3['hpoints'];
$enemiesattack = $enemiesinfo3['attack'];
$enemiesdefense = $enemiesinfo3['defense'];

////Players turn////

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

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

if ($playerattack > $enemiesdefense)
{
echo $playerinfo3['name'] . " fucked up " . $enemies . "!<br>";
$playerdamage = rand(1,6);
$newenemieshp = $enemieshp - $playerdamage;
echo "for " . $playerdamage . " points of damage. <br>";
if ($newenemieshp < 1)
{
echo "The " . $enemies . " has been killed";
////$updateenemies="DELETE from enemies where name='$enemies' limit 1";
////mysql_query($updateenemies) or die("Could not update enemies");

if ($playerinfo3['level'] > $enemiesinfo3['level'])
{
$firstmod = $playerinfo3['level'] - $enemiesinfo3['level'];
$secondmod = $firstmod * 10 ;
if ($secondmod > 90){$secondmod = 90;}
$thirdmod = ($secondmod / 100) * $enemiesinfo3['experience'];
$totalexperience = $enemiesinfo3['experience'] - $thirdmod;
}
else
{
$firstmod = $enemiesinfo3['level'] - $playerinfo3['level'];
$secondmod = $firstmod * 10 ;
if ($secondmod > 90){$secondmod = 90;}
$thirdmod = ($secondmod / 100) * $enemiesinfo3['experience'];
$totalexperience = $enemiesinfo3['experience'] + $thirdmod;
}
echo "<br><b><big>You gain " . $totalexperience . " experience.</b></big><br>";
$updateplayer="update players set experience=experience+'$totalexperience' ,enemies=0 where name='$name'";
mysql_query($updateplayer) or die("Could not update player");

echo "<a href='battle.php'>Go Back";
exit;
}
$updateenemies="update enemies set hpoints='$newenemieshp' where name='$enemies'";
mysql_query($updateenemies) or die("could not update enemies");
}
else
{
echo $playerinfo3['name'] . " misses!<br>";
}

////Enemies turn////

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

echo $enemies . "'s attack roll is " . $enemiesattack . "<br>";
echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";

if ($enemiesattack > $playerdefense)
{
echo $enemies . " hits! <br>";
$enemiesdamage = rand(1,6);
$newplayerhp = $playerhp - $enemiesdamage;
echo "For " . $enemiesdamage . " points of damage. <br>";
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 $enemies . " misses!";
}
echo "<br><br><a href='battle.php'?enemies=$enemies>Battle again!";
?>
Help would be appreciated! :D
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Browser MMO Video#11

Post by Jackolantern »

Halls will have to answer this one for sure, but I think that is fixed as you go on.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Browser MMO Video#11

Post by hallsofvallhalla »

$enemies is being passed back as blank i bet. When you 'refresh' what does the url look like?
Skippy1300
Posts: 12
Joined: Thu Aug 01, 2013 10:55 pm

Re: Browser MMO Video#11

Post by Skippy1300 »

Post Reply

Return to “Older Browser MMO Videos”