Jump to content
MakeWebGames

Hospital Health Cap


OutcasT

Recommended Posts

Hi, i just used a current page, duplicated it and adapted it into a hospital page.

Now Everything is working except for 2 things;

- Waiting Time ( people can just buy and buy and buy health )

- Max Health ( If they have 15% health and buy 100 it will become 115%, i dont know how to do it )

Thanks, Im new to the coding game.

Heres The Code (back end of it);

 

<?
$page_url = explode(".", $_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = $page_url[0].".php";

if($_SERVER['REQUEST_URI'] == "/_hospital.php"){
exit();
}

if($_POST['Option'] == 1){ $amount = 25; $price = 5000; $time = "+5 minutes";}
if($_POST['Option'] == 2){ $amount = 50; $price = 10000; $time = "+10 minutes";}
if($_POST['Option'] == 3){ $amount = 75; $price = 15000; $time = "+15 minutes";}
if($_POST['Option'] == 4){ $amount = 100; $price = 20000; $time = "+20 minutes";}

if(isset($_POST['Purchase'])){

if ($button_value == $_POST['userdigit']) {

if(empty($_POST['Option'])){
echo $lang_empty_field;
}else{

if($money < $price){
echo "You don't have that much money.";
}else{

$health_current = "SELECT health FROM login";
$max_health = 100;

if($health_current == $max_health) {
echo "You have 100% health.";
}else{

$result = mysql_query("UPDATE login SET health=health+'".mysql_real_escape_string($amount)."', exp=exp+'5', money=money-'".mysql_real_escape_string($price)."', bullet_time='".strtotime ($time)."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'") 
or die(mysql_error());

$sql = "SELECT money FROM login WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$money = htmlspecialchars($row->money);

if($money < 0){

$result = mysql_query("UPDATE login SET sitestate='1' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'") 
or die(mysql_error());

$sql = "INSERT INTO banned SET id = '', name = '" .mysql_real_escape_string($name). "', banner = '" .mysql_real_escape_string($site_name). "', reason = 'Exploiting bullets.'";
$res = mysql_query($sql);

echo "You have been banned for exploiting.";
}

$health = $health + $amount;
$exp = $exp + 5;
$dissable = true;
echo "You bought ".number_format($amount)." health for $ ".number_format($price).",-.";

if(!empty($ref)){

$result = mysql_query("UPDATE login SET health=health+'25' WHERE name='".mysql_real_escape_string($ref)."'")
or die(mysql_error());

}

}// if not enough money.
}// if empty field.
}// if no in stock.
} else {
echo "The verification code did not match.";
}// else wrong activation code.
}// if purchase.

?>

 

Heres the "Front Of House" (if it is of use);

 

<fieldset style="color: #000000; border: 1px solid #000000; width: 300px; text-align: left; padding: 5px;">
<legend style="color: #999999; font-weight: bold;">Bullet Factory.</legend>
<form method="post">
<table width="300" border="0" cellpadding="0" cellspacing="2" class="table">
 <tr>
   <td colspan="2" align="left" class="sub"><b>Health:</b></td>
   <td width="100" align="left" class="sub"><b>Price:</b></td>
   <td width="75" align="left" class="sub"><b>Time:</b></td>
 </tr>

 <tr>
   <td width="25" class="cell"><input name="Option" type="radio" value="1" id="1" onfocus="if(this.blur)this.blur()"/></td>
   <td width="150" align="left" class="cell"><label for="1">25% Health.</label></td>
   <td width="100" align="left" class="cell"><label for="1">$ 5,000,-</label></td>
   <td width="75" align="left" class="cell"><label for="1">5 Minutes.</label></td>
 </tr>
 <tr>
   <td width="25" class="cell"><input name="Option" type="radio" value="2" id="2" onfocus="if(this.blur)this.blur()"/></td>
   <td width="150" align="left" class="cell"><label for="2">50% Health.</label></td>
   <td width="100" align="left" class="cell"><label for="2">$ 10,000,-</label></td>
   <td width="75" align="left" class="cell"><label for="2">10 Minutes.</label></td>
 </tr>
 <tr>
   <td width="25" class="cell"><input name="Option" type="radio" value="3" id="3" onfocus="if(this.blur)this.blur()"/></td>
   <td width="150" align="left" class="cell"><label for="3">75% Health.</label></td>
   <td width="100" align="left" class="cell"><label for="3">$ 15,000,-</label></td>
   <td width="75" align="left" class="cell"><label for="3">15 Minutes.</label></td>
 </tr>
 <tr>
   <td width="25" class="cell"><input name="Option" type="radio" value="4" id="4" onfocus="if(this.blur)this.blur()"/></td>
   <td width="150" align="left" class="cell"><label for="4">100% Health.</label></td>
   <td width="100" align="left" class="cell"><label for="4">$ 20,000,-</label></td>
   <td width="75" align="left" class="cell"><label for="4">20 Minutes.</label></td>
 </tr>
 <tr>
   <td colspan="4" align="center" class="submit">
     <table width="295" border="0" cellspacing="0">
       <tr>
         <td width="120" align="center"><img src="files/button.php" alt="Verification." width="120" height="30" /></td>
         <td width="100" align="center"><input name="userdigit" type="text" class="entryfield" style='width: 85%; ' size="5" maxlength="5"<?php echo $disabled; ?>/></td>
         <td width="120" align="center"><input name="Purchase" type="submit" class="button" id="Purchase" onfocus="if(this.blur)this.blur()" value="Purchase."/></td>
       </tr>
     </table>
     </td>
   </tr>
</table>
</form>
</fieldset>

 

Thanks To All Who Help!:D

Link to comment
Share on other sites

if($current_health+$bought_health > 100)
{
echo 'You can't buy more than 100% health';
}

 

Change the vars to what you need but yeh that's pretty much it

No, that's not pretty much it. In fact, that produces the wrong condition.

 

if($ir['hp']+$amount > $ir['maxhp'])
{
echo 'You can't buy more than 100% health';
}

 

Key character in there !Angel is the %.

Link to comment
Share on other sites

No, that's not pretty much it. In fact, that produces the wrong condition.

 

if($ir['hp']+$amount > $ir['maxhp'])
{
echo 'You can't buy more than 100% health';
}

 

Key character in there !Angel is the %.

So mine was "pretty much it", as I said you needed to change the variables... Also escape the can't otherwise it will throw an error...

Link to comment
Share on other sites

No, that's not pretty much it. In fact, that produces the wrong condition.

if($ir['hp']+$amount > $ir['maxhp'])
{
echo 'You can't buy more than 100% health';
}

Key character in there !Angel is the %.

Should probably point out this isn't for McCodes and appears to be custom code.

Link to comment
Share on other sites

That works but i want it to add the difference.

If they had 89% health and bought the 25% pack it would only go to 100% not 114%.

Or if anyone can make it so they can input their desired amount and they would have to wait a specific amount of time depending on how much they bought.

So if they had 77% and they could buy 23% and not waste money.

Thanks

Link to comment
Share on other sites

That works but i want it to add the difference.

If they had 89% health and bought the 25% pack it would only go to 100% not 114%.

Or if anyone can make it so they can input their desired amount and they would have to wait a specific amount of time depending on how much they bought.

So if they had 77% and they could buy 23% and not waste money.

Thanks

Change this part:

UPDATE login SET health=health+'".mysql_real_escape_string($amount)  ."',

 

To this:

UPDATE login SET health=LEAST(health+'".mysql_real_escape_string($amount)  ."', MAXHEALTH),

 

With "MAXHEALTH" being whatever the max health is in the database.

Link to comment
Share on other sites

Bump, can anyone help?

 

$change = (string) $_POST['change'];
if(ctype_digit($change)) {
//Do logic
//Update user stats...etc
} else {
//Fill in the form correctly.
}

 

#Assuming this is in your PHP code, and not a (My)SQL interface, or CL.
UPDATE `login` SET `health` = LEAST(`health` + ". $change .", `max_health`) WHERE `id`=". $_SESSION['user_id'];

 

Column names and table names are most likely incorrect. Where `max_health` is the column name that holds their maximum health value. I assume it's set up like this, it may not be.

Edited by sniko
Link to comment
Share on other sites

  • 2 weeks later...

ahh I think the problem would be the fact that your query for health_current is a little off (line 26). for starters you are "querying" health from login but you don't have a where condition set in place i.e. a userid of the current logged in player. now I haven't really looked too much into GL to know what they use like a session or predefined variable so look more into that.

That was your first problem. Second problem is your not atcually querying your database (mysql*_query () for your health_current variable you defined and fetched it. if memory serves me correctly you can just grab the players current health from safe.php.

I think if you look into those two things you should be golden.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...