Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and lost your copy? Just file a support ticket through your "My Mods" page.


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

AuthorTopic: [Mccodes V2] Crystal Bank  (Read 227 times)

Peterisgb

  • Basic Member
  • *
  • Reputation Power: 20
  • Peterisgb has no influence.
  • Offline Offline
  • Posts: 14
    • View Profile
    • Email
[Mccodes V2] Crystal Bank
« on: January 08, 2012, 02:11:07 PM »
A Crystal Bank for your users

create file called crystalbank.php
place this in the file
Code: [Select]
<?php
include "globals.php";
print 
"<h3>Crystal Bank Bank</h3>";
if(
$ir['crystalbank']>-1)
{
switch(
$_GET['action'])
{
case 
"deposit":
deposit();
break;
 
case 
"withdraw":
withdraw();
break;
 
default:
index();
break;
}
 
}
else
{
if(isset(
$_GET['buy']))
{
if(
$ir['crystals']>5000)
{
print 
"Congratulations, you bought a Crystal bank account for 5000 Crystals Coins!
 
<a href='goldbank.php'>Start using my account</a>"
;
$db->query("UPDATE users SET crystals=crystals-5000,crystalbank=0 WHERE userid=$userid");
}
else
{
print 
"You do not have enough Money to open an account.
<a href='explore.php'>Back to town...</a>"
;
}
}
else
{
print 
"Open a crystal bank account today, just 5000 Crystals coins!
 
<a href='crystalbank.php?buy'> Yes, sign me up!</a>"
;
}
}
function 
index()
{
global 
$db$ir,$c,$userid,$h;
print 
"\n<b>You currently have {$ir['crystalbank']} crystals in the bank.</b>
 
<table width='75%' cellspacing=1 class='table'> <tr> <td width='50%'><b>Deposit Crystals</b>
 
<form action='crystalbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['crystals']}' />
 
<input type='submit' value='Deposit' /></form></td> <td>
<b>Withdraw crystals</b>
 
There is no fee on withdrawals.<form action='crystalbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['crystalbank']}' />
 
<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['crystals'])
{
print 
"You do not have enough crystals to deposite in the bank bank.";
}
else
{
$gain=$_POST['deposit']-$fee;
$ir['crystal']+=$gain;
$db->query("UPDATE users SET crystalbank=crystalbank+$gain, crystals=crystals-{$_POST['deposit']} where userid=$userid");
print 
"You hand over {$_POST['deposit']} to be deposited,
 
$gain is added to your account.
 
<b>You now have {$ir['crystalbank']} in the bank.</b>
 
<a href='crystalbank.php'> Back</a>"
;
}
}
function 
withdraw()
{
global 
$db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((int) $_POST['withdraw']);
if(
$_POST['withdraw'] > $ir['crystalbank'])
{
print 
"You do not have enough crystals to withdraw from the bank.";
}
else
{
 
$gain=$_POST['withdraw'];
$ir['crystalbank']-=$gain;
$db->query("UPDATE users SET crystalbank=crystalbank-$gain, crystals=crystals+$gain where userid=$userid");
print 
"You ask to withdraw $gain,
 
the banking lady grudgingly hands it over.
 
<b>You now have {$ir['crystalbank']} in the bank.</b>
 
<a href='crystalbank.php'> Back</a>"
;
}
}
$h->endpage();
?>


Add to your database

crystalbank int 11 default 0
Logged

javance

  • Basic Member
  • *
  • Reputation Power: 2
  • javance has no influence.
  • Offline Offline
  • Posts: 5
    • View Profile
    • Email
Re: [Mccodes V2] Crystal Bank
« Reply #1 on: January 14, 2012, 10:06:05 AM »
wrong thing for database, dont work bro....................edit it plz!
Logged

dominion

  • Active Member
  • **
  • Reputation Power: 89
  • dominion barely matters.dominion barely matters.
  • Offline Offline
  • Posts: 129
    • View Profile
    • Email
Re: [Mccodes V2] Crystal Bank
« Reply #2 on: January 15, 2012, 08:11:30 AM »
wrong thing for database, dont work bro....................edit it plz!

It's not an exact query it's just telling you what to add...
Logged

javance

  • Basic Member
  • *
  • Reputation Power: 2
  • javance has no influence.
  • Offline Offline
  • Posts: 5
    • View Profile
    • Email
Re: [Mccodes V2] Crystal Bank
« Reply #3 on: January 16, 2012, 04:26:52 AM »
can u edit it for me so it can be in database
Logged

Peterisgb

  • Basic Member
  • *
  • Reputation Power: 20
  • Peterisgb has no influence.
  • Offline Offline
  • Posts: 14
    • View Profile
    • Email
Re: [Mccodes V2] Crystal Bank
« Reply #4 on: January 18, 2012, 05:31:47 AM »
read the post.............
Logged

Djkanna

  • Basic Member
  • *
  • Reputation Power: 0
  • Djkanna is looked down upon.
  • Offline Offline
  • Posts: 29
    • View Profile
Re: [Mccodes V2] Crystal Bank
« Reply #5 on: January 20, 2012, 03:53:57 PM »
can u edit it for me so it can be in database

Code: [Select]
ALTER TABLE `users` ADD `crystalbank` INT (11) UNSIGNED NOT NULL DEFAULT 0 Run this in your DBMS of choice.
Logged
 


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