Browser MMO Video #14
-
- Posts: 14
- Joined: Sun Sep 20, 2009 9:00 pm
Re: Video 14
Its not that I dont like it i am just trying to think of a way when multiple people join to keep the action smooth.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Video 14
well i understand its a pain to keep having to add creatures to it.
Re: Video 14
i cant figure out how to reset the creature hp...wow i must be stupid
if you love something, let it go.
if it doesnt return.....hunt it down and kill it.
if it doesnt return.....hunt it down and kill it.
-
- Posts: 175
- Joined: Sun Oct 11, 2009 9:33 am
Re: Video 14
This is how I did it (I can't believe i actualy did something! LOL!)darspire wrote:i cant figure out how to reset the creature hp...wow i must be stupid
First in the creatues table, make a new field and call it whatever, I called mine 'maxhp'.
Here is my attack.php. You will find the code I added in between ************(code)**************** (Code is in 2 areas.)
If your copying and pasting this, you will find the new code at line 56 and lines 117 and 118
It is quite simple once you think about it. I was looking through the code and figured it out, just did some copying+pasting. Also you can change the variables to whatever you like, I just used them for simplicity.
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'];
********************$creaturestarthp = $creatureinfo3['maxhp']***********************
?>
</div>
<div id="player">
<?php
///////////////////////players turn////////////////////
///////////////////////////////////////////////new for video 13/////////////////////////////
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)
{
$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="update creatures set hpoints='$creaturestarthp' where name='$creature' limit 1";
mysql_query($updatecreature) or die("Could not update people");********************************
// $updatecreature="DELETE from creatures where name='$creature' limit 1";
// mysql_query($updatecreature) or die("Could not update creature");
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'] . " misses!<br>";
}}
?>
</div>
<div id="creature">
<?php
//////////////////////creatures turn //////////////////
echo "<center><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'</a>";
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>
Re: Video 14
THANK YOU.
finally. i bow to you
finally. i bow to you
if you love something, let it go.
if it doesnt return.....hunt it down and kill it.
if it doesnt return.....hunt it down and kill it.
-
- Posts: 175
- Joined: Sun Oct 11, 2009 9:33 am
Re: Video 14
No problem at all mate, we are all here to learn and hone our skillsdarspire wrote:THANK YOU.
finally. i bow to you

Re: Video 14
now i just need to figure out how to make it so when exper gets to a certain number, you level up
if you love something, let it go.
if it doesnt return.....hunt it down and kill it.
if it doesnt return.....hunt it down and kill it.
Re: Video 14
Pseudo code:darspire wrote:now i just need to figure out how to make it so when exper gets to a certain number, you level up
Code: Select all
if ($exp >= 1000)
$level = $level + 1
else
//do other stuff
endif
Re: Video 14
do you know what the real code would be?
if you love something, let it go.
if it doesnt return.....hunt it down and kill it.
if it doesnt return.....hunt it down and kill it.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Video 14
here is a solution I gave when last asked about it
http://indie-resource.com/forums/viewto ... l+up#p8015
http://indie-resource.com/forums/viewto ... l+up#p8015