Hospital

Location of the Videos
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Hospital

Post by herko125 »

okay so i decided to make an hospital
but then i got to a point where i didn't know how to continue

i cant get the health to recover to maxhp by clicking on a button
this is the code...any1 can help

Code: Select all

<title>Hospital</title
><link href="style.css" rel="stylesheet" type="text/css">
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>

<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>

<?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';
 ?>
 
<div id="bank">
<table width="100%" border="1" cellspacing="0" cellpadding="0"">
      <tr>
        <td width="79%" height="48">Health</td>
             <td width="21%"><center>
             <input type="submit" name="heal_hp" value="Recover"></center>
        </td>
      </tr>
      <tr>        
        <td height="48">Spell Points</td>    
           <td><center>
             <input type="submit" name="heal_sp" value="Recover"></center>
    </form>
    </fieldset>
        </td>      
    </table>       
    </div>
    
    <?php
	$playerhealth = $playerinfo3['maxhp'];
	$playerspell = $playerinfo3['maxspoints'];	
	$playerhp = $playerinfo3['hpoints'];
	$playersp = $playerinfo3['spoints'];
	
	?>
            <?php

	if(isset($_POST['heal_hp']))
	{  
		  $newgold = ($playerinfo3['gold'] - 50 );
		  $healedplayer = "update players set  hpoints='$playerhealth', gold='$newgold' where name='$player'";
		  mysql_query($healedplayer) or die("could not update health");   
	   }
	   else
	   echo"U have full health!";
	}
	?>
:D
User avatar
Lord Strife
Posts: 104
Joined: Wed Oct 28, 2009 3:10 pm

Re: Hospital

Post by Lord Strife »

ok here it what i would do for that

Code: Select all

if(isset($_POST['heal_hp'])){
$newgold = $playerinfo3['gold'] - 50;
$heal = mysql_query("Update players set hpoints = '".$playerinfo3['maxhp']."' , gold = '".$newgold."' where name = '".$playerinfo3['name']."'")or die(mysql_error());
echo "You have been healed !";
}
else{
echo '
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="submit" name="heal_hp" value="Heal">
</form>
';
}
that might work ;)
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Hospital

Post by herko125 »

yeah works great !
Thanks for the help ^^

it would be good if we would have a Thank You button (:

*edit*

is there a way to check if the player has enough gold and if hes got full health?
alexrules01
Posts: 175
Joined: Sun Oct 11, 2009 9:33 am

Re: Hospital

Post by alexrules01 »

probably just a couple of IF statements

IF playerhealth < Max HP
THEN Heal
OTHERWISE PRINT "You already have full health"

IF playergold < 50
THEN PRINT "Not enough Gold
OTHERWISE Continue

Something like that :)
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Hospital

Post by hallsofvallhalla »

yep, just copy the gold statement from the buy.php
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: Hospital

Post by Sakar »

And before you do that actual heal remember to check if the healing amount will go over their MaxHP, and if so just set their HP to their MaxHP ;)
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Hospital

Post by hallsofvallhalla »

i have addd a inn to the latest tutorial video. Sorry for the delay, uploading soon.
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Hospital

Post by herko125 »

yeah works now guys
thanks :D
ZeroComp
Posts: 648
Joined: Thu Oct 29, 2009 8:48 pm

Re: Hospital

Post by ZeroComp »

very nice Lord it works perfectly!
Coding-PHP, Javascript, C++, HTML, mySQL
Modeling/Art-Blender, GIMP
Games-Unity, Game Maker 8
User avatar
Lord Strife
Posts: 104
Joined: Wed Oct 28, 2009 3:10 pm

Re: Hospital

Post by Lord Strife »

Code: Select all

    if(isset($_POST['heal_hp']) AND !empty($_POST['hp_heal'])){
        if(($_POST['hp_heal'] + $playerinfo3['hpoints']) > $playerinfo3['maxhp']){
            $totalhealed = $playerinfo3['maxhp'];
        }
        else{
            $totalhealed = $_POST['hp_heal'];
        }
    $healedcost = 0; // <-- set this to the price per HP healed
    $totalcost = $totalhealed * $healedcost
        if($totalcost > $playerinfo3['gold']){
            echo "You do not have the required gold !";
        }
        else{
            $newgold = $playerinfo3['gold'] - $totalcost;
            $heal = mysql_query("Update players set hpoints = '".$totalhealed."' , gold = '".$newgold."' where name = '".$playerinfo3['name']."'")or die(mysql_error());
            echo "You have been healed !";
        }
    }
    else{
        echo '
        <form action="'.$_SERVER['PHP_SELF'].'" method="POST">
        <input type="text" size="4" name="hp_heal"> <input type="submit" name="heal_hp" value="Heal">
        </form>
        ';
    }

Post Reply

Return to “Older Browser MMO Videos”