Browser MMO Video #32
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
-
- Posts: 9
- Joined: Mon Sep 05, 2011 4:05 pm
Re: video 32
Thanks for this. I need to tell you though. Your attack.php doesn't work, well, most of it does work, but some doesn't. When you use an item against a creature, it will roll, but it won't deal any damage. Here is the code, straight from your source...
I tried adding it to where the newcreaturehp is subtracted, but it doesn't work for me.
I tried adding it to where the newcreaturehp is subtracted, but it doesn't work for me.
Code: Select all
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");
}}
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: video 32
seems you are right. Weird. Not sure what happened but here is a temporary fix. I am going to be redoing much of the battle system soon to add some advanced stuff
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'];
$creaturegold = $creatureinfo3['gold'];
$creatureloot = $creatureinfo3['loot'];
$hasloot = $creatureinfo3['isloot'];
?>
</div>
<div id="player">
<?php
///////////////////////players turn////////////////////
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<br>";
$playerpass = 1;
$newcreaturehp = $creaturehp - $sdamage;
$updateplayer="update players set spoints=spoints-'$spoints' where name='$player'";
mysql_query($updateplayer) or die("Could not update player");
$updatecreature="update creatures set hpoints='$newcreaturehp' where name='$creature' limit 1";
mysql_query($updatecreature) or die("Could not update creature");
if ($newcreaturehp < 1)
{
echo "The " . $creature . " has been killed<br>";
$crmaxhp=$creatureinfo3['maxhpoints'];
$updatecreature="update creatures set hpoints='$crmaxhp' where name='$creature' limit 1";
mysql_query($updatecreature) or die("Could not update creature");
////////////////////////
//////////////////////
//////////////////
creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature,$newcreaturehp);
//echo $hasloot;
/////////////////////
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;
}
}}
}
if ($playerpass != 1)
{
$weaponinfo="SELECT * from playerweapons where equip=1 AND pid='$pid'";
$weaponinfo2=mysql_query( $weaponinfo) or die("could not get player weapon!");
$weaponinfo3=mysql_fetch_array( $weaponinfo2);
$playerattack = rand(1,20) + $playerattack + $weaponinfo3['rating'];
//////////////////////////////////////////////////////
$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'] . " " . $weaponinfo3['hittext'] . " and hits!<br>";
$weapdamage = $weaponinfo3['damage'];
$halfdamage = $weaponinfo3['damage'] / 2;
$playerdamage = rand($halfdamage,$weapdamage);
$newcreaturehp = $creaturehp - $playerdamage;
echo "For " . $playerdamage . " points of damage. <br>";
if ($newcreaturehp < 1)
{
echo "The " . $creature . " has been killed";
$crmaxhp=$creatureinfo3['maxhpoints'];
$updatecreature="update creatures set hpoints='$crmaxhp' where name='$creature' limit 1";
mysql_query($updatecreature) or die("Could not update creature");
////////////////////////
//////////////////////
//////////////////
creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature,$newcreaturehp);
echo $hasloot;
/////////////////////
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'] . " " . $weaponinfo3['hittext'] . " and misses!";
}}
?>
</div>
<div id="creature">
<?php
//////////////////////creatures turn //////////////////
echo "<center><u> " . $creature . "'s Attack</u><br>";
///////hit location//////////////////////////////////////
$randlocation = rand(0,100);
if ($randlocation <= 15)
{$location = "arms";}
elseif ($randlocation <= 70)
{$location = "chest";}
elseif ($randlocation <= 90)
{$location = "legs";}
elseif ($randlocation <= 100)
{$location = "head";}
$playerarmor="SELECT * from playerarmor where pid='$pid' AND location='$location' AND equip=1";
$playerarmor2=mysql_query($playerarmor) or die("Could not get player armmor");
$playerarmor3=mysql_fetch_array($playerarmor2);
$noarmor = 0;
if(is_null($playerarmor3['rating']))
{
$playerarmor3['rating'] = 0;
$noarmor = 1;
}
////////////////////////////////////
$creatureattack = rand(1,20) + $creatureattack;
$playerdefense = rand(1,20) + $playerdefense + $playerarmor3['rating'];
echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";
if ($creatureattack > $playerdefense)
{
echo $creature . " hits for a strike to the " . $location . "<br>";
$creaturedamage = rand(1,6);
$newplayerhp = $playerhp - $creaturedamage;
echo "For " . $creaturedamage . " points of damage. <br>";
if ($noarmor == 1)
{
echo "You are not wearing armor on your " . $location . ".<br>";
$extradamage = rand(1,3);
echo "You take an additional " . $extradamage . " points of damage.<br>";
$newplayerhp = $newplayerhp - $extradamage;
}
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 $creature . " misses!";
}
echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
//////////////////////first function
function creaturekilled($creaturegold,$creatureloot,$hasloot,$player,$pid,$creature)
{
$isgold = rand(0,$creaturegold);
$isloot = rand(0,100);
echo "You loot " . $isgold . " gold pieces.<br>";
$updateplayer="update players set gold=gold+'$isgold' where name='$player'";
mysql_query($updateplayer) or die("Could not update player");
if($isloot < $hasloot)
{
echo "You find a " . $creatureloot . " on the " . $creature . ".<br>";
/////////////////pull the items info
$critem="SELECT * from store where name='$creatureloot'";
$critem2=mysql_query($critem) or die("Could not get creature item");
$critem3=mysql_fetch_array($critem2);
/////////////////give it to player
$randid4 = rand(999,99999999);
$itembought = "INSERT into inventory(id, name, stats, statadd, randid,type) VALUES ('$pid','$critem3[name]','$critem3[stats]','$critem3[statadd]','$randid4','$critem3[type]')";
mysql_query($itembought) or die("could not insert item into backpack");
}
else
{
echo " You find no items of value on the creature.<br>";
}
}
?>
</div>
-
- Posts: 9
- Joined: Mon Sep 05, 2011 4:05 pm
Re: video 32
Thanks man. I forgot to re-update the creature using the query. Anyways, works perfectly!
-
- Posts: 165
- Joined: Tue Oct 13, 2009 4:22 pm
Re: video 32
I cant invite players, heres index.php, i click invite player(yes the player is in the db) and it dost invite the player it just gose straight to the index.php page here the code:
index.php
Reply ASAP
index.php
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);
$bypass = 0;
include_once 'statpanel.php';
?>
<div id ="locations">
<?php
$playerhp = $playerinfo3['hpoints'];
if ($playerhp < 1)
{
echo "You are dead!" ;
echo "<br><a href='useitem.php'>Use an Item";
exit;
}
if(isset($_GET['map']))
{
$bypass= 1;
echo "<a href='index.php?mapchange=1&mapname=Crocania'>Crocania</a><br>";
echo "<a href='index.php?mapchange=1&mapname=Fordale Woods'>Fordale Woods</a><br>";
echo "<a href='index.php?mapchange=1&mapname=Mintus Mountains'>Mintus Mountains</a><br>";
echo "<br><br><br><br><a href='index.php'>NeverMind</a><br>";
}
if(isset($_GET['mapchange']))
{
$bypass=1;
$mapname = $_GET['mapname'];
$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'";
mysql_query($updateplayer) or die("Could not update player");
echo "You have traveled to " . $mapname . ".<br>";
echo "<a href='index.php'>To location</a><br>";
}
/////////////////////////////Guild Page/////////////////////////
if((isset($_GET['guild']) && $playerinfo3['guildid'] != 0) || (isset($_GET['guild']) && $playerinfo3['guildid'] != 0))
{
$bypass = 1;
if(isset($_POST['invite']))
{
$user = $_POST['user'];
$name = $_POST['name'];
$guild = $_POST['guild'];
$subject = "Guild Invite for the " . $guild . " guild";
$message = $_POST['message'];
$randid = rand(999,999999);
$messagedate = date('Y-m-d');
$SQL = "INSERT into messages(pid, sender, message, subject, randid, date) VALUES ('$name','$user','$message','$subject','$randid','$messagedate')"; mysql_query($SQL) or die("Could not add to Messages");
echo "<center>Guild Invite Sent<b><b><br><br>";
}
$guildid = $playerinfo3['guildid'];
$guildinfo="SELECT * from guilds where gid='$guildid'";
$guildinfo2=mysql_query($guildinfo) or die("Could not get Guild Stats!");
$guildinfo3=mysql_fetch_array($guildinfo2);
$playerguildinfo="SELECT * from guildmembers where name='$player' AND guildid='$guildid'";
$playerguildinfo2=mysql_query($playerguildinfo) or die("Could not get Guild Stats!!");
$playerguildinfo3=mysql_fetch_array($playerguildinfo2);
$access = $playerguildinfo3['access'];
$accessinfo="SELECT name from guildlevels where access='$access'";
$accessinfo2=mysql_query($accessinfo) or die("Could not get Guild Access Stats!");
$accessinfo3=mysql_fetch_array($accessinfo2);
echo "<b>" . $guildinfo3['name'] . "</b><br>";
echo $guildinfo3['welcome'] . "<br><br>";
echo "Welcome " . $accessinfo3['name'] . " " . $player;
echo "<table border='1'><tr><td><center><b>Invite Player to guild</b><br><form method='POST' action='index.php'>";
echo "Player Name: <input type='text' name='name' size='21'><br>";
echo "Message to player: <input type='text' name='message' size='80'><br>";
echo "<input type='hidden' name='guild' value='1'>";
echo "<input type='hidden' name='invite' value='1'>";
echo "<input type='hidden' name='user' value='$player'>";
echo "<input type='hidden' name='guild' value='$guildinfo3[name]'>";
echo "<input type='submit' value='Invite Player' name='submit'></form></center></td></tr></table>";
echo "<br><br><form method='POST' action='index.php'>";
echo "<input type='submit' value='Go Back' name='submit'></form>";
}
/////////////////////////////QUEST LOG/////////////////////////
if(isset($_GET['quests']))
{
$bypass = 1;
echo "<small>";
print "<center>";
print "<table border='0' width='90%' cellspacing='10'>";
print "<tr><td width='25%' valign='top'>";
print "</td>";
print "<td valign='top' width='85%'>";
$selectbackpack="SELECT * from currentquests where pid='$playerinfo3[name]'";
$selectbackpack2=mysql_query($selectbackpack) or die("could not select backpack");
print "<table border='1' bordercolor='black' bgcolor='#FFFFFF'>";
print "<tr><td> Quest Giver </td><td>Quest Description </td></td><td>Location</td>";
while($selectbackpack3=mysql_fetch_array($selectbackpack2))
{
print "<tr><td><center>$selectbackpack3[name]</td><td>$selectbackpack3[description]</td><td>$selectbackpack3[location]</td></tr>";
}
print "</table>";
print "</td></td></table>";
print "</center>";
echo "</small>";
echo "<center><br><br><form method='post' action='index.php'>";
echo "<input type='submit' value='Back'>";
echo "</form></center>";
}
//////////////////////////////////////////////////////////
if($bypass != 1)
{
echo "<b><big><u>" . $playerinfo3['location'] . "</u></big></b><br>";
echo "<a href='store.php'>Visit Store<br>";
echo "<a href='weaponshop.php'>Visit Weapon Shop</a><br>";
echo "<a href='armorshop.php'>Visti Armor Shop</a><br>";
echo "<a href='inn.php'>Visit Inn</a><br>";
echo "<a href='spelltrainer.php'>Visit Spell Trainer</a><br>";
echo "<a href='startguild.php'>Start Guild</a><br>";
echo "<a href='quests.php'>Visit Quest Hall</a><br>";
echo "<a href='battle.php'>Battle in Arena</a><br>";
echo "<a href='index.php?map=1'>Go to Map</a><br>";
}
?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'></a>";
?>
</div>
Im dumb;)
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: video 32
Code: Select all
if((isset($_GET['guild']) && $playerinfo3['guildid'] != 0) || (isset($_GET['guild']) && $playerinfo3['guildid'] != 0))
Code: Select all
if((isset($_GET['guild']) && $playerinfo3['guildid'] != 0) || (isset($_POST['guild']) && $playerinfo3['guildid'] != 0))
-
- Posts: 165
- Joined: Tue Oct 13, 2009 4:22 pm
Re: video 32
THANKS! I cant see the difference between those 2 but it made a huge difference!Thank you
Im dumb;)
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: video 32
it was get and post.
-
- Posts: 165
- Joined: Tue Oct 13, 2009 4:22 pm