Guest User

HKBank

a guest
Oct 27th, 2012
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.85 KB | None | 0 0
  1. /*
  2. HKBank - An advanced bank system which uses Dialogs and Clickable Textdraws.
  3.  
  4. Credits - [HK]Ryder[AN]
  5.           Y_Less
  6.           ZeeX
  7.           iPLEOMAX
  8. */
  9. #include <a_samp>
  10. #include <YSI\y_ini>
  11. #include <zcmd>
  12. //Textdraws
  13. new PlayerText:Textdraw0[MAX_PLAYERS];
  14. new PlayerText:Textdraw1[MAX_PLAYERS];
  15. new PlayerText:Textdraw2[MAX_PLAYERS];
  16. //Defines
  17. #define PATH "HKBank/%s.ini"
  18. #define DIALOG_LOGIN 998
  19. #define DIALOG_REGISTER 999
  20. #define DIALOG_MAIN 1000
  21. #define DIALOG_WITHDRAW 1001
  22. #define DIALOG_DEPOSIT 1002
  23. #define DIALOG_STATS 1003
  24. //Whirlpool
  25. native WP_Hash(buf[], len, const str[]);
  26. //Player Bank Info
  27. enum bInfo {
  28.     bPass[129],
  29.     bWealth,
  30. }
  31. new BankInfo[MAX_PLAYERS][bInfo];
  32. public OnFilterScriptInit()
  33. {
  34.     return 1;
  35. }
  36.  
  37. public OnFilterScriptExit()
  38. {
  39.     return 1;
  40. }
  41. public OnPlayerConnect(playerid)
  42. {
  43.     Textdraw0[playerid] = CreatePlayerTextDraw(playerid, 403.600006, 148.593338, "usebox");
  44.     PlayerTextDrawLetterSize(playerid, Textdraw0[playerid], 0.000000, 13.952963);
  45.     PlayerTextDrawTextSize(playerid, Textdraw0[playerid], 228.400009, 0.000000);
  46.     PlayerTextDrawAlignment(playerid, Textdraw0[playerid], 1);
  47.     PlayerTextDrawColor(playerid, Textdraw0[playerid], 0);
  48.     PlayerTextDrawUseBox(playerid, Textdraw0[playerid], true);
  49.     PlayerTextDrawBoxColor(playerid, Textdraw0[playerid], 102);
  50.     PlayerTextDrawSetShadow(playerid, Textdraw0[playerid], 0);
  51.     PlayerTextDrawSetOutline(playerid, Textdraw0[playerid], 0);
  52.     PlayerTextDrawFont(playerid, Textdraw0[playerid], 0);
  53.    
  54.     Textdraw1[playerid] = CreatePlayerTextDraw(playerid, 240.000015, 167.253311, "Create a New Account");
  55.     PlayerTextDrawLetterSize(playerid, Textdraw1[playerid], 0.289999, 1.622400);
  56.     PlayerTextDrawAlignment(playerid, Textdraw1[playerid], 1);
  57.     PlayerTextDrawColor(playerid, Textdraw1[playerid], -1);
  58.     PlayerTextDrawSetShadow(playerid, Textdraw1[playerid], 0);
  59.     PlayerTextDrawSetOutline(playerid, Textdraw1[playerid], 1);
  60.     PlayerTextDrawBackgroundColor(playerid, Textdraw1[playerid], 51);
  61.     PlayerTextDrawFont(playerid, Textdraw1[playerid], 2);
  62.     PlayerTextDrawSetProportional(playerid, Textdraw1[playerid], 1);
  63.     PlayerTextDrawSetSelectable(playerid, Textdraw1[playerid], true);
  64.    
  65.     Textdraw2[playerid] = CreatePlayerTextDraw(playerid, 233.599975, 218.026733, "Login to an Existing Account");
  66.     PlayerTextDrawLetterSize(playerid, Textdraw2[playerid], 0.245199, 1.719465);
  67.     PlayerTextDrawAlignment(playerid, Textdraw2[playerid], 1);
  68.     PlayerTextDrawColor(playerid, Textdraw2[playerid], -1);
  69.     PlayerTextDrawSetShadow(playerid, Textdraw2[playerid], 0);
  70.     PlayerTextDrawSetOutline(playerid, Textdraw2[playerid], 1);
  71.     PlayerTextDrawBackgroundColor(playerid, Textdraw2[playerid], 51);
  72.     PlayerTextDrawFont(playerid, Textdraw2[playerid], 2);
  73.     PlayerTextDrawSetProportional(playerid, Textdraw2[playerid], 1);
  74.     PlayerTextDrawSetSelectable(playerid, Textdraw2[playerid], true);
  75.    
  76.     if(!fexist(pBankAccount(playerid)))
  77.     {
  78.         SendClientMessage(playerid, -1, "You don't have a bank account yet. Please use /bank to register one");
  79.     }
  80.     else if(fexist(pBankAccount(playerid)))
  81.     {
  82.         INI_ParseFile(pBankAccount(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  83.     }
  84.     return 1;
  85. }
  86. CMD:bank(playerid, params[])
  87. {
  88.     PlayerTextDrawShow(playerid, Textdraw0[playerid]);
  89.     PlayerTextDrawShow(playerid, Textdraw1[playerid]);
  90.     PlayerTextDrawShow(playerid, Textdraw2[playerid]);
  91.     SelectTextDraw(playerid, 0x00FF00FF);
  92.     return 1;
  93. }
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96.     if(fexist(pBankAccount(playerid)))
  97.     {
  98.         new INI:file = INI_Open(pBankAccount(playerid));
  99.         INI_WriteInt(file, "BankCash", BankInfo[playerid][bWealth]);
  100.         INI_Close(file);
  101.     }
  102.     return 1;
  103. }
  104. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  105. {
  106.     if(dialogid == DIALOG_REGISTER)
  107.     {
  108.         if(!response)
  109.         {
  110.             SendClientMessage(playerid, -1, "You cancelled bank registration");
  111.         }
  112.         else
  113.         {
  114.             if(!fexist(pBankAccount(playerid)))
  115.             {
  116.                 if(strlen(inputtext) < 4) return SendClientMessage(playerid, -1, "Your password must be atleast 4 characters");
  117.                 new Hash[129], PassString[128];
  118.                 new INI:file = INI_Open(pBankAccount(playerid));
  119.                 WP_Hash(Hash, sizeof(Hash), inputtext);
  120.                 INI_WriteString(file, "BankPassword", Hash);
  121.                 INI_WriteInt(file, "BankCash", 0);
  122.                 INI_Close(file);
  123.                 INI_ParseFile(pBankAccount(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  124.                 format(PassString, sizeof(PassString), "Thank You For Registering. You bank password is %s", inputtext);
  125.                 SendClientMessage(playerid, -1, PassString);
  126.                 ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, "HKBank", "Withdraw\nDeposit\nStats", "Ok", "Cancel");
  127.             }
  128.             else
  129.             {
  130.                 SendClientMessage(playerid, -1, "You already have a bank account");
  131.                 return 0;
  132.             }
  133.         }
  134.     }
  135.     if(dialogid == DIALOG_LOGIN)
  136.     {
  137.         if(!response)
  138.         {
  139.             SendClientMessage(playerid, -1, "You cancelled the option");
  140.         }
  141.         else
  142.         {
  143.             if(!fexist(pBankAccount(playerid)))
  144.             {
  145.                 SendClientMessage(playerid, -1, "You don't have a bank account");
  146.             }
  147.             else
  148.             {
  149.                 if(!strcmp(inputtext, BankInfo[playerid][bPass], true))
  150.                 {
  151.                     ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, "HKBank", "Withdraw\nDeposit\nStats", "Ok", "Cancel");
  152.                 }
  153.                 else
  154.                 {
  155.                     SendClientMessage(playerid, -1, "Wrong Password. Please try again.");
  156.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "HKBank", "Please type your password to login into your bank account", "Login", "Cancel");
  157.                 }
  158.             }
  159.         }
  160.     }
  161.     if(dialogid == DIALOG_MAIN)
  162.     {
  163.         if(!response)
  164.         {
  165.             SendClientMessage(playerid, -1, "You cancelled the selection");
  166.         }
  167.         else
  168.         {
  169.             if(listitem == 0)
  170.             {
  171.                 ShowPlayerDialog(playerid, DIALOG_WITHDRAW, DIALOG_STYLE_INPUT, "HKBank", "Enter the amount of money you want to withdraw", "OK", "Cancel");
  172.             }
  173.             if(listitem == 1)
  174.             {
  175.                 ShowPlayerDialog(playerid, DIALOG_DEPOSIT, DIALOG_STYLE_INPUT, "HKBank", "Enter the amount of money you want to deposit", "OK", "Cancel");
  176.             }
  177.             if(listitem == 2)
  178.             {
  179.                 new string[128];
  180.                 format(string, sizeof(string), "You Have $%i on your account", BankInfo[playerid][bWealth]);
  181.                 ShowPlayerDialog(playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "HKBank", string, "OK", "");
  182.             }
  183.         }
  184.     }
  185.     if(dialogid == DIALOG_WITHDRAW)
  186.     {
  187.         if(!response)
  188.         {
  189.             SendClientMessage(playerid, -1, "You cancelled the selection");
  190.             ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, "HKBank", "Withdraw\nDeposit\nStats", "Ok", "Cancel");
  191.         }
  192.         else
  193.         {
  194.             if(!isnumeric(inputtext)) return SendClientMessage(playerid, -1, "Please enter a valid amount");
  195.             if(strval(inputtext) > BankInfo[playerid][bWealth]) return SendClientMessage(playerid, -1, "You dont have that much money in your bank account");
  196.             BankInfo[playerid][bWealth] = (BankInfo[playerid][bWealth] - strval(inputtext));
  197.             GivePlayerMoney(playerid, strval(inputtext));
  198.             new String[128];
  199.             format( String, sizeof String, "You withdrew $%i from your bank", strval(inputtext));
  200.             SendClientMessage(playerid, -1, String);
  201.             ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, "HKBank", "Withdraw\nDeposit\nStats", "Ok", "Cancel");
  202.         }
  203.     }
  204.     if(dialogid == DIALOG_DEPOSIT)
  205.     {
  206.         if(!response)
  207.         {
  208.             SendClientMessage(playerid, -1, "You cancelled the selection");
  209.             ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, "HKBank", "Withdraw\nDeposit\nStats", "Ok", "Cancel");
  210.         }
  211.         else
  212.         {
  213.             if(!isnumeric(inputtext)) return SendClientMessage(playerid, -1, "Please enter a valid amount");
  214.             if(GetPlayerMoney(playerid) < strval(inputtext)) return SendClientMessage(playerid, -1, "You don't have that much money");
  215.             BankInfo[playerid][bWealth] = (BankInfo[playerid][bWealth] + strval(inputtext));
  216.             GivePlayerMoney(playerid, -strval(inputtext));
  217.             new string[128];
  218.             format(string, sizeof(string), "You deposited $%i to your bank account", strval(inputtext));
  219.             SendClientMessage(playerid, -1, string);
  220.             ShowPlayerDialog(playerid, DIALOG_MAIN, DIALOG_STYLE_LIST, "HKBank", "Withdraw\nDeposit\nStats", "Ok", "Cancel");
  221.         }
  222.     }
  223.     return 1;
  224. }
  225. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  226. {
  227.     if(playertextid == Textdraw1[playerid])
  228.     {
  229.         if(!fexist(pBankAccount(playerid)))
  230.         {
  231.             ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "HKBank", "Enter a password to register your bank account", "Enter", "Cancel");
  232.             PlayerTextDrawHide(playerid, Textdraw0[playerid]);
  233.             PlayerTextDrawHide(playerid, Textdraw1[playerid]);
  234.             PlayerTextDrawHide(playerid, Textdraw2[playerid]);
  235.             CancelSelectTextDraw(playerid);
  236.         }
  237.         else if(fexist(pBankAccount(playerid)))
  238.         {
  239.             SendClientMessage(playerid, -1, "You already have a bank account.");
  240.  
  241.         }
  242.     }
  243.     if(playertextid == Textdraw2[playerid])
  244.     {
  245.         if(fexist(pBankAccount(playerid)))
  246.         {
  247.             ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "HKBank", "Please type your password to login into your bank account", "Login", "Cancel");
  248.             PlayerTextDrawHide(playerid, Textdraw0[playerid]);
  249.             PlayerTextDrawHide(playerid, Textdraw1[playerid]);
  250.             PlayerTextDrawHide(playerid, Textdraw2[playerid]);
  251.             CancelSelectTextDraw(playerid);
  252.         }
  253.         else if(!fexist(pBankAccount(playerid)))
  254.         {
  255.             SendClientMessage(playerid, -1, "You don't have a bank account. Please register first");
  256.  
  257.         }
  258.     }
  259.     return 1;
  260. }
  261. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  262. {
  263.     return 1;
  264. }
  265. //Loaduser Public
  266. forward LoadUser_data(playerid, name[], value[]);
  267. public LoadUser_data(playerid, name[], value[])
  268. {
  269.     INI_Int("BankCash", BankInfo[playerid][bWealth]);
  270.     INI_String("BankPassword", BankInfo[playerid][bPass], 129);
  271.     return 1;
  272. }
  273. //Stocks
  274. stock pBankAccount(playerid)
  275. {
  276.     new string[50];
  277.     format(string, sizeof(string), PATH, GetName(playerid));
  278.     return string;
  279. }
  280.  
  281. stock GetName(playerid)
  282. {
  283.     new name[24];
  284.     GetPlayerName(playerid, name, sizeof(name));
  285.     return name;
  286. }
Add Comment
Please, Sign In to add comment