Increase per level [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Increase per level [Resolved]

Post by Epiales »

It's me :) YAY :P

Okay, my brain is twitterpated as usual today. I've been messing around trying to make it where one can only purchase so many items per level. Example:

level 1 can purchase up to 100
level 2 can purchase up to 200
level 3 can purchase up to 300

Now I could go in there and write a whole bunch of If 1 > than blah blah, but I'd have to write that for each level that exists :lol: I'm not that enthusiastic about that :D Anyway, I can't think of how to write the equation. Any Eye Dee Urs? Thanks!
Last edited by Epiales on Tue Sep 24, 2013 8:29 pm, edited 3 times in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Increase per level

Post by Xaos »

$purchasemax = $player_level * 100;
$inventorylimit = $purchasemax;
if($inventoryamount == $inventorylimit){
purchase can't go through
}
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Increase per level

Post by Xaos »

Although, I don't know why a Level 21 would need 2100 items in their inventory, and so forth :D
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Increase per level

Post by Epiales »

Yeah, I'm always changing things around as I play it and see how fast/slow it goes :D

Anyway, I tried the equation and it seems to skip it for whatever reason:

Code: Select all

            $maxpurchase = $stats['level'] * 100;
            $inventorylimit = $maxpurchase;
            
            if($unit['henchmen'] == $inventorylimit){
            echo "bla bla bla";        
        }else{
Nothing happens. You can just continue to purchase however many you wish.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Increase per level

Post by Xaos »

Epiales wrote:Yeah, I'm always changing things around as I play it and see how fast/slow it goes :D

Anyway, I tried the equation and it seems to skip it for whatever reason:

Code: Select all

            $maxpurchase = $stats['level'] * 100;
            $inventorylimit = $maxpurchase;
            
            if($unit['henchmen'] == $inventorylimit){
            echo "bla bla bla";        
        }else{ 
Nothing happens. You can just continue to purchase however many you wish.
Make sure you're matching how many items they have in their inventory compare to the inventorylimit
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Increase per level

Post by Epiales »

Xaos wrote:
Epiales wrote:Yeah, I'm always changing things around as I play it and see how fast/slow it goes :D

Anyway, I tried the equation and it seems to skip it for whatever reason:

Code: Select all

            $maxpurchase = $stats['level'] * 100;
            $inventorylimit = $maxpurchase;
            
            if($unit['henchmen'] == $inventorylimit){
            echo "bla bla bla";        
        }else{
Nothing happens. You can just continue to purchase however many you wish.
Make sure you're matching how many items they have in their inventory compare to the inventorylimit
I thought that the $unit['henchmen'] was doing that? It's checking to see how many henchmen they have, and if that amount exceeds the inventory limit, then it won't let them purchase anymore? Since that is the table that holds the amount of henchmen they have?
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Increase per level

Post by Xaos »

Ohhhhh, didn't comprehend the game, sorry. Do >= instead, and see if that works. Also, make sure you don't have code that sells the item elsewhere, basically if the inventorylimit has been reached, no purchase code should be accessed (so it should be in the else)
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Increase per level

Post by Epiales »

Xaos wrote:Ohhhhh, didn't comprehend the game, sorry. Do >= instead, and seei f that works.
It went through with the purchase, but error this time:

Code: Select all

Notice: Undefined variable: inventorylimit in C:\xampp\htdocs\flash\units.php on line 116
I thought it was defined by the previous statement grrr lol
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Increase per level

Post by Epiales »

Code: Select all

}else{
            $maxpurchase = $stats['level'] * 100;
            $inventorylimit = $maxpurchase;
            
            if($unit['henchmen'] <= $inventorylimit){
            echo "bla bla bla";    
            
            
            
            
/////After all else fails, you can make a purchase YAY/////            
        }else{ 
Okay, code I have now...but still goes through purchase no errors
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Increase per level

Post by Epiales »

Okay, it must have to do with my elses and ifs...I usually find out that is a problem. Here is what I have before and after:

Code: Select all

 //user buys a unit Gunmen//
    if(isset($_POST['train'])){
        $henchmen = protect($_POST['henchmen']);
        $food_needed = (($unit['henchmen']) * $henchmen);
        
        
////Can't leave it empty or zero dufus/////        
        if($henchmen == 0){
            echo '<span id="errormess"><big><font color="red"><b>You must purchase a positive amount!</b></font></span></big>';
        
        

////Gotta have the food baby, gotta have the food/////    
        }elseif($stats['food'] < $food_needed){
            echo '<span id="errormess"><big><font color="red"><b>You do not have enough food!</b></font></span></big>';
            
            
/////If they have hit their limit for their level, then no buy guns, buh bye bye/////            
        }else{
            $maxpurchase = $stats['level'] * 100;
            $inventorylimit = $maxpurchase;
            
            if($unit['henchmen'] <= $inventorylimit){
            echo "bla bla bla";    
            
        
/////After all else fails, you can make a purchase YAY/////            
        }else{
            $unit['henchmen'] += $henchmen;            
            $update_units = mysql_query("UPDATE `unit` SET `henchmen`='".$unit['henchmen']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
            $stats['food'] -= $food_needed;
            $update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
            include("update_stats.php");

            echo '<span id="errormess"><big><font color="red"><b>You have purchased Gunmen!</b></font></span></big>';
That's just mad though. I move it to the top, or wherever and it just bypasses that equation completely... I even put exit; there and it bypasses it. grrrr
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”