Page 1 of 2

Hospital

Posted: Thu Oct 29, 2009 8:05 pm
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

Re: Hospital

Posted: Thu Oct 29, 2009 8:21 pm
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 ;)

Re: Hospital

Posted: Fri Oct 30, 2009 9:23 am
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?

Re: Hospital

Posted: Fri Oct 30, 2009 11:10 am
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 :)

Re: Hospital

Posted: Fri Oct 30, 2009 1:52 pm
by hallsofvallhalla
yep, just copy the gold statement from the buy.php

Re: Hospital

Posted: Sat Oct 31, 2009 1:26 am
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 ;)

Re: Hospital

Posted: Sat Oct 31, 2009 4:18 am
by hallsofvallhalla
i have addd a inn to the latest tutorial video. Sorry for the delay, uploading soon.

Re: Hospital

Posted: Mon Nov 02, 2009 11:45 am
by herko125
yeah works now guys
thanks :D

Re: Hospital

Posted: Mon Dec 07, 2009 4:39 am
by ZeroComp
very nice Lord it works perfectly!

Re: Hospital

Posted: Wed Dec 09, 2009 2:32 pm
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>
        ';
    }