2

Well, I made an achievement system for my game. I have an achievement for banking a certain amount. Well, when their's the certain amount banked you will have the achievement posted on your users wall. But when you withdraw cash the achievement will go away. Here's the coding below. So how could I fix it to where the achievement will stay even after the cash is gone from the users bank account?

<?php 
if ( $userp['bank_account'] >= 100000 )
{
    echo 
    '<img src="achievements/Diamond-Bank.png"  hspace="5" width="65" height="65" title="Diamond Banker: Made a deposit of $100,000 or more!"">';
} 
elseif ( $userp['bank_account'] >= 50000  )
{
    echo 
    '<img src="achievements/Gold-Bank.png"  hspace="5" width="65" height="65" title="Golden Banker: Made a deposit of $50,000 of more."">';
}
elseif ( $userp['bank_account'] >= 1000 )
{
    echo 
    '<img src="achievements/Silver-Bank.png"  hspace="5" width="65" height="65" title="Silver Banker: Made a deposit of $1,000 or more."">';
}
elseif ( $userp['bank_account'] >= 1 )
{
    echo 
    '<img src="achievements/Bronze-Bank.png"  hspace="5" width="65" height="65" title="Bronze Banker: Opened a bank account!"">';
}
?>          

2 Answers2

0

Well, there a several possibilities to fix this. You could store all achievements of a user in a database and insert / select them. This way, nothing is lost, even if the balance is dropping.

You could also add up to the "total" bank account, that is not decremented if the user withdraws cash. This way, you could use $userp['bank_account_total'] for "achievement detection".

David Müller
  • 5,291
  • 2
  • 29
  • 33
  • So make another row in the table that will add everytime you deposit into the bank and whatever the total number is, will be used to detect the amount you have deposited. Then it would give the achievement. – Charles Moore Nov 25 '12 at 10:58
0

I would do it by adding 1 more column to the mysql table - achievement with DEFAULT = 0. Then add the achievement badge using your criteria -

<?php 
if ( $userp['bank_account'] >= 100000 )
{
   "UPDATE table SET `achievement` = 4"
} 
elseif ( $userp['bank_account'] >= 50000  )
{
   "UPDATE table SET `achievement` = 3";
}
elseif ( $userp['bank_account'] >= 1000 )
{
   "UPDATE table SET `achievement` = 2";
}
elseif ( $userp['bank_account'] >= 1 )
{
   "UPDATE table SET `achievement` = 1";
}
?>      

And then to view the achievement badge -

<?php 
if ( $userp['achievement'] = 4 )
{
   echo 
   '<img src="achievements/Diamond-Bank.png"  hspace="5" width="65" height="65" title="Diamond Banker: Made a deposit of $100,000 or more!"">';
} 
elseif ( $userp['achievement'] = 3  )
{
   echo 
   '<img src="achievements/Gold-Bank.png"  hspace="5" width="65" height="65" title="Golden Banker: Made a deposit of $50,000 of more."">';
}
elseif ( $userp['achievement'] = 2 )
{
   echo 
   '<img src="achievements/Silver-Bank.png"  hspace="5" width="65" height="65" title="Silver Banker: Made a deposit of $1,000 or more."">';
}
elseif ( $userp['achievement'] = 1 )
{
   echo 
   '<img src="achievements/Bronze-Bank.png"  hspace="5" width="65" height="65" title="Bronze Banker: Opened a bank account!"">';
}
?>      
Sean
  • 12,443
  • 3
  • 29
  • 47