Page 1 of 1

Need some help here![resolved]

Posted: Mon Aug 15, 2011 1:17 pm
by Andrew
Hey all!, I've got some questions about things in my game that I can't figure out. :)

*The first Question is: How can I make the fightsystem to not change creature when I press refresh buttom?
Attack.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);
 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;
}
$playersm = $playerinfo3['stamina'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];
$playerpass = 0;

$creature = $creatureinfo3['name'];
$creaturesm = $creatureinfo3['stamina'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];

 ?>
 </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";
	$playerpass = 1;
	  $updateplayer="update players set spoints=spoints-'$spoints' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");
	}} 
} 




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);
   $newcreaturesm = $creaturesm - $playerdamage;
  echo "For " . $playerdamage . " points of damage. <br>";
   if ($newcreaturesm < 1)
   {
     echo "The " . $creature . " has been killed";

   $crmaxsm=$creatureinfo3['maxsm'];
       $updatecreature="update creatures set stamina='$crmaxsm' 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 stamina='$newcreaturesm' 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);
   $newplayersm = $playersm - $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>";
  $newplayersm = $newplayersm - $extradamage;
  }
     if ($newplayersm < 1)
   {
     echo $playerinfo3['name'] . " has been killed<br>";
      echo "<a href='gameover.php>Continue'";
      exit;
   }
  $updateplayer="update players set stamina='$newplayersm' 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>
Also Battle.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);

include_once 'statpanel.php';

$pid = $playerinfo3['id'];
$name = $playerinfo3['name'];
$playerlevel = $playerinfo3['level'];
$playerstamina = $playerinfo3['stamina'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

?>
<div id="table">
<?php

if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid' AND id ='$pid'";
$iteminfo2=mysql_query($iteminfo) or die("Could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}
else
{

$iname = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];

if ($type == "healing")
{
   $newstamina = $statadd + $playerstamina;
   if ($newstamina > $playerinfo3['maxsm'])
   {
    $newstamina = $playerinfo3['maxsm'];
   }
    $updateplayer="update players set stamina='$newstamina' where id='$pid'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where id='$pid' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");
   
   $playerstamina = $newstamina;
  
  echo "Used " . $iname . " and recovered " . $statadd . ".<br>";
}

}}


$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
    {
    ////////////////////new for video 20
    if (isset($_GET['pllocation']))
{

    $playerinfo3=$_GET['pllocation'];
    $arenainfo="SELECT * from locations where location='$pllocation' AND type='arena'";
    $arenainfo2=mysql_query($arenainfo) or die("Could not get arena");
    $arenainfo3=mysql_fetch_array($arenainfo2);
 $arenalevel = $arenainfo3['level'];
        $creatureinfo="SELECT * from creatures where level <= '$arenalevel' order by rand() limit 1";
        }else{
        $creatureinfo="SELECT * from creatures order by rand() limit 1";
        }      
        $creatureinfo2=mysql_query($creatureinfo) or die("Could not get a creature!");
        $creatureinfo3=mysql_fetch_array($creatureinfo2);
        $cid = $creatureinfo3['id'];
        $updateplayer="update players set creature='$cid' where name='$name'";
           mysql_query($updateplayer) or die("Could not update player");
    }

    $creature = $creatureinfo3['name'];
    $creature = $creatureinfo3['level'];
	$creaturestamina = $creatureinfo3['stamina'];
    $creatureattack = $creatureinfo3['attack'];
    $creaturedefense = $creatureinfo3['defense'];
	$creaturelocation = $creatureinfo3['location'];



?>
</div>
<div id="player">
<?php
/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Level = " . $playerlevel . "<br><br>";
echo "Stamina = " . $playerstamina . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";
?>
</div>
<div id="creature">
<?php
///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Level " . $creatureinfo3['level'] . "<br><br>";
echo "Stamina  =  " . $creaturestamina . "<br>";
echo "Attack  =  " . $creatureattack . "<br>";
echo "Defense  =  " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php'>Attack</a>";
echo "<br><a href='usemagic.php'>Use Magic</a>";
echo "<br><a href='useitem.php'>Use Item</a>";
echo "<br><a href='index.php'>Exit Arena</a>";


?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>

The second Question is: Can someone actually help me with fight cooldown?

The Third Question is: How is it possible to add weapon and armor stats? I mean that stay on the character until you change to a better one for example.
Let us think that I have 100hp, and when I equip a weapon I've got 110 hp to fight with. etc.

