Jump to content

my monster and players Hitpoints keep resetting,


silverglade

Recommended Posts

Hi, I have a battle script that has a monster and player fighting. The hit points keep resetting on both characters. I set my session variables in intro.php, and included a session_start(); on the pages leading up to my main battle page. I set the array names of both $monster stats and $player stats to $_SESSION variables and initialized them on a separate page before the main page. My monster and players hitpoints keep resetting so no one dies. Any help GREATLY appreciated. Thanks. Derek

 

here is the intro page where I initialize the stat session variables.

 

<?php
//include("connect1.php");
session_start();
// include('bouncer_final.php');

//include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man.

$_SESSION['charname']='';
$_SESSION['player']['stats']['playerHP'] = 100;
$_SESSION['player']['stats']['playerMana'] = 100;
$_SESSION['player']['stats']['playerDmgLow'] = 1;
$_SESSION['player']['stats']['playerDmgHigh'] = 10;
$_SESSION['player']['stats']['playerHitRollLow'] = 1;
$_SESSION['player']['stats']['playerHitRollHigh'] = 20;
$_SESSION['player']['stats']['playerDefense'] = 5;
$_SESSION['player']['stats']['Teardrop_Ocean_Protectors'] = 3;

$_SESSION['monsters']['Ocean']['octalisk']['exp']=10;
$_SESSION['monsters']['Ocean']['octalisk']['mana']=100;
$_SESSION['monsters']['Ocean']['octalisk']['hp']=100;


/* End */



?>

 

here is the main battle page where all my battle coding goes on, and I declare the session variables equal to my array names near the top .

 

<?php

session_start();
// include("connect1.php");
//include('bouncer_final.php');
// include('frames/encounters.php');
require_once("shoutbox/dbconnect.php");
//  include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man.
//turned these off while we are developing 

// ini_set('display_errors',1);
//error_reporting(E_ALL|E_STRICT);

//or if you only want to see Warning Messages and not Notice Messages:
//ini_set('display_errors',1);
error_reporting(E_ALL);

//and if you just want all Error Reporting off, simply use this:
//error_reporting(0);

// error_reporting (E_ALL ^ E_NOTICE);

//declare vars 
//$oceanBackground='';//we dont need this because it's bad practice and its already set in the program.
$player='';
$monsters='';
$_SESSION['player'] = $player;// set this right after they log in, run this once, eventually in database.
$_SESSION['monsters']=$monsters;

$currentMonsterLevel='';//get rid of this eventually and put in session variable cuz we use it on other pages.
$currentPlayerLevel='';
$error='';
$playerHp='';//get rid and make session var.
$monsterHp='';
$echoPlayerMana='';
$echoMonster='';
$echoSpell='';
$player='';
$monsters='';
$playerMessage='';
$monsterMessage='';
$currentPLayerLevel =''; 

function encounter($monsterSeeInvis,$monsterAggro, $playerFaction)
{
if($monsterSeeInvis==true && $monsterAggro==true || $playerFaction<5)
{
	return true;//return yes, for attack function
}
else
{
	return false;
}
}





function monsterAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$playerDefense, &$playerHp)
{     
$monsterRoll= rand($hitRollLow, $hitRollHigh);
if($monsterRoll>=$playerDefense)
{
	$monsterDamage= rand($dmgLow,$dmgHigh);

	$monsterMessage = "You have been hit by a ". $currentMonster." for "."<strong>". $monsterDamage."</strong> points of damage!";
	$playerHp= $playerHp- $monsterDamage;
	$monsterMessage.=" your hp is now ".$playerHp;
}
else
{
	$monsterMessage= " the ".$currentMonster." missed you!<br />";
}
return $monsterMessage;

}

