Page 1 of 1

Max Levels Issue

Posted: Tue Mar 04, 2014 10:23 pm
by Epiales
Okay, I have it to where the player can purchase so many gunmen per level, and it works fine for the gunmen, but for some reason, the guards are not letting it work. It allows one to go over the max amount of guards one can purchase per level. I'm sure I"m just missing something little in the code, but I just can't find it. Any help would be great.

Code For Working Max Gunmen

Code: Select all

<?php    
    //user buys a unit Gunmen//
    if(isset($_POST['train'])){
        $henchmen = protect($_POST['henchmen']);
        $food_needed = ((30) * $henchmen);
        
            if($henchmen == 0){
            echo '<span id="errormess"><big><font color="red"><b>You must purchase a positive amount!</b></font></span></big>';
        }elseif($henchmen > 5){
            echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
        }elseif($henchmen < 5){    
            echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
        
            }elseif($stats_food < $food_needed){
            echo '<span id="errormess"><big><font color="red"><b>You do not have enough food!</b></font></span></big>';
            
            }else{
            $maxpurchase = $stats_level * 25;
            $inventorylimit = $maxpurchase;
            
            if($unit_gunmen == $inventorylimit){
            echo '<span id="errormess"><big><font color="red"><b>You may only purchase 25 per level!</b></font></span></big>';
            
        }else{
            $unit_gunmen += $henchmen;
                        
$update_gunmen = "UPDATE `unit` SET `henchmen`='".$unit_gunmen."' WHERE `id`='".$_SESSION['userid']."'";
$user_query1 = mysqli_query($db_conx, $update_gunmen);

$stats_food -= $food_needed;            
            
$update_food = "UPDATE `stats` SET `food`='".$stats_food."' WHERE `id`='".$_SESSION['userid']."'";
$user_query = mysqli_query($db_conx, $update_food);

            include("update_stats.php");            
            
            echo '<span id="errormess"><big><font color="red"><b>You have purchased Gunmen!</b></font></span></big>';

            }
        }
    } 
Code For Non-Working Guards:

Code: Select all

<?PHP
 //user buys unit Guards//
    if(isset($_POST['train1'])){
        $guards = protect($_POST['guards']);
        $food_needed = ((30) * $guards);
        
        if($guards == 0){
            echo '<span id="errormess"><big><font color="red"><b>You must purchase a positive amount!</b></font></span></big>';
        }elseif($guards > 5){
            echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
        }elseif($guards < 5){
            echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';    
            
        }elseif($stats_food < $food_needed){
            echo '<span id="errormess"><big><font color="red"><b>You do not have enough food!</b></font></span></big>';
            
        }else{
            $maxpurchase = $stats_level * 25;
            $inventorylimit = $maxpurchase;
            
            if($unit_guards == $inventorylimit){
            echo '<span id="errormess"><big><font color="red"><b>You may only purchase 25 per level!</b></font></span></big>';
        
        }else{
            $unit_guards += $guards; 
                        
$update_guards = "UPDATE `unit` SET `guards`='".$unit_guards."' WHERE `id`='".$_SESSION['userid']."'";
$user_query = mysqli_query($db_conx, $update_guards);
            $stats_food -= $food_needed;            
$update_food = "UPDATE `stats` SET `food`='".$stats_food."' WHERE `id`='".$_SESSION['userid']."'";
$user_query = mysqli_query($db_conx, $update_food);            
                     
            include("update_stats.php");

            echo '<span id="errormess"><big><font color="red"><b>You have purchased Guards!</b></font></span></big>';
            }
        }
    }
?>
Form For Both Gunmen and Guards:

Code: Select all

<center> <form action="units.php" method="post">
<center><h2>Train Units</h2></center>
<table cellspacing="0" border="3" bordercolor="grey" width="99%">
<tr style="background-color:black;" align="center">
<td class = "tooltip" style=" border-right: 1px solid white;">Gunmen<img src="images/infoicon.png" width = "30"><span>Purchasing Gunmen will increase your attack.<br>You should have a gun for each<br>gunmen you own! </span></td>
<td class = "tooltip" style=" border-right: 1px solid white;">Guards<img src="images/infoicon.png" width = "30"><span>Purchasing Guards will increase your defense.<br>You should have a vest for each<br>guard you own! </span></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;"><img src="theme/henchmen.png" width="75" height="75"></td>
<td><img src="theme/guards.png" width="75" height="75"></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;">You Own: <?php echo number_format($unit_gunmen); ?></td>
<td>You Own: <?php echo number_format($unit_guards); ?></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;"><img src="http://bit.ly/14ngtSd" width="20" height="20"><font color="yellow">30</font> <input type="text" name="henchmen" placeholder="5 at a time" maxlength="1" size="7"/></td>
<td><img src="http://bit.ly/14ngtSd" width="20" height="20"><font color="yellow">30</font> <input type="text" name="guards" placeholder="5 at a time" maxlength="1" size="7"/></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;"><input type="submit" name="train" value="Buy Gunmen"/> </td>
<td><input type="submit" name="train1" value="Buy Guards"/> </td>
</tr>
</table></form>

Re: Max Levels Issue

Posted: Sun Mar 09, 2014 8:40 am
by MikuzA
Hello,

Can't see any difference in your codes, so it should work fine on both.
However, you could change this>

Code: Select all

if($unit_guards == $inventorylimit){
to

Code: Select all

if($unit_guards >= $inventorylimit){
I can't remember how the guard amounts are reduced in your game, but if for example one guard dies and you buy 5 more, then it would allow it to go pass that limit, since it never triggers the exact match of '200' == '200'.
Instead of doing '199' == '200' and add +5 more to that, making it 204 at first purchase and then player can 'abuse' it buy buying above the limit., 209, 214 etc.

Or is it actually going like 205, 210 above the limit? If so, I can't really see why this is happening :(

Hope this helps in any way..

Re: Max Levels Issue

Posted: Sun Mar 09, 2014 6:41 pm
by Epiales
MikuzA wrote:Hello,

Can't see any difference in your codes, so it should work fine on both.
However, you could change this>

Code: Select all

if($unit_guards == $inventorylimit){
to

Code: Select all

if($unit_guards >= $inventorylimit){
I can't remember how the guard amounts are reduced in your game, but if for example one guard dies and you buy 5 more, then it would allow it to go pass that limit, since it never triggers the exact match of '200' == '200'.
Instead of doing '199' == '200' and add +5 more to that, making it 204 at first purchase and then player can 'abuse' it buy buying above the limit., 209, 214 etc.

Or is it actually going like 205, 210 above the limit? If so, I can't really see why this is happening :(

Hope this helps in any way..

Exactly... I can't seem to figure out why it's not working either. Why I asked here. Makes no sense. I will change according to u're suggestion and see what happens then. But when you fight in the arena, you lose guards. You have to kill their guards first, before you touch their HP, then when all the guards are dead, you take their HP and win or if you lose u'res first, you lose. Anyway, I'll let you know when I get the time to change to u're suggestion and see how it works. Thanks :)