Guest User

trablonBANK

a guest
Jun 27th, 2018
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // trablon's Realistic Bank System
  4. // Coder: trablon(Onur YAKAVETTA)
  5. // Tester: TaMSaH , razol , Woods
  6. //
  7. //
  8. //
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //=====================================================================[include]
  12. #include <a_samp>
  13. #include <file>
  14. #include <zcmd>
  15. #include <sscanf2>
  16.  
  17. #define Scripter "trablon"
  18. #define ScriptVersion "ALPHA(0.1)"
  19.  
  20. #define function%0(%1) forward%0(%1); \
  21. public%0(%1)
  22.  
  23. new AccBalance[MAX_PLAYERS];
  24. new AccNumber[MAX_PLAYERS];
  25. //==============================================================================
  26. public OnPlayerConnect(playerid)
  27. {
  28. ReadBankAccounts(playerid);
  29. return 1;
  30. }
  31.  
  32. public OnPlayerUpdate(playerid)
  33. {
  34. return 1;
  35. }
  36. //==============================================================================
  37. #if defined _ALS_OnPlayerConnect
  38. #undef OnPlayerConnect
  39. #else
  40. #define _ALS_OnPlayerConnect
  41. #endif
  42.  
  43. #define OnPlayerConnect FC_OnPlayerConnect
  44.  
  45.  
  46.  
  47. #if defined _ALS_OnPlayerUpdate
  48. #undef OnPlayerUpdate
  49. #else
  50. #define _ALS_OnPlayerUpdate
  51. #endif
  52.  
  53. #define OnPlayerUpdate FC_OnPlayerUpdate
  54. //=======================================================================[zcmd]
  55. CMD:openaccount(playerid, params[])
  56. {
  57. if(AccNumber[playerid] > 0) return SendClientMessage(playerid,0xFF0000FF,"* You already have a bank account.");
  58. new accnumber = 10000 + random(99999),str[128];
  59. CreateBankAccount(Isim(playerid), accnumber, 0);
  60. format(str,sizeof(str),"* Your account has been created. ( Account Number: %i , Balance: 0$ )",accnumber);
  61. SendClientMessage(playerid,0x00FF00FF,str);
  62. SendClientMessage(playerid,-1,"INFO: You can view your bank setting by writing '/bank' command.");
  63. return 1;
  64. }
  65. CMD:bank(playerid,params[])
  66. {
  67. if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
  68. new str[128];
  69. format(str,sizeof(str),"* Your account has been created. ( Account Number: %i , Balance: %i$ )",AccNumber[playerid],AccBalance[playerid]);
  70. SendClientMessage(playerid,0x00FF00FF,str);
  71. SendClientMessage(playerid,-1,"INFO: You can send money to other player's account by writing their account number.(/transfer)");
  72. return 1;
  73. }
  74. CMD:transfer(playerid,params[])
  75. {
  76. new number,amm;
  77. if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
  78. if(sscanf(params, "dd",number,amm)) return SendClientMessage(playerid, -1, "* /transfer [Bank Account Number] [Amount]");
  79. if(amm < 1 || amm > 10000) return SendClientMessage(playerid,0xFF0000FF,"* Enter number between 1 and 10000$.");
  80. if(AccBalance[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have enough cash in your bank account.");
  81. for(new i=0; i<MAX_PLAYERS; i++)
  82. {
  83. if(number == AccNumber[i])
  84. {
  85. AccBalance[playerid] -= amm;
  86. AccBalance[i] += amm;
  87. SendClientMessage(i,0x00FF00FF,"* Someone transfared money into your bank account.");
  88. }
  89. }
  90. SendClientMessage(playerid,0x00FF00FF,"* You have transfered your money to player's account.");
  91. return 1;
  92. }
  93. CMD:deposit(playerid,params[])
  94. {
  95. new amm;
  96. if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
  97. if(sscanf(params, "d",amm)) return SendClientMessage(playerid, -1, "* /deposit [Amount]");
  98. if(amm < 1 || amm > 10000) return SendClientMessage(playerid,0xFF0000FF,"* Enter number between 1 and 10000$.");
  99. if(GetPlayerMoney(playerid) == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have enough cash.");
  100. GivePlayerMoney(playerid,-amm);
  101. AccBalance[playerid] += amm;
  102. SendClientMessage(playerid,0x00FF00FF,"* You have deposited your cash.(To check your balance, /bank)");
  103. return 1;
  104. }
  105. CMD:withdraw(playerid,params[])
  106. {
  107. new amm;
  108. if(AccNumber[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have bank account.");
  109. if(sscanf(params, "d",amm)) return SendClientMessage(playerid, -1, "* /withdraw [Amount]");
  110. if(amm < 1 || amm > 10000) return SendClientMessage(playerid,0xFF0000FF,"* Enter number between 1 and 10000$.");
  111. if(AccBalance[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"* You do not have enough cash.");
  112. GivePlayerMoney(playerid,amm);
  113. AccBalance[playerid] -= amm;
  114. SendClientMessage(playerid,0x00FF00FF,"* You have withdrawn your cash.(To check your balance, /bank)");
  115. return 1;
  116. }
  117. //=======================================================================[stock]
  118. function fcreate(filename[])
  119. {
  120. if (fexist(filename)){return false;}
  121. new File:fhandle = fopen(filename,io_write);
  122. fclose(fhandle);
  123. return true;
  124. }
  125. function CreateBankAccount(playername[],accnumber, balance)
  126. {
  127. new string[128];
  128. new File:p0s=fopen("BankAccounts.cfg", io_append);
  129. if(!p0s)
  130. {
  131. fcreate("BankAccounts.cfg");
  132. }
  133. format(string, 256, "%s, %i, %i\n\r", playername, accnumber, balance);
  134. fwrite(p0s,string);
  135. fclose(p0s);
  136. return 1;
  137. }
  138. function ReadBankAccounts(playerid)
  139. {
  140. new File:p0s=fopen("BankAccounts.cfg", io_read);
  141. new string[128];
  142. while(fread(p0s, string))
  143. {
  144. if(strcmp(string, Isim(playerid), false, strlen(Isim(playerid)))==0)
  145. {
  146. AccNumber[playerid]=GetVal(1, string);
  147. AccBalance[playerid]=GetVal(2, string);
  148. }
  149. }
  150. fclose(p0s);
  151. return 1;
  152. }
  153. GetVal(numb, str[]) {
  154. new tmp[256], idx;
  155. for(new i=0; i<numb; i++)
  156. {
  157. tmp=strtok(str, idx);
  158. }
  159. return strval(tmp);
  160. }
  161. strtok(const string[], &index)
  162. {
  163. new length = strlen(string);
  164. while ((index < length) && (string[index] <= ' '))
  165. {
  166. index++;
  167. }
  168.  
  169. new offset = index;
  170. new result[20];
  171. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  172. {
  173. result[index - offset] = string[index];
  174. index++;
  175. }
  176. result[index - offset] = EOS;
  177. return result;
  178. }
  179. stock Isim(playerid)
  180. {
  181. new isimm[MAX_PLAYER_NAME];
  182. GetPlayerName(playerid,isimm,MAX_PLAYER_NAME);
  183. return isimm;
  184. }
  185. //=====================================================================[forward]
  186. forward OnPlayerConnect(playerid);
  187. forward OnPlayerUpdate(playerid);
  188. // =========== [ END ] ============== //
Add Comment
Please, Sign In to add comment