Bank system I made using dbnpc.
DBNPC Script (Name is BankDB):
PHP Code:
function onCreated()
{
this.interest = 0.01;
this.hour = 0;
Interest();
setTimer(3600);
}
public function CreateAccount(pl,ammount)
{
if (this.accounts.index(pl) = -1)
{
this.accounts.add(pl);
this.("acc"@pl) = ammount;
findplayer(pl).rupees -= ammount;
return true
}
else return false;
}
public function CheckBalance(pl)
{
if (this.accounts.index(pl) => 0)
{
return this.("acc"@pl);
}
else return false;
}
public function AddMoney(pl,ammount)
{
if (this.accounts.index(pl) => 0)
{
findplayer(pl).rupees -= ammount;
this.("acc"@pl) += ammount;
return this.("acc"@pl);
}
else return false;
}
public function RemoveMoney(pl,ammount)
{
if (this.accounts.index(pl) => 0)
{
if (this.("acc"@pl) => ammount)
{
this.("acc"@pl) -= ammount;
findplayer(pl).rupees += ammount;
return true;
}
else return "nm";
}
else return "na";
}
function onTimeout()
{
/* Cheers to Kuji for this.hour idea */
this.hour ++;
if (this.hour => 24)
{
echo("Interest Added");
Interest();
this.hour = 0;
}
setTimer(3600);
}
public function Interest()
{
for (int : this.accounts)
{
this.("acc"@int) = int(this.("acc"@int) * 1.01);
}
}
Manual interest for RC - add this to your Control-NPC
PHP Code:
function onRCChat()
{
if (params[0] == "interest")
{
if (player.account == "Whoever")
{
echo("Manual Interest Added!");
BankDB.Interest();
}
}
}
And finally some examples on how to use this system in a bank
PHP Code:
/* Do not clientside this script */
function onPlayerChats()
{
/*Create Account*/
if (player.chat.starts("/createaccount"))
{
temp.result = BankDB.CreateAccount(player.account,player.chat.substring(15,-1));
if (temp.result == true)
say2("Account Opened");
else say2("You already have an account");
}
else if (player.chat == "/balance")
{
temp.result = BankDB.CheckBalance(player.account);
if(temp.result != false)
say2("Current Balance" SPC temp.result);
else say2("You do not have an account");
}
else if (player.chat.starts("/withdraw"))
{
temp.result = BankDB.RemoveMoney(player.account,player.chat.substring(10,-1));
if (temp.result == "na")
say2("Open an account?");
else if (temp.result == "nm")
say2("Not enough money");
else if (temp.result == true)
say2("Withdrawn");
}
else if (player.chat.starts("/deposit"))
{
if (player.rupees > player.chat.substring(9,-1))
{
temp.result = BankDB.AddMoney(player.account,player.chat.substring(9,-1));
if (temp.result != false)
say2("Money Deposited. Balance: " @ temp.result);
else
say2("Open an account first");
}
}
}
This system can work on a global scale. One BankDB can serve any ammount of banks. I used a BankDB for a couple of reasons. First off - incredibly easy to add interest now. Secondly - I can use functions to determine who has the most money, total ammount of money etc. (Not included).