Emistry

[RO] SQL Bank

May 20th, 2018
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. // https://rathena.org/board/topic/115606-zeny-in-separate-table/
  2.  
  3. /*
  4. CREATE TABLE IF NOT EXISTS `e_bank` (
  5. `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  6. `aid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  7. `bank_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  8. `zeny` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
  9. `daily_deposit` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  10. `daily_withdraw` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  11. PRIMARY KEY (`id`),
  12. KEY `aid` (`aid`)
  13. ) ENGINE=InnoDB;
  14. */
  15.  
  16.  
  17. prontera,155,181,5 script Sample 4_F_KAFRA1,{
  18. doevent "bank_main::OnTalk";
  19. }
  20.  
  21. - script bank_main -1,{
  22. function func_SetupBank;
  23.  
  24. OnInit:
  25. // func_SetupBank(<id>, "<name>", <cost>, <deposit_limit>, <withdraw_limit>);
  26. func_SetupBank(1, "Basic Account", 1000000, 100000000, 10000000);
  27. func_SetupBank(2, "Premium Account", 5000000, 1000000000, 100000000);
  28. // func_SetupBank(3, "Wicked Account", 10000000, 5000000000, 1000000000); // by default emulator only can hold 2.1b integer
  29. end;
  30.  
  31. OnTalk:
  32. .@aid = getcharid(3);
  33. query_sql("SELECT `id`,`bank_id`,`daily_deposit`,`daily_withdraw`,`zeny` FROM `e_bank` WHERE `aid` = "+.@aid+" LIMIT 1", .@id, .@bank_id, .@daily_deposit, .@daily_withdraw, .@total_zeny$);
  34.  
  35. if (.@id > 0 && .@bank_id > 0) {
  36. mes "^0055FF" + .bank_name$[.@i]+"^000000";
  37. mes "Total Zeny: " + F_InsertComma(.@total_zeny$)+" z";
  38. mes "Daily deposit limit:";
  39. mes F_InsertComma(.@daily_deposit) + " / " + F_InsertComma(.bank_limit_deposit[.@bank_id - 1])+" z";
  40. mes "Daily withdraw limit:";
  41. mes F_InsertComma(.@daily_withdraw) + " / " + F_InsertComma(.bank_limit_withdraw[.@bank_id - 1])+" z";
  42. next;
  43. switch (select(
  44. "Deposit Zeny",
  45. "Withdraw Zeny",
  46. "^FF0000Cancel Account^000000"
  47. )) {
  48. case 1:
  49. .@max_amount = (.bank_limit_deposit[.@bank_id - 1] - .@daily_deposit);
  50. if (.@max_amount > Zeny)
  51. .@max_amount = Zeny;
  52. mes "How many Zeny will be deposit into the account? (max: "+F_InsertComma(.@max_amount)+"z)";
  53. input .@amount, 0, .@max_amount;
  54. if (.@amount > 0) {
  55. Zeny -= .@amount;
  56. query_sql("UPDATE `e_bank` SET `zeny` = `zeny` + "+.@amount+", `daily_deposit` = `daily_deposit` + "+.@amount+" WHERE `aid` = "+.@aid+" LIMIT 1");
  57. mes "You have deposit "+F_InsertComma(.@amount)+" Zeny into the Bank.";
  58. }
  59. break;
  60. case 2:
  61. .@max_amount = (.bank_limit_withdraw[.@bank_id - 1] - .@daily_withdraw);
  62. if (.@max_amount > (MAX_ZENY - Zeny))
  63. .@max_amount = (MAX_ZENY - Zeny);
  64. mes "How many Zeny will be withdraw into the account? (max: "+F_InsertComma(.@max_amount)+"z)";
  65. input .@amount, 0, .@max_amount;
  66. if (.@amount > 0) {
  67. Zeny += .@amount;
  68. query_sql("UPDATE `e_bank` SET `zeny` = `zeny` - "+.@amount+", `daily_withdraw` = `daily_withdraw` + "+.@amount+" WHERE `aid` = "+.@aid+" LIMIT 1");
  69. mes "You have withdraw "+F_InsertComma(.@amount)+" Zeny from the Bank.";
  70. }
  71. break;
  72. case 3:
  73. if (.@total_zeny$ != "0") {
  74. mes "You need to withdraw all the remaining "+F_InsertComma(.@total_zeny$)+" zeny before you can cancel your account.";
  75. }
  76. else {
  77. query_sql("DELETE FROM `e_bank` WHERE `aid` = "+.@aid+" LIMIT 1");
  78. mes "Your bank account has been cancelled.";
  79. }
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. else {
  86. mes "You didnt have a bank account yet.";
  87. next;
  88. if (select("Create a Bank?", "Cancel") == 1) {
  89. mes "Pick a bank type...";
  90. for (.@i = 0; .@i < .bank_size; .@i++) {
  91. mes " ";
  92. mes "^0055FF" + .bank_name$[.@i]+"^000000";
  93. mes "Daily deposit limit:";
  94. mes F_InsertComma(.bank_limit_deposit[.@i])+" z";
  95. mes "Daily withdraw limit:";
  96. mes F_InsertComma(.bank_limit_withdraw[.@i])+" z";
  97. mes "Cost: " + F_InsertComma(.bank_cost[.@i])+" z";
  98. .@menu$ = .@menu$ + .bank_name$[.@i] + ":";
  99. }
  100. next;
  101. .@i = select(.@menu$) - 1;
  102. if (Zeny < .bank_cost[.@i]) {
  103. mes "You dont have enough zeny to purchase this bank type.";
  104. }
  105. else {
  106. Zeny -= .bank_cost[.@i];
  107. query_sql("INSERT INTO `e_bank` (`aid`,`bank_id`) VALUES ("+.@aid+", "+.bank_id[.@i]+")");
  108. mes "You have successfully purchased this bank type.";
  109. }
  110. }
  111. }
  112. close;
  113.  
  114. OnHour00:
  115. query_sql("UPDATE `e_bank` SET `daily_deposit` = 0, `daily_withdraw` = 0");
  116. end;
  117.  
  118. function func_SetupBank {
  119. .@id = getarg(0, 0);
  120. .@name$ = getarg(1, "");
  121. .@cost = getarg(2, MAX_ZENY);
  122. .@limit_deposit = getarg(3, MAX_ZENY);
  123. .@limit_withdraw = getarg(4, MAX_ZENY);
  124.  
  125. if (.@id > 0 && .@name$ != "") {
  126. .bank_id[.bank_size] = .@id;
  127. .bank_name$[.bank_size] = .@name$;
  128. .bank_cost[.bank_size] = .@cost;
  129. .bank_limit_deposit[.bank_size] = .@limit_deposit;
  130. .bank_limit_withdraw[.bank_size] = .@limit_withdraw;
  131. .bank_size++;
  132. }
  133. return;
  134. }
  135.  
  136. }
Add Comment
Please, Sign In to add comment