The Fourth Question is: When I press "battle again" in the fight with a creature the system sends me back to the mainpage of battle if you know what I mean, The page that show what level the creature is and what name it got etc. From there I can choose, attack, Use item, Exit arena etc. And when I then press "attack" the system has choosen another creature, it means I haven't killed the old creature yeat.... Hope you know what I mean

I would be very glad it someone could help me with atleast some of these..

Thanks,

Greetings, Andrew

Re: Need some help here!

Posted: Mon Aug 15, 2011 8:13 pm
by Andrew
Anyone having any idea?,

Andrew

Re: Need some help here!

Posted: Wed Aug 17, 2011 9:11 am
by Andrew
No one?... Comon' I know someone know something about these problems.

Andrew

Re: Need some help here!

Posted: Wed Aug 17, 2011 5:28 pm
by Tim
How can I make the fight system to not change creature when I press refresh button?
I think if you keep watching the series, it will show you down the road. I'm not entirely what video since it has been some time since I watched them. Anyways, if you want the user to be able to select what creature to engage in battle with you'll need to make a form. I will show you mine.

Code: Select all

<form action="combat.php" method="post">
<table id="table">
<tr>
<th>Image</th>
<th>Level</th>
<th>Information</th>
<th>Attack</th>
</tr>
<tr>
<td><img src="images/creatures/rabbit.png"></td>
<td>Level 1</td>
<td>A small brown Rabbit.</td>
<td><input type="submit" name="creature" value="Rabbit" /></td>
</tr>
<tr class="alt">
<td><img src="images/creatures/rat.png"></td>
<td>Level 3</td>
<td>An ugly small Rat.</td>
<td><input type="submit" name="creature" value="Rat" /></td>
</tr>
<tr>
<td><img src="images/creatures/beaver.png"></td>
<td>Level 6</td>
<td>A cute little Beaver.</td>
<td><input type="submit" name="creature" value="Beaver" /></td>
</tr>
<tr class="alt">
<td><img src="images/creatures/brownie.png"></td>
<td>Level 8</td>
<td>A very tiny woman.</td>
<td><input type="submit" name="creature" value="Brownie" /></td>
</tr>
<tr>
<td><img src="images/creatures/wood_sprite.png"></td>
<td>Level 20</td>
<td>A tiny fairy-like creature.</td>
<td><input type="submit" name="creature" value="Wood Sprite" /></td>
</tr>
</table> 
</form>
So this gives me a table of a few creatures, the level they are (average of attack/defense level), a short description, and the submit button which is the most important thing. When the player hits the submit button, it will carry that submission to combat.php (I consolidated everything to combat.php instead of having attack.php and battle.php), so it will reload the page but will stop and say "hey we have a post variable!" when it gets to this point and will execute all the fighting, rounds, loot, etc.

Code: Select all

if (isset($_POST['creature']))
{
	$creature_name = $_POST['creature'];
	
	$creature_info_1 = "SELECT * from creatures where name = '$creature_name'";
	$creature_info_2 = mysql_query($creature_info_1) or die("System: Unable to retrieve creature information.");
	$creature_info_3 = mysql_fetch_array($creature_info_2);
Can someone actually help me with fight cooldown?
I have honestly been wanting this too lately and I'm almost positive it would have to be done with a Javascript timer. I'm not sure if you've ever played The Lost Runes (free PBBG) but it uses a cooldown of 5 seconds per action so a user can't click the mouse button a hundred times a minute. I really need to start looking into Jquery, reading tutorials, etc. I would suggest you might do the same.

How is it possible to add weapon and armor stats?
I am working on a new way of doing this for my game. Once I get it working I will show you.

When I press "battle again" in the fight with a creature the system sends me back to the mainpage of battle
Yeah I am probably not the best guy to be answering these questions since I have not watched Halls' videos in so long. Sorry man! All I can say is okay with it and alter it to your own way. Halls gave everyone a great foundation but it's gonna be up to you to make it unique. I have changed every single system since I started my game with the browser based tutorial series, I would suggest trying to do the same. It's a great learning experience.

Re: Need some help here!

Posted: Wed Aug 17, 2011 8:05 pm
by Andrew
Thanks man, I'm very glad for this answer, I'll try your tip and see what I can do :)
Have a good day!

Andrew

Re: Need some help here!

Posted: Wed Aug 17, 2011 11:38 pm
by 62896dude
A simple andwer for the refresh problem, have the creature id stored in a player field called CID (or whatever you wanna name it). Then, change your creature query to select * from creatures where ID = '$cid'; when a creature is already selected