Update!
Bank System v 1.1
After receving advice from Skyld I have made a improved bank system using classes.
DBNPC named BankDB
PHP Code:
function onCreated()
{
this.interest = 0.01;
this.hour = 0;
Interest();
setTimer(3600);
}
function onTimeout()
{
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);
}
}
Class with bank functions
PHP Code:
public function bankCreate(amount)
{
if (BankDB.accounts.index(player.account) = -1)
{
if (player.rupees => amount)
{
BankDB.accounts.add(player.account);
BankDB.("acc"@player.account) = amount;
player.rupees -= amount;
return True;
}
else return "nem";
}
else return false;
}
public function bankDeposit(amount)
{
if (BankDB.accounts.index(player.account) => 0)
{
if (player.rupees => amount)
{
BankDB.("acc"@player.account) += amount;
player.rupees -= amount;
return true;
}
else return "nem"; //Not enough money
}
else return "nba"; //No bank account
}
public function bankWithdraw(amount)
{
if (BankDB.accounts.index(player.account) => 0)
{
if (BankDB.("acc"@player.account) => amount)
{
BankDB.("acc"@player.account) -= amount;
player.rupees += amount;
return true;
}
else return "nem";
}
else return "nba";
}
public function bankBalance()
{
if (BankDB.accounts.index(player.account) => 0)
{
return BankDB.("acc"@player.account);
}
else return "nba";
}
public function bankTransfer(amount,pl)
{
/* Lot's of Tests */
if (BankDB.accounts.index(player.account) => 0)
{
if(BankDB.accounts.index(pl) => 0)
{
if (BankDB.("acc"@player.account) => amount)
{
BankDB.("acc"@pl) += amount;
BankDB.("acc"@player.account) -= amount;
return true;
}
else return "nem";
}
else return "pdne"; //Player does not exist
}
else return "nba";
}
Finally add in your Control-NPC
PHP Code:
function onActionPlayeronline()
{
player.join("classname");
}
function onRCChat()
{
if (params[0] == "interest")
{
if (player.account == "Whoever")
{
echo("Manual Interest Added!");
BankDB.Interest();
}
}
}
Commands Available
PHP Code:
player.bankCreate(amount);
player.bankDeposit(amount);
player.bankWithdraw(amount);
player.bankBalance();
player.bankTransfer(amount,account);
Simple enough to use. Call the commands serverside eg. player.bankDeposit(400);
May add a GUI script to use the Bank system next.