Page 1 of 1
Increase per level [Resolved]
Posted: Sat Sep 14, 2013 9:42 pm
by Epiales
It's me

YAY
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

I'm not that enthusiastic about that

Anyway, I can't think of how to write the equation. Any Eye Dee Urs? Thanks!
Re: Increase per level
Posted: Sat Sep 14, 2013 9:52 pm
by Xaos
$purchasemax = $player_level * 100;
$inventorylimit = $purchasemax;
if($inventoryamount == $inventorylimit){
purchase can't go through
}
Re: Increase per level
Posted: Sat Sep 14, 2013 10:00 pm
by Xaos
Although, I don't know why a Level 21 would need 2100 items in their inventory, and so forth

Re: Increase per level
Posted: Sat Sep 14, 2013 10:14 pm
by Epiales
Yeah, I'm always changing things around as I play it and see how fast/slow it goes
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.
Re: Increase per level
Posted: Sat Sep 14, 2013 10:20 pm
by Xaos
Epiales wrote:Yeah, I'm always changing things around as I play it and see how fast/slow it goes
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
Re: Increase per level
Posted: Sat Sep 14, 2013 10:22 pm
by Epiales
Xaos wrote:Epiales wrote:Yeah, I'm always changing things around as I play it and see how fast/slow it goes
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?
Re: Increase per level
Posted: Sat Sep 14, 2013 10:23 pm
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)
Re: Increase per level
Posted: Sat Sep 14, 2013 10:25 pm
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
Re: Increase per level
Posted: Sat Sep 14, 2013 10:27 pm
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
Re: Increase per level
Posted: Sat Sep 14, 2013 10:35 pm
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