function playerAttack($currMonster,$playerHitRollLow,$playerHitRollHigh,$playerDmgLow,$playerDmgHigh,$monsterDefense, &$monsterHp,$playerFaction,$playerMana)
{     
$playerRoll= rand($playerHitRollLow, $playerHitRollHigh);
if($playerRoll>=$monsterDefense)
{   


	$playerDamage= rand($playerDmgLow,$playerDmgHigh);

	$playerMessage = "You have hit a ". $currMonster." for "."<strong>". $playerDamage."</strong> points of damage!";

	$monsterHp= $monsterHp- $playerDamage;
	$playerMessage.=" The ".$currMonster."'s hp is now ".$monsterHp;
	if($monsterHp<=0)
	{
		if($playerFaction<=0)
		{
			$playerMessage="Your faction standing with ".$playerFaction. "could not possibly get any worse.";
		}
		$playerMessage.=" You have killed the ".$currMonster. "Your faction standing with ".$playerFaction." is now ".$playerFaction-1;

	}
}
else
{
	$playerMessage; //WTF i dont know what im doing.
	$playerMessage= " Whoa! You missed the  ".$currMonster; 
}
return $playerMessage;
}
  

//ini_set('display_errors',1);
//error_reporting(E_ALL);


$spells = array
(
"red" => "red",
"green"=>"green",
"blue" =>"blue"
);

//////////////////////////////////////////////////////////////
$player = array
(
 'inventory'=>'',
 'spells'=>'',
 'stats'=> array
 ( 
     'int'=>16,
     'playerHp'=>100,
     'playerMana'=>100,
     'playerDmgLow'=>1,
     'playerDmgHigh'=>10,
     'playerHitRollLow'=>1,
     'playerHitRollHigh'=>20,
     'playerDefense'=>5,
     'Teardrop_Ocean_Protectors'=>3
     
  
 ),
     'armor'=> array
     (
      'shield'=>'gold'
     ),
     'weapons' =>array
     (
     'sword'=>'silver'
     )
     ,
     'faction'=> array
     (
     'Teardrop_Ocean_Protectors'=>3 //zero means the worst faction you can have, 10 being best , 5 being indifferent.
     )

);
///////////////////////////////////////////////////////////////
$monsters = array
(
'Ocean'=>array
(
	'octalisk'=>array
	(
		'name'=>'octalisk',
		'hp'=>100,
		'exp'=>10,
		'mana'=>100,
		'dmgLow'=>1,
		'dmgHigh'=>10,
		'seeInvis'=>true,
		'aggro'=>true,
		'defense'=>5,
	    'faction'=>'Teardrop_Ocean_Protectors',
		'hitRollLow'=>1,
		'hitRollHigh'=>20),


		'shark' ,

		'eel' 

),
'Desert'=>array
(
	'sand_snake'
),
'Forest'=>array
(
	'frog',
	'lizard',
	'spider'
)
);

//*/IF ATTACK BUTTON PRESSED, INCLUDE ENCOUNTERS FILE WHICH HAS THE BATTLE FUNCTION AND RUN IT
/*if(!empty($_POST['attack']))
{
include('frames/encounters.php');
battle();
}*/
$currentMonster='octalisk';

///////////////////////////////////////////////////////////battle////////////////////////////
//function monsterEncounter($echoMonster,$monsterImage)
if(!empty($_POST['attack']))
{
$echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>";

// instead of using globals we make the return of playerAttack == to $playerMessage to be used outside function.			
 $playerMessage = playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'],
$player['stats']['playerDmgLow'],$player['stats']['playerDmgHigh'],$monsters['Ocean']['octalisk']['defense'],$monsters['Ocean']['octalisk']['hp'],$player['faction']['Teardrop_Ocean_Protectors'],$player['stats']['playerMana']);



//insert octalisk stats into monsterattack function.
		      
if(encounter($monsters['Ocean']['octalisk']['seeInvis'],$monsters['Ocean']['octalisk']['aggro'],$player['faction']['Teardrop_Ocean_Protectors']))
    {     
    
    	//BELOWE CODE instead of using globals, we set the output of monsterAttack
    	//to $monsterMessage becasue it can be used outside the function.
    
        $monsterMessage = monsterAttack($currentMonster,$monsters['Ocean']['octalisk']['hitRollLow'],$monsters['Ocean']['octalisk']['hitRollHigh'] ,
         $monsters['Ocean']['octalisk']['dmgLow'],$monsters['Ocean']['octalisk']['dmgHigh'],
         $player['stats']['playerDefense'],$player['stats']['playerHp'],$monsters['Ocean']['octalisk']['hp']);
    
    }
	else 
	{
	echo "do nothing";
	} 
}

