Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //credits Made By djcabo an simple bank system made from scratch and special thanks to sa-mp wiki
- #include <a_samp>
- #include <dini>
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- #define GREEN 0x33AA33AA
- #define RED 0xAA3333AA
- #define YELLOW 0xFFFF00AA
- #define LIGHTBLUE 0x33CCFFAA
- #define ORANGE 0xFF9900AA
- #define DCCbank "DCbank/%s.ini"
- #pragma tabsize 0
- new Bank;
- enum PLAYER_MAIN
- {
- PLAYER_BALANCE,
- PLAYER_INBANK,
- PLAYER_SCORE
- };
- new pBankInfo[MAX_PLAYERS][PLAYER_MAIN];
- new Float:atms[][3] =
- {
- {2475.4091796875, -1747.2602539063, 13.189774513245},
- {2107.5859375, -1790.6883544922, 13.197587013245},
- {1919.0524902344, -1765.8768310547, 13.189774513245},
- {2397.1623535156, -1244.2271728516, 23.646553039551}
- };
- public OnFilterScriptInit()
- {
- print("\n---------------------");
- print("DCbank by djcabo");
- print("-----------------------");
- CreateObject(2942, 2475.4091796875, -1747.2602539063, 13.189774513245, 0.000000, 0.000000, 92.780029296875); //object (kmb_atm1) (1)
- CreateObject(2942, 2107.5859375, -1790.6883544922, 13.197587013245, 0.000000, 0.000000, 185.85498046875); //object (kmb_atm1) (2)
- CreateObject(2942, 1919.0524902344, -1765.8768310547, 13.189774513245, 0.000000, 0.000000, 179.10003662109); //object (kmb_atm1) (3)
- CreateObject(2942, 2397.1623535156, -1244.2271728516, 23.646553039551, 0.000000, 0.000000, 0.000000); //object (kmb_atm1) (4)
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SetPlayerMapIcon(playerid,22,2475.4091796875, -1747.2602539063, 13.189774513245,36,0);
- SetPlayerMapIcon(playerid,24,2107.5859375, -1790.6883544922, 13.197587013245,36,0);
- SetPlayerMapIcon(playerid,26,1919.0524902344, -1765.8768310547, 13.189774513245,36,0);
- SetPlayerMapIcon(playerid,28,2397.1623535156, -1244.2271728516, 23.646553039551,36,0);
- SetPlayerMapIcon(playerid,20,1480.9901,-1771.2242,18.7958,52,0);
- SendClientMessage(playerid,GREEN,"DCbank Simple Bank by djcabo");
- Bank = CreatePickup(1274,23,1480.9901,-1771.2242,18.7958,0);
- new Name[24]; GetPlayerName(playerid,Name,24);
- new file[100]; format(file,100,DCCbank,Name);
- if(!fexist(file)) {
- dini_Create(file);
- dini_IntSet(file,"Score",0);
- dini_IntSet(file,"Balance",0);
- dini_IntSet(file,"InBank",0);
- }
- else {
- pBankInfo[playerid][PLAYER_BALANCE] = dini_Int(file,"Balance");
- pBankInfo[playerid][PLAYER_INBANK] = dini_Int(file,"InBank");
- pBankInfo[playerid][PLAYER_SCORE] = dini_Int(file,"Score");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid,reason)
- {
- pBankInfo[playerid][PLAYER_INBANK] = 0;
- new Name[24]; GetPlayerName(playerid,Name,24);
- new file[100]; format(file,100,dcbank,Name);
- dini_IntSet(file,"Balance",pBankInfo[playerid][PLAYER_BALANCE]);
- dini_IntSet(file,"InBank",pBankInfo[playerid][PLAYER_INBANK]);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(bankhelp,8,cmdtext);
- dcmd(withdraw,8,cmdtext);
- dcmd(deposit,7,cmdtext);
- dcmd(wiret,5,cmdtext);
- dcmd(balance,7,cmdtext);
- dcmd(exit,4,cmdtext);
- return 0;
- }
- dcmd_bankhelp(playerid,params[]) {
- #pragma unused params
- SendClientMessage(playerid,LIGHTBLUE,"**Type /deposit, /withdraw, and /wiret");
- return 1;
- }
- dcmd_withdraw(playerid,params[]) {
- new amount;
- if(sscanf(params,"d",amount)) SendClientMessage(playerid,RED,"USAGE: /withdraw [amount]");
- else if(amount > pBankInfo[playerid][PLAYER_BALANCE]) return SendClientMessage(playerid,RED,"**Insuficient Funds In Bank");
- else if(pBankInfo[playerid][PLAYER_INBANK] == 0)
- {
- if(IsPlayerInRangeOfPoint(playerid,5.0,atms[0][0],atms[0][1],atms[0][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- GivePlayerMoney(playerid,amount);
- new str[256];
- format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[1][0],atms[1][1],atms[1][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- GivePlayerMoney(playerid,amount);
- new str[256];
- format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[2][0],atms[2][1],atms[2][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- GivePlayerMoney(playerid,amount);
- new str[256];
- format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[3][0],atms[3][1],atms[3][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- GivePlayerMoney(playerid,amount);
- new str[256];
- format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else SendClientMessage(playerid,RED,"**You're not near atm or bank");
- }
- else if(amount < pBankInfo[playerid][PLAYER_BALANCE]) {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- GivePlayerMoney(playerid,amount);
- new str[256];
- format(str,sizeof(str),"**You have withdrawn $%d from your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- return 1;
- }
- dcmd_deposit(playerid,params[]) {
- new amount;
- new pMoney;
- pMoney = GetPlayerMoney(playerid);
- if(sscanf(params,"d",amount)) SendClientMessage(playerid,RED,"USAGE: /deposit [amount]");
- else if(GetPlayerMoney(playerid) < amount) return SendClientMessage(playerid,RED,"**Insufficient funds");
- else if(amount > pMoney) return SendClientMessage(playerid,RED,"**Insuficient Funds In Bank");
- else if(pBankInfo[playerid][PLAYER_INBANK] == 0)
- {
- if(IsPlayerInRangeOfPoint(playerid,5.0,atms[0][0],atms[0][1],atms[0][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] += amount;
- GivePlayerMoney(playerid,-amount);
- new str[256];
- format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[1][0],atms[1][1],atms[1][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] += amount;
- GivePlayerMoney(playerid,-amount);
- new str[256];
- format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[2][0],atms[2][1],atms[2][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] += amount;
- GivePlayerMoney(playerid,-amount);
- new str[256];
- format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[3][0],atms[3][1],atms[3][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] += amount;
- GivePlayerMoney(playerid,-amount);
- new str[256];
- format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else SendClientMessage(playerid,RED,"**You are not near an atm or bank");
- }
- else
- {
- pBankInfo[playerid][PLAYER_BALANCE] += amount;
- GivePlayerMoney(playerid,-amount);
- new str[256];
- format(str,sizeof(str),"**You have deposited $%d into your bank account. You now have $%d in the bank",amount,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- return 1;
- }
- dcmd_wiret(playerid,params[]) {
- new id;
- new amount;
- if(sscanf(params,"dd",id,amount)) SendClientMessage(playerid,RED,"USAGE: /transfer [id] [amount]");
- else if(!IsPlayerConnected(id)) return SendClientMessage(id,RED,"**That player is not online");
- else if(amount > pBankInfo[playerid][PLAYER_BALANCE]) return SendClientMessage(playerid,RED,"**Insuficient Funds In Bank");
- else if(pBankInfo[playerid][PLAYER_INBANK] == 0)
- {
- if(IsPlayerInRangeOfPoint(playerid,5.0,atms[0][0],atms[0][1],atms[0][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- pBankInfo[id][PLAYER_BALANCE] += amount;
- new str[256];
- format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[1][0],atms[1][1],atms[1][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- pBankInfo[id][PLAYER_BALANCE] += amount;
- new str[256];
- format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[2][0],atms[2][1],atms[2][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- pBankInfo[id][PLAYER_BALANCE] += amount;
- new str[256];
- format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else if(IsPlayerInRangeOfPoint(playerid,5.0,atms[3][0],atms[3][1],atms[3][2]))
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- pBankInfo[id][PLAYER_BALANCE] += amount;
- new str[256];
- format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- else SendClientMessage(playerid,RED,"**You're not near atm or bank");
- }
- else
- {
- pBankInfo[playerid][PLAYER_BALANCE] -= amount;
- pBankInfo[id][PLAYER_BALANCE] += amount;
- new str[256];
- format(str,sizeof(str),"**You have transferred $%i to id %i's bank account. You now have %i in your bank account",amount,id,pBankInfo[playerid][PLAYER_BALANCE]);
- SendClientMessage(playerid,LIGHTBLUE,str);
- }
- return 1;
- }
- dcmd_balance(playerid,params[]) {
- #pragma unused params
- new name[256];
- GetPlayerName(playerid,name,sizeof(name));
- new string[256], pBalance;
- pBalance = pBankInfo[playerid][PLAYER_BALANCE];
- format(string,sizeof(string),"**Bank Operator: Hi, %s, your balance is $%i",name,pBalance);
- SendClientMessage(playerid,GREEN,string);
- return 1;
- }
- dcmd_exit(playerid,params[]) {
- #pragma unused params
- if(pBankInfo[playerid][PLAYER_INBANK] == 1) {
- SetPlayerInterior(playerid,0);
- SetPlayerPos(playerid,1481.0139,-1763.1412,18.7958);
- pBankInfo[playerid][PLAYER_INBANK] = 0;
- }
- return 1;
- }
- public OnPlayerPickUpPickup(playerid,pickupid)
- {
- if(pickupid == Bank) {
- SetPlayerInterior(playerid,10);
- SetPlayerPos(playerid,6.091180,-29.271898,1003.549988);
- pBankInfo[playerid][PLAYER_INBANK] = 1;
- GameTextForPlayer(playerid,"~r~/exit ~b~to leave the bank",5000,3);
- }
- return 1;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs();
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if (ch >= '0' && ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return 1;
- }
- }
- while ((ch = string[stringPos]) && ch != ' ');
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- ch,
- num = 0;
- while ((ch = string[stringPos++]))
- {
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- case ' ':
- {
- break;
- }
- default:
- {
- return 1;
- }
- }
- }
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new tmp[25];
- strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
- setarg(paramPos, 0, _:floatstr(tmp));
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != ' ')
- {
- setarg(paramPos, i++, ch);
- }
- if (!i) return 1;
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != ' ')
- {
- stringPos++;
- }
- while (string[stringPos] == ' ')
- {
- stringPos++;
- }
- paramPos++;
- }
- while (format[formatPos] == 'z') formatPos++;
- return format[formatPos];
- }
Add Comment
Please, Sign In to add comment