Page 1 of 1
When Purchasing Things, Cost Increases
Posted: Tue Aug 27, 2013 3:22 am
by Epiales
Okay, on to my next adventure

YAY me! lol
I have an idea on how to do this, but I don't know how I would do it for purchasing 10 at a time.
Let's say you purchase 10 weapons... I want the cost of those weapons to increase by a certain percentage for each 10 that are purchased. If I have to I can just make it max 10 at a time, but would rather have them purchase any amount up to 1000 at a time, but also have the increases in the total amount. But to start with, I would like a simple solution to just purchasing 10 at a time and then the cost of the weapon to increase by a certain percentage for each 10 purchased.
Any idea where to start on that?
Re: When Purchasing Things, Cost Increases
Posted: Tue Aug 27, 2013 3:33 am
by Jackolantern
So you want the cost to increase for every 10 sold, and then stay increased ongoing?
But here is the basic mechanic for figuring out a cost increase for every 10 items sold when they can buy an infinite amount:
Code: Select all
$numberSold;
$cost;
//amount of increase per groups sold as a float (where 0.3 would be 30% increase, 0.05 would be 5%, etc.)
$increase = 0.08; //8% price increase for each 10 items
//determine how many groups of 10 were sold
$groupsSold = $numberSold / 10;
//round to lowest integer
$groupsSold = floor($groupsSold);
//now increase the price
for ($x = 0; $x < $groupsSold; $x++) {
$cost += $cost * $increase;
}
//cost has now increased cumulatively for each group of 10 bought
Re: When Purchasing Things, Cost Increases
Posted: Tue Aug 27, 2013 10:26 am
by Callan S.
There's probably a proper math way of doing it, but I was going to suggest a for loop as well.
Off topic: I Find those math equations that seem to do the actions of a for loop but are just a singular equation to be pretty freaky.
Re: When Purchasing Things, Cost Increases
Posted: Tue Aug 27, 2013 10:36 am
by Epiales
Yeah, I hate trying to figure the equations out. I'm pretty good in math, but making the equation I am not.
Okay, what's wrong with this?
Code: Select all
$update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food'] - .$cost."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
Error I get: Parse error: syntax error, unexpected '.' in C:\xampp\htdocs\flash\units.php on line 233
Oh, I left out a huge part of information LOL....
The cost and everything is NOT in the database, but the script. So I don't think I can even do this then, unless I rewrite the entire thing.

Re: When Purchasing Things, Cost Increases
Posted: Tue Aug 27, 2013 11:45 am
by MikuzA
Epiales wrote:Yeah, I hate trying to figure the equations out. I'm pretty good in math, but making the equation I am not.
Okay, what's wrong with this?
Code: Select all
$update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food'] - .$cost."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
Error I get: Parse error: syntax error, unexpected '.' in C:\xampp\htdocs\flash\units.php on line 233
Oh, I left out a huge part of information LOL....
The cost and everything is NOT in the database, but the script. So I don't think I can even do this then, unless I rewrite the entire thing.

Hello,
you have an unexpected '.'
Code: Select all
SET `food`='".$stats['food'] - .$cost."'
should be
Code: Select all
SET `food`='".$stats['food'] - $cost."'
And what comes for the equations, it's just making the step-by-step logicality of a mathematical happening.
I don't think you are not good with equations, it's just that you are not yet fully familiar on how to get your thoughts written down in PHP, am I right?
The cost do not have to be in database, as long as it is defined before the new pricing loop done by Mr. Jacko.
But the quantities sold needs to be stored somewhere, unless you just do a one time purchase increaser.. example:
"I want to buy 1000 AXES for my underground dwarven army, booyaah!"
"One axe costs 10 gold coins, and every ten axes increases the axe cost amount with 10%, so that makes it.. *massive loopings* muchos Dollars!"
And only the gold reducing is updated to db.
Re: When Purchasing Things, Cost Increases
Posted: Wed Aug 28, 2013 12:47 am
by Callan S.
Code: Select all
$update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food'] - .$cost."'
WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
I'd also do that '$stats['food'] - $cost' stuff outside the update string.
Trying to fit it all into the one line will just lower your Call of Cthulhu sanity stat by a few points, when you look at it a month from now!