//////////////////////////////////////////////////////////////////////////////


//CHANGING BACKGROUND FOR OCEAN GOES HERE, 1 IMAGE FOR EACH LEVEL OF DEEPNESS WHEN further
// BUTTON PRESSED

if(empty($_POST['further']))
{
$oceanBackground='  <img src="sundragon_environments/ocean/ocean1_FRAME.jpg"/>';

}
elseif(!empty($_POST['further']))
{
$oceanBackground=' <img src="sundragon_environments/ocean/ocean1_FRAME2.jpg"/>';
$echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>";
$monsterMessage='You see an Octalisk, it looks very scary';

}

else
{
$oceanBackground='SHIT where the hell am I?';
$echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>";
$monsterMessage='You see an Octalisk, it looks very scary';
}

//////////////////////////////////////////////////////////////////////////////////
if(!empty($_POST['search']))
{

//include('frames/search.php');

//I CANT GET THIS BELOW TO RUN IN A FUNCTION INSIDE THE SEARCH.PHP FILE, WTF IS UP WITH THAT
//and it returns random ALL monsters instead of ocean monsters.
$random = 'Ocean';
$monster = array_rand($monsters[$random]);

	if(is_array($monsters[$random][$monster])) 
	{
	$currentMonster = $monsters[$random][$monster]['name'];
	}

	else
    {

	$currentMonster = $monsters[$random][$monster];
    }


	//instead of echoing out $currentMonster , we set it so we can get random monster images with it output.
	$monsterImage=$currentMonster;


	//make the below into a function, note what changes , those will be your parameters.
	//i dont know how to do it. i tried.

	//function monsterEncounter($echoMonster,$monsterImage)


if($monsterImage=='octalisk') 
{
$echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>";
$monsterMessage='You see an Octalisk, it looks very scary';
}
elseif($monsterImage=='eel')
{
$echoMonster="<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png'/>";
$monsterMessage='You see an electric Eel , look out.';

}

elseif($monsterImage=='shark')
{
$echoMonster="<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>";
$monsterMessage='You see a Hammerhead Shark, it looks powerful.';
}

else $echoMonster="no monster here";

}//end elseif

//////////////////////////////////////////////////////////////////////////
if(!empty($_POST['spell']))
{
$spellColor = array_rand($spells);
if(is_array($spells)) 
{
	$currentSpell= $spellColor;
}
else 
{

return 0;
}


//instead of echoing out $currentMonster , we set it so we can get random monster images with it output.


if($currentSpell=='red') 
{
	$echoSpell=" <img src='sundragon_interface_template/spells/red.gif' align='center'/> ";
	$monsterMessage=' You cast <strong> BLOOD OF BEATHULE </strong>';
	$player['stats']['playerMana']-=5;
	$echoPlayerMana=$player['stats']['playerMana'];
}
elseif ($currentSpell=='green')
{
	$echoSpell=" <img src='sundragon_interface_template/spells/green.gif' align='center'/> ";
	$monsterMessage='You cast <strong> POISONOUS PLAGUE </strong> spell';
	$player['stats']['playerMana']-=5;
	$echoPlayerMana=$player['stats']['playerMana'];
}
elseif($currentSpell=='blue')
{
	$echoSpell=" <img   src='sundragon_interface_template/spells/blue.gif' align='center'/> ";
	$monsterMessage='You cast <strong> HEART OF DARKNESS </strong>';
	$player['stats']['playerMana']-=5;
	$echoPlayerMana=$player['stats']['playerMana'];
}
else
{
echo "nothing";
}
}



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



<title>Realm of the Sun Dragon</title>

