Browser MMO Video #4

Location of the Videos
Post Reply
mrmajic
Posts: 117
Joined: Sat Jun 27, 2009 9:37 am

Re: Video #4

Post by mrmajic »

you just run the script from your webserver / wamp server .. or just the same way you run any of ya pages..
Mr Majic...

Current Project: http://www.deltarealm.net
feedback welcome.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #4

Post by hallsofvallhalla »

yeah just run create_creatures instead of making it an include.

OR

in your attack.php comment out delete creature when hp = 0 or instead of delete, update it to maxhp and leave the exho thats says creature killed. Many way of doing this.
Ruule
Posts: 2
Joined: Sat Aug 29, 2009 8:10 pm

Re: Video #4

Post by Ruule »

Notice: Undefined index: defense in C:\Program Files\wamp\www\tutorial\battle.php on line 13

Notice: Undefined index: defense in C:\Program Files\wamp\www\tutorial\battle.php on line 33
player1
Hit points = 14
Attack = 5
Defense =


goblin
Hit points = 5
Attack = 3
Defense =


Attack!


I get this when I go to localhost/tutorial/battle.php
does anyone know what i should change in the lines 13 and 33

this is the php:

Code: Select all

<?php
include 'connect.php';




$playerinfo="SELECT * from players where name='player1'";
$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!";

?>
btw im a newbie.
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: Video #4

Post by Sakar »

You did setup the fields defense for the players table and creatures table, right? If not then that is the problem. If you do have it in make sure it is spelled exactly like it is in the script as PHP is case sensitive.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #4

Post by hallsofvallhalla »

yep, sounds like a mysql field issue, check case!
User avatar
Hutch
Posts: 95
Joined: Wed Aug 12, 2009 11:12 pm

Re: Video #4

Post by Hutch »

Been playing around and I came up with and put in my attack.php

Code: Select all

mysql_query("UPDATE creatures SET hpoints = '10' WHERE name = 'orc'");
 
mysql_query("UPDATE creatures SET hpoints = '7' WHERE name = 'demon'");
         
mysql_query("UPDATE creatures SET hpoints = '5' WHERE name = 'wrench'");
This was based on earlier posts.

Am I ok with this? could I make it better?

------------------------------------------------------------------------------------------------------------------

I have also been playing with the level up. I had something kind of working so I registered another player and it didn't work correct. Now I don't remember the origianl code that I had for it to work.

Here is something close to what I had that was working for the one player in my DB.

Code: Select all

mysql_query("UPDATE players SET level = level + 1 WHERE exper > 100");
What am I missing?

I am a noob at this and try to figure out my changes. I am just having trouble with this one.
User avatar
Hutch
Posts: 95
Joined: Wed Aug 12, 2009 11:12 pm

Re: Video #4

Post by Hutch »

Ok, I wasn't thinking to much when I was trying to do a level up yesterday.

This is what I have now. Any tips?

Code: Select all

if ($playerinfo3['exper'] > 100)

        $updateplayer = "update players SET level='1' where name='$player'";
        mysql_query($updateplayer ) or die("Could not update player");
        
        if ($playerinfo3['exper'] > 200)

        $updateplayer = "update players SET level='2' where name='$player'";
        mysql_query($updateplayer ) or die("Could not update player");
        
        if ($playerinfo3['exper'] > 300)

        $updateplayer = "update players SET level='3' where name='$player'";
        mysql_query($updateplayer ) or die("Could not update player");

        if ($playerinfo3['exper'] > 400)

        $updateplayer = "update players SET level='4' where name='$player'";
        mysql_query($updateplayer ) or die("Could not update player");
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video #4

Post by hallsofvallhalla »

here is what I use and it works great

put this in a file called islevelup.php then in all your pages put include_once 'islevelup.php';

Code: Select all

 $expneeded = ($playerinfo3[level] * 100) * $playerinfo3[level];
  if ($playerinfo3[expe] >= $expneeded)
 {	echo "<br><br><a href='../levelup.php'><img src='../images/levelup.png' width='150' height='50' border='0'/></a>";}
this takes your level * 100 * level and makes that your exp goal. This way the higher your level is the more the exp gap grows.

Example

level 1
1 * 100 * 1 = 100, you need 100 exp
level 2
2 * 100 * 2 = 400, you need 400 exp

level 5
5 * 100 * 5 = 2500 and so on

1 line of code to figure the exp needed

then if current exp is greater than exp needed then place a button that will link you to a level up page, where you level up and bring the characters level up one, when its done the islevelup.php will figure the next exp amount needed.


its brilliant really :)


oh yeah by the way in your islevelup.php make sure you put a if statement saying if exp is > expneeded then level up, otherwise people will cheat and fast link the level up page :)
User avatar
Hutch
Posts: 95
Joined: Wed Aug 12, 2009 11:12 pm

Re: Video #4

Post by Hutch »

Thank you

I knew there had to be an easier way then putting stuff for evry level.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Video #4

Post by SpiritWebb »

Wow, I wasn't even ready for this part yet. This helps alot...thanks there Halls...lol!! :p
Image

Image
Post Reply

Return to “Older Browser MMO Videos”