tags:

views:

56

answers:

2

Hi,

Could someone help me figure out how to do this.

I have a game where a player can use potions to enhance their abilities.

This is on a timer which works fine. However Im now looking to add to this query when the player uses 2 different type of potions. I can get it to work but not 100% how I wish.

Player uses potion 1 and their stats are boosted by 20% for 20minutes. Player then uses potion 2 and their stats are boosted by 60% for 20minutes.

With my code at the moment

$check = sprintf("SELECT time,strmod FROM `effects` WHERE `userid` = %u", $userid);

$exe = mysql_query($check);

while($bonus = mysql_fetch_array($exe))
{

$last = $bonus['time'];

$strmod=$bonus['strmod']);

It will display the users bonus (base strength in this example is 2,364,195)

Potion 1 boost your base strength to 2837034 (+20%) Potion 2 boost your base strength to 3782712 (+60%)

Is there a solution where I can get the second 60% potion to take into account the bonus received from the 1st potion. So 60% of 2837034 rather than 2364195. Before I consider recoding the whole thing :D

I hope thats clear bit hard to explain.

Thanks

A: 

Probably not the way your doing it, since your not recording the original players HP, you just have the current (after modifiers have been applied) HP.

Mr-sk
+1  A: 

I presume the database table contains the list of potions in effect. Try something which keeps the value over the while loop...

$multiplier = 1;
while($bonus = mysql_fetch_array($exe))
{
    $last = $bonus['time'];
    $strmod=$bonus['strmod']);
    $multiplier += $strmod/100; // convert from percent to decimal
}

$currStrength = $multiplier*$baseStrength;
SorcyCat
Did the job spot on thanks!
anadin