Guest User

Bank System

a guest
Mar 17th, 2014
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.85 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #include <sscanf2>
  4. #include <zcmd>
  5. //---------------
  6. #define COLOR_WHITE 0xFFFFFFFF
  7. #define COLOR_GREY 0x999999FF
  8. #define COLOR_YELLOW 0xFFFF00FF
  9. #define FILTERSCRIPT
  10. #define BANK_FILE "Bank/%s.ini"
  11. #define PRESSED(%0) \
  12.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  13. //---------------
  14. enum pInfo
  15. {
  16.     BankAcc,
  17.     Bcash,
  18.     Cash,
  19.     BankPass,
  20.     BankOpen,
  21.     Card
  22. }
  23. new PlayerInfo[MAX_PLAYERS][pInfo];
  24. public OnFilterScriptInit()
  25. {
  26.     printf("\n=======================");
  27.     printf("Bank System 1.0 by James_Carter");
  28.     printf(">> Status: LOADED !");
  29.     printf("\n=======================");
  30.     return 1;
  31. }
  32. public OnFilterScriptExit()
  33. {
  34.     printf("\n=======================");
  35.     printf("Bank System 1.0 by James_Carter");
  36.     printf(">> Status: UNLOADED !");
  37.     printf("\n=======================");
  38.     return 1;
  39. }
  40. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  41. {
  42.     if(PRESSED(KEY_SECONDARY_ATTACK))
  43.     {
  44.         if(IsPlayerInRangeOfPoint(playerid, 4.0,1464.1750,-1011.3233,26.8438))//BANK EXTERIOR
  45.         {
  46.             SetPlayerPos(playerid,2315.952880,-1.618174,26.742187);
  47.             SetPlayerInterior(playerid,0);
  48.             if(PlayerInfo[playerid][BankAcc] == 0)
  49.             {
  50.                 SendClientMessage(playerid,COLOR_YELLOW,"[Bank]: You can create a bank account for free using /bankaccount !");
  51.             }
  52.             if(PlayerInfo[playerid][Card] == 0)
  53.             {
  54.                 SendClientMessage(playerid,COLOR_YELLOW,"[Bank]: You can buy for 25.000$ your card using /card !");
  55.             }
  56.         }
  57.         else if(IsPlayerInRangeOfPoint(playerid, 2.0,2315.952880,-1.618174,26.742187))//BANK INTERIOR
  58.         {
  59.             SetPlayerPos(playerid,1464.1750,-1011.3233,26.8438);
  60.             PlayerInfo[playerid][BankOpen] = 0;
  61.             SetPlayerInterior(playerid,0);
  62.         }
  63.     }
  64.     return 1;
  65. }
  66. public OnPlayerConnect(playerid)
  67. {
  68.     new name[MAX_PLAYER_NAME],file[128];
  69.     GetPlayerName(playerid,name,sizeof(name));
  70.     format(file,sizeof(file),BANK_FILE,name);
  71.     if(!dini_Exists(file))
  72.     {
  73.         dini_Create(file);
  74.         dini_IntSet(file,"BankAcc",PlayerInfo[playerid][BankAcc] = 0);
  75.         dini_IntSet(file,"BankCash",PlayerInfo[playerid][Bcash] = 0);
  76.         dini_IntSet(file,"Money",PlayerInfo[playerid][Cash] = 25000);
  77.         dini_IntSet(file,"BankPassword",PlayerInfo[playerid][BankPass] = -1);
  78.         dini_IntSet(file,"AccountOpen",PlayerInfo[playerid][BankOpen] = 0);
  79.         dini_IntSet(file,"Card",PlayerInfo[playerid][Card] = 0);
  80.     }
  81.     else
  82.     {
  83.         PlayerInfo[playerid][BankAcc] = dini_Int(file,"BankAcc");
  84.         PlayerInfo[playerid][Bcash] = dini_Int(file,"BankCash");
  85.         PlayerInfo[playerid][Cash] = dini_Int(file,"Cash");
  86.         PlayerInfo[playerid][BankPass] = dini_Int(file,"BankPassword");
  87.         PlayerInfo[playerid][BankOpen] = dini_Int(file,"AccountOpen");
  88.         PlayerInfo[playerid][Card] = dini_Int(file,"Card");
  89.     }
  90.     return 1;
  91. }
  92. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  93. {
  94.     if(dialogid == 1)
  95.     {
  96.         if(PlayerInfo[playerid][BankAcc] == 0)
  97.         {
  98.             if(strval(inputtext) > 9999 || strval(inputtext) < 999) return ShowPlayerDialog(playerid,4,DIALOG_STYLE_INPUT,"Bank Account","Your password must contain only numbers and must have 4 characters !","Create","Cancel");
  99.             else
  100.             {
  101.                 PlayerInfo[playerid][BankAcc] = 1;
  102.                 PlayerInfo[playerid][BankOpen] = 1;
  103.                 PlayerInfo[playerid][BankPass] = strval(inputtext);
  104.                 SendClientMessage(playerid,COLOR_YELLOW,"[Info]: Bank account succesfully created !");
  105.                 SendClientMessage(playerid,COLOR_YELLOW,"Now you can withdraw or deposit money in the bank !");
  106.             }
  107.         }
  108.         else return ShowPlayerDialog(playerid,5,DIALOG_STYLE_INPUT,"Bank Account","Please type your bank account password","Login","Cancel");
  109.     }
  110.     if(dialogid == 2)
  111.     {
  112.         if(!response)
  113.         {
  114.             PlayerInfo[playerid][BankOpen] = 0;
  115.         }
  116.         else
  117.         {
  118.             new file[128],tmp,name[MAX_PLAYER_NAME],str[128];
  119.             GetPlayerName(playerid,name,sizeof(name));
  120.             format(file,sizeof(file),BANK_FILE,name);
  121.             tmp = dini_Int(file, "BankPassword");
  122.             if(tmp != strval(inputtext)) return ShowPlayerDialog(playerid,5,DIALOG_STYLE_INPUT,"Bank Account","The password you entered is not correct !","Login","Cancel");
  123.             else if(!response)
  124.             {
  125.                 PlayerInfo[playerid][BankOpen] = 0;
  126.             }
  127.             else if(tmp == strval(inputtext))
  128.             {
  129.                 format(str,sizeof(str),"[Info]: Password match,welcome dear {ff0000}%s{ffff00} at L.S. Central Bank.",name);
  130.                 SendClientMessage(playerid,COLOR_YELLOW,str);
  131.                 PlayerInfo[playerid][BankOpen] = 1;
  132.             }
  133.         }
  134.     }
  135.     if(dialogid == 3)
  136.     {
  137.         if(response)
  138.         {
  139.             if(listitem == 1)
  140.             {
  141.                 if(GetPlayerMoney(playerid) >= 25000)
  142.                 {
  143.                     PlayerInfo[playerid][Card] = 1;
  144.                     new oldcash = GetPlayerMoney(playerid);
  145.                     ResetPlayerMoney(playerid);
  146.                     GivePlayerMoney(playerid,oldcash-25000);
  147.                     SendClientMessage(playerid,COLOR_YELLOW,"[Info]: You have succesfully bought the card !");
  148.                 }
  149.                 else{SendClientMessage(playerid,COLOR_GREY,"You don't have enough money !");}
  150.             }
  151.             if(listitem == 2)
  152.             {
  153.                 if(PlayerInfo[playerid][Bcash] >= 25000)
  154.                 {
  155.                     PlayerInfo[playerid][Card] = 1;
  156.                     PlayerInfo[playerid][Bcash] -= 25000;
  157.                     SendClientMessage(playerid,COLOR_YELLOW,"[Info]: You have succesfully bought the A.T.M. card !");
  158.                 }
  159.                 else{SendClientMessage(playerid,COLOR_GREY,"You don't have enough money !");}
  160.             }
  161.         }
  162.         else if(!response) return SendClientMessage(playerid,COLOR_GREY,"[Bank]: You can come back everytime to get your  card !");
  163.     }
  164.     return 1;
  165. }
  166. //---------------[Bank CMD's]---------------------------
  167. CMD:withdraw(playerid,params[])
  168. {
  169.     new cash,bank;
  170.     new string[128],name[MAX_PLAYER_NAME];
  171.     if(PlayerInfo[playerid][BankAcc] == 1)
  172.     {
  173.         if(IsPlayerInRangeOfPoint(playerid,5.0,2316.6194,-9.9600,26.7422))
  174.         {
  175.             if(PlayerInfo[playerid][BankOpen] == 1)
  176.             {
  177.                 if(sscanf(params,"i",bank)) return SendClientMessage(playerid,COLOR_GREY,"Syntax: /withdraw [Amount]");
  178.                 else if(bank <= 0) return SendClientMessage(playerid,COLOR_GREY,"The minimun amount is 1$ !");
  179.                 else if(PlayerInfo[playerid][Bcash] < bank) return SendClientMessage(playerid,COLOR_GREY,"You don't have enough money !");
  180.                 else
  181.                 {
  182.                     GetPlayerName(playerid,name,sizeof(name));
  183.                     PlayerInfo[playerid][Bcash] -= bank;
  184.                     PlayerInfo[playerid][Cash] += bank;
  185.                     cash = GetPlayerMoney(playerid);
  186.                     ResetPlayerMoney(playerid);
  187.                     GivePlayerMoney(playerid, cash+bank);
  188.                     format(string,sizeof(string),"[Info]:{FFFFFF} You have taken from your bank account {FFFF00}%d{009900}${FFFFFF}.",bank);
  189.                     SendClientMessage(playerid,COLOR_YELLOW,string);
  190.                 }
  191.             }
  192.             else{SendClientMessage(playerid,COLOR_GREY,"First request permission to withdraw money from bank account desk office by typing your bank password !");}
  193.         }
  194.         else{SendClientMessage(playerid,COLOR_GREY,"You must be inside the bank at withdraw desk office !");}
  195.     }
  196.     else{SendClientMessage(playerid,COLOR_GREY,"You don't have a bank account !");SendClientMessage(playerid,COLOR_GREY,"Go to {FFFF00}Los Santos Central Bank{B5B1B0} and create one.");}
  197.     return 1;
  198. }
  199. CMD:deposit(playerid,params[])
  200. {
  201.     new cash,bank;
  202.     new string[128],name[MAX_PLAYER_NAME];
  203.     if(PlayerInfo[playerid][BankAcc] == 1)
  204.     {
  205.         if(IsPlayerInRangeOfPoint(playerid,5.0,2316.6208,-12.7549,26.7422))
  206.         {
  207.             if(PlayerInfo[playerid][BankOpen] == 1)
  208.             {
  209.                 if(sscanf(params,"i",bank)) return SendClientMessage(playerid,COLOR_GREY,"Syntax: /deposit [Amount]");
  210.                 else if(bank <= 0) return SendClientMessage(playerid,COLOR_GREY,"The minimun amount is 1$ !");
  211.                 else if(PlayerInfo[playerid][Cash] < bank) return SendClientMessage(playerid,COLOR_GREY,"You don't have enough money !");
  212.                 else
  213.                 {
  214.                     GetPlayerName(playerid,name,sizeof(name));
  215.                     PlayerInfo[playerid][Bcash] += bank;
  216.                     PlayerInfo[playerid][Cash] -= bank;
  217.                     cash = GetPlayerMoney(playerid);
  218.                     ResetPlayerMoney(playerid);
  219.                     GivePlayerMoney(playerid, cash-bank);
  220.                     format(string,sizeof(string),"[Info]:{FFFFFF} You have put in your bank account {FFFF00}%d{009900}${FFFFFF}.",bank);
  221.                     SendClientMessage(playerid,COLOR_YELLOW,string);
  222.                 }
  223.             }
  224.             else{SendClientMessage(playerid,COLOR_GREY,"First request permission to withdraw money from bank account desk office by typing your bank password !");}
  225.         }
  226.         else{SendClientMessage(playerid,COLOR_GREY,"You must be inside the bank at deposit desk office !");}
  227.     }
  228.     else{SendClientMessage(playerid,COLOR_GREY,"You don't have a bank account !");SendClientMessage(playerid,COLOR_GREY,"Go to {ffff00}Los Santos Central Bank{B5B1B0} and create one.");}
  229.     return 1;
  230. }
  231. CMD:bankaccount(playerid,params[])
  232. {
  233.     if(IsPlayerInRangeOfPoint(playerid,5.0,2309.0051,-2.3579,26.7422))
  234.     {
  235.         if(PlayerInfo[playerid][BankAcc] == 0)
  236.         {
  237.             ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Bank Account","Create your bank account by typing a password, and don't forget your password !","Create","Cancel");
  238.         }
  239.         else if(PlayerInfo[playerid][BankAcc] == 1)
  240.         {
  241.             ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Bank Account","Please type your bank account password","Login","Cancel");
  242.         }
  243.     }
  244.     else{SendClientMessage(playerid,COLOR_GREY,"You must be inside the bank at {ffff00}bank account desk office{B5B1B0} !");}
  245.     return 1;
  246. }
  247. CMD:balance(playerid,params[])
  248. {
  249.     new string[128];
  250.     if(IsPlayerInRangeOfPoint(playerid,5.0,2308.8706,-13.2487,26.7422))
  251.     {
  252.         if(PlayerInfo[playerid][BankOpen] == 1)
  253.         {
  254.             SendClientMessage(playerid,COLOR_YELLOW,"|__________[Account Info]__________|");
  255.             format(string,sizeof(string),"Money: {ffff00}%d{009900}$",PlayerInfo[playerid][Bcash]);
  256.             SendClientMessage(playerid,COLOR_WHITE,string);
  257.         }
  258.         else{SendClientMessage(playerid,COLOR_GREY,"First request permission to check your account from {ffff00}bank account desk office{B5B1B0} by typing your bank {ffff00}password{B5B1B0} !");}
  259.     }
  260.     else{SendClientMessage(playerid,COLOR_GREY,"You must be inside the bank at {ffff00}balance computer{B5B1B0} !");}
  261.     return 1;
  262. }
  263. CMD:card(playerid,params[])
  264. {
  265.     if(IsPlayerInRangeOfPoint(playerid,5.0,2309.1914,-8.4871,26.7422))
  266.     {
  267.         if(PlayerInfo[playerid][BankAcc] == 1)
  268.         {
  269.             if(PlayerInfo[playerid][Card] == 0)
  270.             {
  271.                 ShowPlayerDialog(playerid,6,DIALOG_STYLE_LIST,"Bank Account [Card]]","|-----------------------------------[How do you will pay ?]-----------------------------------|\nBy cash\nBy bank account","Select","Cancel");
  272.             }
  273.             else{SendClientMessage(playerid,COLOR_GREY,"You already have the card !");}
  274.         }
  275.         else{SendClientMessage(playerid,COLOR_GREY,"You don't have a bank account !");}
  276.     }
  277.     else{SendClientMessage(playerid,COLOR_GREY,"You must be inside the bank at {ffff00}card desk office{b5b1b0} !");}
  278.     return 1;
  279. }
Add Comment
Please, Sign In to add comment