CMD:bank(playerid, params[])
{
// Build a main state to check if a player is inside a bank
new type[20];
if (sscanf(params, "s[20]", type))
{
return SendSyntaxMessage(playerid, "/bank [balance/withdraw/deposit/savings/loan]");
}
// Balance
if (!strcmp(type, "balance", true, 7))
{
SendClientMessageEx(playerid, COLOR_INFO, "Your current balance is: %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
// Deposit
if (!strcmp(type, "deposit", true, 7))
{
new amount[20];
if (sscanf(params, "s[20]d[20]", type, amount))
{
SendSyntaxMessage(playerid, "/bank deposit [amount]");
return 1;
}
else
{
if(amount[0] > Player[playerid][pCash])
{
SendErrorMessage(playerid, "You don't have enough money on your hand to do that.");
return 1;
}
if(amount[0] <= 0)
{
SendErrorMessage(playerid, "You can't deposit zero or less cash.");
return 1;
}
else {
new nBank, nCash;
nBank = Player[playerid][pBank] + amount[0];
nCash = Player[playerid][pCash] - amount[0];
Player[playerid][pBank] = nBank;
Player[playerid][pCash] = nCash;
GivePlayerMoney(playerid, - amount[0]);
SendClientMessageEx(playerid, COLOR_SUCCESS, "You've deposited %d onto your bank account.", FormatNumber(amount[0]));
SendClientMessageEx(playerid, COLOR_INFO, "Your new balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
}
}
// Withdraw
if (!strcmp(type, "withdraw", true, 8))
{
new amount[20];
if (sscanf(params, "s[20]d[20]", type, amount))
{
SendSyntaxMessage(playerid, "/bank withdraw [amount]");
SendClientMessageEx(playerid, COLOR_INFO, "Your balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
else
{
if(amount[0] > Player[playerid][pBank])
{
SendErrorMessage(playerid, "You don't have enough balance to do that.");
SendClientMessageEx(playerid, COLOR_INFO, "Your balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
if(amount[0] <= 0)
{
SendErrorMessage(playerid, "You can't withdraw zero or less cash.");
return 1;
}
else {
new nBank, nCash;
nBank = Player[playerid][pBank] - amount[0];
nCash = Player[playerid][pCash] + amount[0];
Player[playerid][pBank] = nBank;
Player[playerid][pCash] = nCash;
GivePlayerMoney(playerid, amount[0]);
SendClientMessageEx(playerid, COLOR_SUCCESS, "You've withdrawn %d from your bank account.", FormatNumber(amount[0]));
SendClientMessageEx(playerid, COLOR_INFO, "Your new balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
}
}
// Savings
if (!strcmp(type, "savings", true, 7))
{
new subtype[20];
// Main command
if (sscanf(params, "s[20]s[20]", type, subtype))
{
SendSyntaxMessage(playerid, "/bank savings [info/create/abort]");
if(Player[playerid][pSavings] == 0)
{
SendClientMessageEx(playerid, COLOR_INFO, "You haven't created a savings account yet.");
SendClientMessageEx(playerid, COLOR_INFO, "You can create one by using [/bank savings create]");
return 1;
}
if(Player[playerid][pSavings] >= SAVINGS_MIN || Player[playerid][pSavings] <= SAVINGS_MAX)
{
SendClientMessageEx(playerid, COLOR_INFO, "You have a savings account with plan %d.", Player[playerid][pSavingsPlan]);
SendClientMessageEx(playerid, COLOR_INFO, "Your savings initial deposit is %d, which has an interest rate of %d percent.", FormatNumber(Player[playerid][pSavings]), GetSavingsRate(Player[playerid][pSavingsPlan]));
SendClientMessageEx(playerid, COLOR_INFO, "You currently have %d hours on the savings. Your goal is %d hours.", Player[playerid][pSavingsTime], GetSavingsPaychecks(Player[playerid][pSavingsPlan]));
}
return 1;
}
else
{
// Savings info
if (!strcmp(subtype, "info", true, 4))
{
SendClientMessageEx(playerid, COLOR_INFO, "Info about savings and the plans.");
return 1;
}
// Savings create
if (!strcmp(subtype, "create", true, 6))
{
new amount[20], plan[20];
if (sscanf(params, "s[20]s[20]d[20]d[20]", type, subtype, amount, plan))
{
SendSyntaxMessage(playerid, "/bank savings create [%d-%d] [1-4]", FormatNumber(SAVINGS_MIN), FormatNumber(SAVINGS_MAX));
SendClientMessageEx(playerid, COLOR_INFO, "Use '/bank savings info' for more information about savings.");
return 1;
}
else
{
if(Player[playerid][pSavings] == 0)
{
if(plan[0] <= 0 || plan[0] > 4)
{
SendErrorMessage(playerid, "The savings plan you've entered does not exist.");
SendSyntaxMessage(playerid, "/bank savings create [%d-%d] [1-4]", FormatNumber(SAVINGS_MIN), FormatNumber(SAVINGS_MAX));
return 1;
}
if(amount[0] < SAVINGS_MIN || amount[0] > SAVINGS_MAX)
{
SendErrorMessage(playerid, "The deposit value for your savings have to be between %d and %d.", FormatNumber(SAVINGS_MIN), FormatNumber(SAVINGS_MAX));
return 1;
}
if(amount[0] > Player[playerid][pBank])
{
SendErrorMessage(playerid, "You do not have enough money on your bank account to do that.");
return 1;
}
else
{
new nBank, nSavings, nPlan;
nBank = Player[playerid][pBank] - amount[0];
nSavings = Player[playerid][pSavings] + amount[0];
nPlan = plan[0];
Player[playerid][pBank] = nBank;
Player[playerid][pSavings] = nSavings;
Player[playerid][pSavingsPlan] = nPlan;
Player[playerid][pSavingsTime] = 0;
SendClientMessageEx(playerid, COLOR_SUCCESS, "You've created a savings account with %d using plan %d.", FormatNumber(amount[0]), plan);
SendClientMessageEx(playerid, COLOR_INFO, "Your new main bank balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
}
else
{
SendErrorMessage(playerid, "You already have a savings account.");
return 1;
}
}
}
// Savings abort
if (!strcmp(subtype, "abort", true, 5))
{
if(Player[playerid][pSavings] == 0)
{
SendErrorMessage(playerid, "You haven't got an savings account yet.");
return 1;
}
else
{
new confirm[20];
if (sscanf(params, "s[20]s[20]s[20]", type, subtype, confirm))
{
SendWarningMessage(playerid, "You'll lose all your gained interest if you abort now. Are you sure to abort your savings account?");
SendSyntaxMessage(playerid, "/bank savings abort yes");
return 1;
}
else
{
if (!strcmp(confirm, "yes", true, 3))
{
new nBank, nSavings, initialSavings;
nBank = Player[playerid][pBank] + Player[playerid][pSavings];
nSavings = 0;
initialSavings = Player[playerid][pSavings];
// Tax?
Player[playerid][pBank] = nBank;
Player[playerid][pSavings] = nSavings;
Player[playerid][pSavingsPlan] = 0;
Player[playerid][pSavingsTime] = 0;
SendClientMessageEx(playerid, COLOR_SUCCESS, "You've successfully aborted your savings account.");
SendClientMessageEx(playerid, COLOR_SUCCESS, "There has been %d deposited to your main bank account.", FormatNumber(initialSavings));
SendClientMessageEx(playerid, COLOR_INFO, "Your new bank account balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
else
{
SendSyntaxMessage(playerid, "/bank savings abort yes");
return 1;
}
}
}
}
}
}
if (!strcmp(type, "loan", true, 4))
{
new subtype[20];
// Main command
if (sscanf(params, "s[20]s[20]", type, subtype))
{
SendSyntaxMessage(playerid, "/bank loan [info/new]");
if(Player[playerid][pLoan] == 0)
{
SendClientMessageEx(playerid, COLOR_INFO, "You haven't got a loan yet.");
SendClientMessageEx(playerid, COLOR_INFO, "You can request one by using [/bank loan new]");
return 1;
}
if(Player[playerid][pLoan] >= LOAN_MIN || Player[playerid][pLoan] <= LOAN_MAX)
{
SendClientMessageEx(playerid, COLOR_INFO, "You currently have a loan with plan %d.", Player[playerid][pLoanPlan]);
SendClientMessageEx(playerid, COLOR_INFO, "Your initial loan is %d, which has an interest rate of %d percent.", FormatNumber(Player[playerid][pLoan]), GetLoanRate(Player[playerid][pLoanPlan]));
SendClientMessageEx(playerid, COLOR_INFO, "You currently have paid %d times. You need a total of %d times to pay it off completely.", Player[playerid][pLoanTime], GetLoanPaychecks(Player[playerid][pLoanPlan]));
}
return 1;
}
else
{
// Loan info
if (!strcmp(subtype, "info", true, 4))
{
SendClientMessageEx(playerid, COLOR_INFO, "Info about loan and the plans.");
return 1;
}
// Loan new
if (!strcmp(subtype, "new", true, 3))
{
new amount[20], plan[20];
if (sscanf(params, "s[20]s[20]d[20]d[20]", type, subtype, amount, plan))
{
SendSyntaxMessage(playerid, "/bank loan new [%d-%d] [1-4]", FormatNumber(LOAN_MIN), FormatNumber(LOAN_MAX));
SendClientMessageEx(playerid, COLOR_INFO, "Use '/bank loan info' for more information about loans.");
return 1;
}
else
{
if(Player[playerid][pLoan] == 0)
{
if(plan[0] <= 0 || plan[0] > 4)
{
SendErrorMessage(playerid, "The loan plan you've entered does not exist.");
SendSyntaxMessage(playerid, "/bank loan new [%d-%d] [1-4]", FormatNumber(LOAN_MIN), FormatNumber(LOAN_MAX));
return 1;
}
if(amount[0] < LOAN_MIN || amount[0] > SAVINGS_MAX)
{
SendErrorMessage(playerid, "The amount of loan has to be between %d and %d.", FormatNumber(LOAN_MIN), FormatNumber(LOAN_MAX));
return 1;
}
else
{
new nBank, nLoan, nPlan;
nBank = Player[playerid][pBank] + amount[0];
nLoan = Player[playerid][pLoan] + amount[0];
nPlan = plan[0];
Player[playerid][pBank] = nBank;
Player[playerid][pLoan] = nLoan;
Player[playerid][pLoanPlan] = nPlan;
Player[playerid][pLoanTime] = 0;
SendClientMessageEx(playerid, COLOR_SUCCESS, "You've successfully received a loan of %d using plan %d.", FormatNumber(amount[0]), plan);
SendClientMessageEx(playerid, COLOR_INFO, "Your new main bank balance is %d.", FormatNumber(Player[playerid][pBank]));
return 1;
}
}
else
{
SendErrorMessage(playerid, "You already have a loan.");
return 1;
}
}
}
}
}
else
{
return SendSyntaxMessage(playerid, "/bank [balance/withdraw/deposit/savings/loan]");
}
return 1;
}
I'd suggest using a dialog when command /bank is used, I can try to help but I am on phone right now so yeah, you'll have to wait a little bit. Other than that, not bad at all!
|
new amount[20];
if(strcmp(type, "savings") == 0)
Alrighty let me point a few things out:
Код:
new amount[20]; So remove all the [...] after all 'amount' variables and dont forget to remove it from the sscanf lines aswell! (Now you also dont need to format that variable to display it.) |
if(strcmp(type, "savings") == 0)
PHP код:
Thanks |