Guest User

Bert

a guest
Sep 2nd, 2008
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini> //http://www.dracoblue.net/download.php?ID=35&URL=http://www.dracoblue.net/Downloads/Dini_1_5_1.zip
  3. #include <dudb> //http://www.dracoblue.net/download.php?ID=31&URL=http://www.dracoblue.net/Downloads/DUDB_2_4.zip
  4.  
  5. /*--------------------[ Credits ]---------------------------------
  6.  
  7. Thanks to Bert for programming the loan system, ty to Paul
  8. for the spelling mistakes he found
  9.  
  10. ----------------------------------------------------------------*/
  11.  
  12. new Loaned[MAX_PLAYERS];
  13. new BankString[128];
  14.  
  15. //COLOR defines
  16. #define COLOR_RED 0xAA3333AA
  17. #define COLOR_YELLOW 0xFFFF00AA
  18. #define COLOR_GREEN 0x33AA33AA
  19.  
  20. public OnFilterScriptInit()
  21. {
  22. SetTimer("LoanPayOff", 300000, 1);
  23. return 1;
  24. }
  25.  
  26. public OnPlayerConnect(playerid)
  27. {
  28. SetTimer("LoanPayOff", 5000, 1);
  29. new PlayerName[24];
  30. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  31. if(dini_Exists(udb_encode(PlayerName)))
  32. {
  33. Loaned[playerid] = dini_Int(udb_encode(PlayerName), "Loaned");
  34. GivePlayerMoney(playerid, Loaned[playerid]);
  35. if(Loaned[playerid] == 0)
  36. {
  37. SendClientMessage(playerid, COLOR_GREEN, "You dont have a loan yet, the bank wishes you a good day!");
  38. }
  39. else
  40. {
  41. format(BankString, sizeof(BankString), "You still have a loan of %d$, the bank requests you to pay!", Loaned[playerid]);
  42. SendClientMessage(playerid, COLOR_RED, BankString);
  43. }
  44. }
  45. return 1;
  46. }
  47.  
  48. public OnPlayerDisconnect(playerid)
  49. {
  50. new PlayerName[24];
  51. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  52. dini_IntSet(udb_encode(PlayerName), "Loaned", Loaned[playerid]);
  53. }
  54.  
  55. forward LoanPayOff();
  56. public LoanPayOff()
  57. {
  58. for(new i = 0; i < MAX_PLAYERS; i ++)
  59. {
  60. if(Loaned[i] > 0)
  61. {
  62. new thing = random(5);
  63. if(thing == 1)
  64. {
  65. new amount = Loaned[i]/7;
  66. format(BankString, sizeof(BankString), "The bank doesn't want to wait anymore, it took %d$ of your loan back", amount);
  67. SendClientMessage(i, COLOR_RED, BankString);
  68. format(BankString, sizeof(BankString), "~r~Loan -%d$", amount);
  69. GameTextForPlayer(i, BankString, 3000, 1);
  70. GivePlayerMoney(i, -amount);
  71. Loaned[i] -= amount;
  72. }
  73. else
  74. {
  75. SendClientMessage(i, 0xFFFFFF, "The bank asks you to pay off your loan!");
  76. }
  77. }
  78. }
  79. }
  80.  
  81. public OnPlayerCommandText(playerid, cmdtext[])
  82. {
  83. new cmd[256], idx;
  84. cmd = strtok(cmdtext, idx);
  85.  
  86. if (strcmp("/loanamount", cmdtext, true, 11) == 0)
  87. {
  88. format(BankString, sizeof(BankString), "The amount of your loan currently is: %d$", Loaned[playerid]);
  89. SendClientMessage(playerid, COLOR_YELLOW, BankString);
  90. return 1;
  91. }
  92. if (strcmp("/loan", cmdtext, true, 5) == 0)
  93. {
  94. new tmp[255];
  95. tmp = strtok(cmdtext, idx);
  96. new amount = strval(tmp);
  97. if(!amount)
  98. {
  99. SendClientMessage(playerid, COLOR_RED, "Invalid transaction amount");
  100. return 1;
  101. }
  102. else if(Loaned[playerid] > 0)
  103. {
  104. format(BankString, sizeof(BankString), "You already have a loan of: %d$", Loaned[playerid]);
  105. SendClientMessage(playerid, COLOR_RED , BankString);
  106. }
  107. else
  108. {
  109. SendClientMessage(playerid, COLOR_GREEN , "You succesfully took a loan, use /loanamount to see how much you have borrowed and /payoff to payoff");
  110. format(BankString, sizeof(BankString), "~y~Loan %d$", amount);
  111. GameTextForPlayer(playerid, BankString, 3000, 1);
  112. GivePlayerMoney(playerid, amount);
  113. Loaned[playerid] = amount;
  114. }
  115. return 1;
  116. }
  117. if (strcmp("/payoff", cmdtext, true, 5) == 0)
  118. {
  119. new tmp[255];
  120. tmp = strtok(cmdtext, idx);
  121. new amount = strval(tmp);
  122. if(!amount)
  123. {
  124. SendClientMessage(playerid, COLOR_RED, "Invalid transaction amount");
  125. return 1;
  126. }
  127. else if(amount > Loaned[playerid])
  128. {
  129. format(BankString, sizeof(BankString), "You cant payoff more then your max loan, which is %d$", Loaned[playerid]);
  130. SendClientMessage(playerid, COLOR_RED , BankString);
  131. }
  132. else if(amount < GetPlayerMoney(playerid))
  133. {
  134. format(BankString, sizeof(BankString), "You succesfully paid off %d$, your new loan is %d$", amount, Loaned[playerid]-amount);
  135. SendClientMessage(playerid, COLOR_YELLOW , BankString);
  136. format(BankString, sizeof(BankString), "~r~-Loan %d$", amount);
  137. GameTextForPlayer(playerid, BankString, 3000, 1);
  138. GivePlayerMoney(playerid, -amount);
  139. Loaned[playerid] = Loaned[playerid]-amount;
  140. if(Loaned[playerid] == 0)
  141. {
  142. SendClientMessage(playerid, COLOR_GREEN , "The bank thanks you for paying back all of your loan");
  143. }
  144. }
  145. else
  146. {
  147. SendClientMessage(playerid, COLOR_RED , "You cant pay off more then you have in your pocket");
  148. }
  149. return 1;
  150. }
  151. return 0;
  152. }
  153.  
  154. /*--------------------[ Strtok ]-----------------------------------------
  155. strtok(const string[], &index)
  156. {
  157. new length = strlen(string);
  158. while ((index < length) && (string[index] <= ' '))
  159. {
  160. index++;
  161. }
  162.  
  163. new offset = index;
  164. new result[20];
  165. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  166. {
  167. result[index - offset] = string[index];
  168. index++;
  169. }
  170. result[index - offset] = EOS;
  171. return result;
  172. }*/
Advertisement
Add Comment
Please, Sign In to add comment