Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have errors in your coding or want something specific added to your game? Check out our paid support here.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: [Mccodes Version 2] Bank  (Read 215 times)

MonoD

  • Basic Member
  • *
  • Reputation Power: 23
  • MonoD has no influence.
  • Offline Offline
  • Posts: 34
    • MSN Messenger - Contact@Monodistrict.com
    • View Profile
    • WWW
    • Email
[Mccodes Version 2] Bank
« on: July 07, 2011, 03:39:05 PM »
Hi Cronwerks, Here is a Simple Bank.

All i have done is took the standard bank and improved the code and style.

Notice: The reason the H3/H4 Are different is because my CSS is custom, If you wish to know how to get your H3/H4's like that just let me know!

Screenshots:





bank.php:
Code: [Select]
<?php
include_once(DIRNAME(__FILE__) . '/globals.php');
echo 
"<h3>Town Bank</h3><h4>Welcome to the Town Bank, Here you can deposit your cash to keep it safe from other players!</h4><br />";
if (
$ir['bankmoney'] > -1) {
        switch (
$_GET['page']) {
                case 
"deposit"deposit(); break;
                case 
"withdraw"withdraw(); break;
                default: 
index(); break;
        }
} else {
        if (isset(
$_GET['buy'])) {
                if (
$ir['money'] > 999) {
                        echo 
"<b>Success:</b> You have paid <b>$1,000</b> for a bank account.<br />
                              Would you like to go to your bank account?<br /><br />
                              <a href='bank.php'>Yes</a> | <a href='town.php'>No</a>"
;
                        
$db->query("UPDATE users SET money=money-1000,bankmoney=0 WHERE userid=$userid");
                } else {
                        echo 
"<b>Error:</b> You do not have enough cash to open an account!<br /><br /> &gt <a href='town.php'>Back</a>";
                }
        } else {
                echo 
"<b>Bank Manager:</b> Hi <i>" $ir['username'] . "</i>, Welcome to the Town Bank.<br />
                      Here you can deposit your cash so it doesn't get stolen by other players.<br />
                      To open a bank account it will cost <b>$1,000</b>, Would you like to open an account?<br /><br />
                      <br /><a href='bank.php?buy'>Yes please</a> | <a href='town.php'>No thanks</a>"
;
        }
}
function 
index()
{
        global 
$db$ir$c$userid$h;
        echo 
"You currently have <b>" money_formatter($ir['bankmoney']) . "</b> in your bank account.<br /><br />
              <table width='80%' class='table'><tr><th width='50%'>Deposit Cash</th><th>Withdraw Cash</th></tr>
              <tr><td style='text-align:center;'> <br />
              <form action='bank.php?page=deposit' method='post'>
              <input type='text' name='deposit' value='{$ir['money']}' /><br />
              <input type='submit' value='Deposit' /></form></td>
              
              <td style='text-align:center;'> <br /><form action='bank.php?page=withdraw' method='post'>
              <input type='text' name='withdraw' value='{$ir['bankmoney']}' /><br />
              <input type='submit' value='Withdraw' /></form></td> </tr> </table>"
;
}
function 
deposit()
{
        global 
$db$ir$c$userid$h;
        
$_POST['deposit'] = abs((int) $_POST['deposit']);
        if (
$_POST['deposit'] > $ir['money']) {
                echo 
"<b>Error:</b> You do not have enough cash to deposit that amount!<br /><br /> &gt <a href='bank.php'>Back</a>";
        } else {
                
$fee ceil($_POST['deposit'] * 15 100);
                if (
$fee 0) {
                        
$fee 0;
                }
                
$gain $_POST['deposit'] - $fee;
                
$ir['bankmoney'] += $gain;
                
$db->query("UPDATE users SET bankmoney=bankmoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
                echo 
"You hand over <b>" money_formatter($_POST['deposit']) . "</b> to be added into your bank account.<br /><br />
                      <b>Bank Manager:</b> Okay <i>" 
$ir['username'] . "</i>, The cash has been added to your bank account.<br /><br />
                      You now have <b>" 
money_formatter($ir['bankmoney']) . "</b> in your bank account.<br /><br />
                      &gt <a href='bank.php'>Back</a>"
;
        }
}
function 
withdraw()
{
        global 
$db$ir$c$userid$h;
        
$_POST['withdraw'] = abs((int) $_POST['withdraw']);
        if (
$_POST['withdraw'] > $ir['bankmoney']) {
                echo 
"<b>Error:</b> You do not have enough banked cash to withdraw that amount!<br /><br /> &gt <a href='bank.php'>Back</a>";
        } else {
                
$gain $_POST['withdraw'];
                
$ir['bankmoney'] -= $gain;
                
$db->query("UPDATE users SET bankmoney=bankmoney-$gain, money=money+$gain where userid=$userid");
                echo 
"You ask for <b>\$" $gain "</b> to be taken from your account.<br /><br />
                      <b>Bank Manager:</b> Okay <i>" 
$ir['username'] . "</i>, Here is your cash.<br /><br />
                      You now have <b>" 
money_formatter($ir['bankmoney']) . "</b> in your bank account.<br /><br />
                      &gt <a href='bank.php'>Back</a>"
;
        }
}
$h->endpage();
?>

Enjoy!
« Last Edit: July 07, 2011, 03:45:50 PM by Xecho »
Logged
 


This forum is now closed and has moved to a new location! Click here to find out why.