Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- //
- // trablon's Realistic Bank System
- // Coder: trablon(Onur YAKAVETTA)
- // Tester: TaMSaH , razol , Woods
- //
- //
- //
- //
- ///////////////////////////////////////////////////////////////////////////////
- //=====================================================================[include]
- #include <a_samp>
- #include <file>
- #include <zcmd>
- #include <sscanf2>
- #define Scripter "trablon"
- #define ScriptVersion "ALPHA(0.1)"
- #define function%0(%1) forward%0(%1); \
- public%0(%1)
- new AccBalance[MAX_PLAYERS];
- new AccNumber[MAX_PLAYERS];
- //==============================================================================
- public OnPlayerConnect(playerid)
- {
- ReadBankAccounts(playerid);
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- return 1;
- }
- //==============================================================================
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect FC_OnPlayerConnect
- #if defined _ALS_OnPlayerUpdate
- #undef OnPlayerUpdate
- #else
- #define _ALS_OnPlayerUpdate
- #endif
- #define OnPlayerUpdate FC_OnPlayerUpdate
- //=======================================================================[zcmd]
- CMD:openaccount(playerid, params[])
- {
- if(AccNumber[playerid] > 0) return SendClientMessage(playerid,0xFF0000FF,"* You already have a bank account.");
- new accnumber = 10000 + random(99999),str[128];
- CreateBankAccount(Isim(playerid), accnumber, 0);
- format(str,sizeof(str),"* Your account has been created. ( Account Number: %i , Balance: 0$ )",accnumber);
- SendClientMessage(playerid,0x00FF00FF,str);
- SendClientMessage(playerid,-1,"INFO: You can view your bank setting by writing '/bank' command.");
- return 1;
- }
- CMD:bank(playerid,params[])
- {
- if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
- new str[128];
- format(str,sizeof(str),"* Your account has been created. ( Account Number: %i , Balance: %i$ )",AccNumber[playerid],AccBalance[playerid]);
- SendClientMessage(playerid,0x00FF00FF,str);
- SendClientMessage(playerid,-1,"INFO: You can send money to other player's account by writing their account number.(/transfer)");
- return 1;
- }
- CMD:transfer(playerid,params[])
- {
- new number,amm;
- if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
- if(sscanf(params, "dd",number,amm)) return SendClientMessage(playerid, -1, "* /transfer [Bank Account Number] [Amount]");
- if(amm < 1 || amm > 10000) return SendClientMessage(playerid,0xFF0000FF,"* Enter number between 1 and 10000$.");
- if(AccBalance[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have enough cash in your bank account.");
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(number == AccNumber[i])
- {
- AccBalance[playerid] -= amm;
- AccBalance[i] += amm;
- SendClientMessage(i,0x00FF00FF,"* Someone transfared money into your bank account.");
- }
- }
- SendClientMessage(playerid,0x00FF00FF,"* You have transfered your money to player's account.");
- return 1;
- }
- CMD:deposit(playerid,params[])
- {
- new amm;
- if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
- if(sscanf(params, "d",amm)) return SendClientMessage(playerid, -1, "* /deposit [Amount]");
- if(amm < 1 || amm > 10000) return SendClientMessage(playerid,0xFF0000FF,"* Enter number between 1 and 10000$.");
- if(GetPlayerMoney(playerid) == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have enough cash.");
- GivePlayerMoney(playerid,-amm);
- AccBalance[playerid] += amm;
- SendClientMessage(playerid,0x00FF00FF,"* You have deposited your cash.(To check your balance, /bank)");
- return 1;
- }
- CMD:withdraw(playerid,params[])
- {
- new amm;
- if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
- if(sscanf(params, "d",amm)) return SendClientMessage(playerid, -1, "* /withdraw [Amount]");
- if(amm < 1 || amm > 10000) return SendClientMessage(playerid,0xFF0000FF,"* Enter number between 1 and 10000$.");
- if(AccBalance[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have enough cash.");
- GivePlayerMoney(playerid,amm);
- AccBalance[playerid] -= amm;
- SendClientMessage(playerid,0x00FF00FF,"* You have withdrawn your cash.(To check your balance, /bank)");
- return 1;
- }
- //=======================================================================[stock]
- function fcreate(filename[])
- {
- if (fexist(filename)){return false;}
- new File:fhandle = fopen(filename,io_write);
- fclose(fhandle);
- return true;
- }
- function CreateBankAccount(playername[],accnumber, balance)
- {
- new string[128];
- new File:p0s=fopen("BankAccounts.cfg", io_append);
- if(!p0s)
- {
- fcreate("BankAccounts.cfg");
- }
- format(string, 256, "%s, %i, %i\n\r", playername, accnumber, balance);
- fwrite(p0s,string);
- fclose(p0s);
- return 1;
- }
- function ReadBankAccounts(playerid)
- {
- new File:p0s=fopen("BankAccounts.cfg", io_read);
- new string[128];
- while(fread(p0s, string))
- {
- if(strcmp(string, Isim(playerid), false, strlen(Isim(playerid)))==0)
- {
- AccNumber[playerid]=GetVal(1, string);
- AccBalance[playerid]=GetVal(2, string);
- }
- }
- fclose(p0s);
- return 1;
- }
- GetVal(numb, str[]) {
- new tmp[256], idx;
- for(new i=0; i<numb; i++)
- {
- tmp=strtok(str, idx);
- }
- return strval(tmp);
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock Isim(playerid)
- {
- new isimm[MAX_PLAYER_NAME];
- GetPlayerName(playerid,isimm,MAX_PLAYER_NAME);
- return isimm;
- }
- //=====================================================================[forward]
- forward OnPlayerConnect(playerid);
- forward OnPlayerUpdate(playerid);
- // =========== [ END ] ============== //
Add Comment
Please, Sign In to add comment