Bank Tutorial
Posted: Sun Oct 18, 2009 6:46 pm
This is the bank code from my testing scripts and would like to give it to the community to go over and incorporate into your game. It plugs right in with the standard tutorials. All you have to do is make a bank.php file and a paste the code below into it. This script will post to itself so no need to link it to another page. This can be inserted into a frame or iframe if you would like. It works very well with those.
I am not using the layout in the tutorials however. I am only using the same tables and names. You will have to replace <?php include session.php';?> with the standard session script from the tutorials.
Basics:
The script will allow you to deposit and withdraw gold in the appropriate fields by entering an amount and then hitting withdraw or deposit. It will update on your stat panel in real time if you add the panel to this script. If you do not enter anything into the fields or try to withdraw or deposit an amount of money you don't have it will give you a negative response.
*This is a stripped down basic version of the one I currently have in development. My full version has random responses and replies from the bank teller. Right now he has 4 greetings, 4 deposit, 4 withdraw, and 4 negative responses. The teller's name also changes depending on the location of where you are banking.
** You will also need a field in your players table called 'bank'. this is where the game will store your money that you do not keep on your character.
Enjoy! I don't think I'll have to make a video to go along with it but if you have any questions please ask.
I am not using the layout in the tutorials however. I am only using the same tables and names. You will have to replace <?php include session.php';?> with the standard session script from the tutorials.
Basics:
The script will allow you to deposit and withdraw gold in the appropriate fields by entering an amount and then hitting withdraw or deposit. It will update on your stat panel in real time if you add the panel to this script. If you do not enter anything into the fields or try to withdraw or deposit an amount of money you don't have it will give you a negative response.
*This is a stripped down basic version of the one I currently have in development. My full version has random responses and replies from the bank teller. Right now he has 4 greetings, 4 deposit, 4 withdraw, and 4 negative responses. The teller's name also changes depending on the location of where you are banking.
** You will also need a field in your players table called 'bank'. this is where the game will store your money that you do not keep on your character.
Code: Select all
<?php
include_once 'connect.php';
session_start();
?>
<?php
include 'session.php';?>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
?>
<center>
<table width="90%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Gold:</td>
<td><?php echo "Your balance is: " . $playerinfo3['bank'] . "<br>";?></td>
</tr>
<tr>
<td>Deposit</td>
<td>Amount:<fieldset>
<form method="post" action="bank.php" target="_self">
<input type="text" name="deposit" value="">
<input type="submit" name="bank_action" value="Deposit">
</form>
</fieldset>
</td>
</tr>
<tr>
<td>Withrawl</td>
<td>Amount:<fieldset>
<form method="post" action="bank.php" target="_self">
<input type="text" name="withdraw" value="">
<input type="submit" name="bank_action" value="Withdraw">
</form>
</fieldset>
</td>
</tr>
</table>
</center>
</div>
<?php
if (isset($_POST['deposit']))
{
if ($_POST['deposit'] > $playerinfo3['gold'] || $_POST['deposit'] < 0)
{
echo "You are trying to deposit too much. Try a smaller amount.";
}
else
{
$newbankd = ($playerinfo3['bank'] + $_POST['deposit']);
$newgoldd = ($playerinfo3['gold'] - $_POST['deposit']);
$bankdeposit = "update players set bank='$newbankd', gold='$newgoldd' where name='$player'";
mysql_query($bankdeposit) or die("could not update bank");
echo "You deposited your gold into the bank!";
}
}
else if (isset($_POST['withdraw']))
{
if ($_POST['withdraw'] > $playerinfo3['bank'] || $_POST['withdraw'] < 0)
{
echo "You do not have enough in your account.";
}
else
{
$newbankw = ($playerinfo3['bank'] - $_POST['withdraw']);
$newgoldw = ($playerinfo3['gold'] + $_POST['withdraw']);
$bankwithdraw = "update players set bank='$newbankw', gold='$newgoldw' where name='$player'";
mysql_query($bankwithdraw) or die("could not withdraw bank");
echo "You have withdrawn your gold!";
}
}
?>