<link rel="stylesheet" type="text/css" href="css/gamestyles.css">
<style type="text/css">
body {

margin-top:-32px;
padding:0;

color: gold;
}
table {
color: black;
}
.style8 {color: #000000}
</style>
</head>

<body>



<div id="container">



  
  <div id="monster_message"><?php if(!empty($battleResult)){echo $battleResult;} // if isset battleresult, then echo ?><?php echo $error;?><?php echo "<br />". $playerMessage. "<br />". $monsterMessage."<br />";?></div>


<div id="currentWeapon">
   <img src="sundragon_interface_template/items/swords/sword_shrunk.png" width="190" height="65" /> </div>
   
<div id="iframe_player_top_lft"  > 
  <div id="left_player_stats"><table align="center" width="30" border="0">
    <tr>
      
      <td><strong>HP</strong></td>
      <td><strong><font color="red"><?php echo $playerHp;?></font></strong></td>
    </tr>
    <tr>
     
      <td><strong>MANA</strong></td>
      <td><strong><font color="green"><?php echo $echoPlayerMana;?></font></td>
    </tr>
    <tr>
     
      <td><strong>EXP</strong></td>
      <td><strong><font color="blue">999</font></strong></td>
    </tr>
    <tr>
     
      <td><strong>PLAT</strong></td>
      <td><strong><font color="white">999</font></strong></td>
    </tr>
  </table></div>
  
  	<p> </p>
  	<p> </p>
  	<p> </p>
  	<p align="center"><strong><br />
  	    <span class="style8">Octalisk (Level <?php echo $currentMonsterLevel;?>) </span></strong> 
      <br/>
       <strong><span class="style8">HP</span><font color="red"> <?php echo $monsterHp;?></font></strong> </p>
       
       
      
        
        
  	<div id="spelleffectsleft" > 
            
            <div class="divcenter"> 
              <div align="center">
                <div class="inline">
                <div align="center">spell</div>
                </div>
                
                <div class="inline">
                <div align="center">spell</div>
                </div>
                
                <div class="inline">
                <div align="center">spell</div>
                </div>
            </div> 
            </div> <!--end divcenter-->
    </div><!--end spell effects-->
   

    
    <div id="bottomspellsleft" > 
        <div class="divcenter"> 
            <div class="inline">
            <div align="center">spell</div>
            </div>
            
            <div class="inline">
            <div align="center">spell</div>
            </div>
            
            <div class="inline">
            <div align="center">spell</div>
            </div>
             
        </div> <!--end div center-->

  </div><!--end bottomspells-->
  

  
  </div><!-- end player div-->




<div id="iframe_spell_foreground"><?php echo $echoSpell;?></div>

<div id="iframe_monster_background"> <?php echo $oceanBackground; ?></div>

<div id="iframe_transparent_monster"><?php echo $echoMonster;?></div>

<!--not here-->


<div id="iframe_player_top_right"   > 
  <table width="160" height="64" border="0" align= "center">
    <tr>
      <td width="160"><div align="center">
        <p><strong><br />
          Silverglade (Level: <?php echo $currentPLayerLevel;?>)<br />
        </strong></p>
        </div></td>
    </tr>
  </table>
  
  
  
    <div class="spelleffects" > 
            
      <div class="divcenter"> 
            
                <div class="inline">
                <div align="center">spell</div>
                </div>
                
                <div class="inline">
                <div align="center">spell</div>
                </div>
                
                <div class="inline">
                <div align="center">spell</div>
                </div>
            
      </div> 
    </div>
   

    
    <div class="bottomspells" > 
      <div class="divcenter"> 
            <div class="inline">
            <div align="center">spell</div>
            </div>
            
            <div class="inline">
            <div align="center">spell</div>
            </div>
            
            <div class="inline">
            <div align="center">spell</div>
            </div>
             
      </div> 

  </div>

</div>
  
  
  
  
<div id="iframe_chat_right">
the data from the chat message box will be output to this div</div>
  
  <!--not  here-->


<div id="iframe_player_center_bottom" align="center" >
  <div align="center"> <form action='gamestart.php' method='post'><input type='submit' name='attack' value='Attack'/><input type="submit" name="search" value="search" /><input type="submit" value="cast spell" name="spell" /><input type="submit" value="go further" name="further" /> <input type="submit"value="Go back" name="back"/><input type="submit" name="inventory" value="Inventory"/></form>
<div id="chat">
       
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    <strong>Message:</strong>       
    <textarea name="message"></textarea>
           
    <input type="submit" name="submit" value="Chat">
    <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>">


</form> </div></div></div>



<!--not here-->


<div id="log_off"> <a href="logout.php"><strong>LOG OFF</strong></a> </div>





<!--not here-->








</div>
</body>
</html>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.