Advertisement
AutismAlex

uBalance

Jan 6th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. startBalance = 0;
  2. currencyName = 0;
  3. zombieKillReward = 0;
  4. MegaZombieKillReward = 0;
  5. zombieKillRewardMessage = "Message Not Set!";
  6. MegaZombieKillRewardMessage = "Message Not Set!";
  7. PlayerNotSpecified = "Message Not Set!";
  8. PlayerNotFound = "Message Not Found!";
  9. AmountUnspecified = "Message Not Found!";
  10. NotEnoughBalance = "Message Not Found!";
  11. IncomingPayment = "Message Not Found!";
  12. OutgoingPayment = "Message Not Found!";
  13. PlayerCheckBalance = "Message Not Found!";
  14. IncreasedPlayersBalance = "Message Not Found!";
  15. DecreasedPlayersBalance = "Message Not Found!";
  16. ResetPlayersBalance = "Message Not Found!";
  17. event onLoad(){
  18. logger.log("uBalance Loaded!");
  19. file.write("../uBalance_configuration.txt","");
  20. if(file.read("../uBalance_configuration.txt") != ""){
  21. logger.log("uBalance Configuration Found!");
  22. }
  23. else{
  24. logger.log("uBalance Configuration Created!");
  25. file.writeAll("../uBalance_configuration.txt", "<startingBalance>0</startingBalance>\n<currencyName>Credits</currencyName>\n<zombieKillReward>15</zombieKillReward>\n<MegaZombieKillReward>50</MegaZombieKillReward>");
  26. }
  27. file.write("../uBalance_translations.txt","");
  28. if(file.read("../uBalance_translations.txt") != ""){
  29. logger.log("uBalance Translations Found!");
  30. }
  31. else{
  32. logger.log("uBalance Translations Created!");
  33. file.writeAll("../uBalance_translations.txt", "<zombieKillRewardMessage>You earned {0} for killing a zombie!</zombieKillRewardMessage>\n<MegaZombieKillRewardMessage>You earned {0} for killing a mega zombie!</MegaZombieKillRewardMessage>\n<PlayerNotSpecified>You must specify a player!</PlayerNotSpecified>\n<PlayerNotFound>Target player could not be found</PlayerNotFound>\n<AmountUnspecified>You must specify an amount!</AmountUnspecified>\n<NotEnoughBalance>You do not have that amount</NotEnoughBalance>\n<IncomingPayment>{0} paid you {1} {2}</IncomingPayment>\n<OutgoingPayment>You paid {0} {1} {2}</OutgoingPayment>\n<PlayerCheckBalance>You have {0} {1}</PlayerCheckBalance>\n<IncreasedPlayersBalance>Increased {0}'s balance by {1}</IncreasedPlayersBalance>\n<DecreasedPlayersBalance>Decreased {0}'s balancy by {1}</DecreasedPlayersBalance>\n<ResetPlayersBalance>{0}'s Balance Has Been Reset!</ResetPlayersBalance>");
  34. }
  35. // Translations
  36. translationFile = file.read("../uBalance_translations.txt").split("\n");
  37. zombieKillRewardMessage = translationFile[0].replace("<zombieKillRewardMessage>", "");
  38. zombieKillRewardMessage = zombieKillRewardMessage.replace("</zombieKillRewardMessage>", "");
  39. MegaZombieKillRewardMessage = translationFile[1].replace("<MegaZombieKillRewardMessage>", "");
  40. MegaZombieKillRewardMessage = MegaZombieKillRewardMessage.replace("</MegaZombieKillRewardMessage>", "");
  41. PlayerNotSpecified = translationFile[2].replace("<PlayerNotSpecified>", "");
  42. PlayerNotSpecified = PlayerNotSpecified.replace("</PlayerNotSpecified>", "");
  43. PlayerNotFound = translationFile[3].replace("<PlayerNotFound>", "");
  44. PlayerNotFound = PlayerNotFound.replace("</PlayerNotFound>", "");
  45. AmountUnspecified = translationFile[4].replace("<AmountUnspecified>", "");
  46. AmountUnspecified = AmountUnspecified.replace("</AmountUnspecified>", "");
  47. NotEnoughBalance = translationFile[5].replace("<NotEnoughBalance>", "");
  48. NotEnoughBalance = NotEnoughBalance.replace("</NotEnoughBalance>", "");
  49. IncomingPayment = translationFile[6].replace("<IncomingPayment>", "");
  50. IncomingPayment = IncomingPayment.replace("</IncomingPayment>", "");
  51. OutgoingPayment = translationFile[7].replace("<OutgoingPayment>", "");
  52. OutgoingPayment = OutgoingPayment.replace("</OutgoingPayment>", "");
  53. PlayerCheckBalance = translationFile[8].replace("<PlayerCheckBalance>", "");
  54. PlayerCheckBalance = PlayerCheckBalance.replace("</PlayerCheckBalance>", "");
  55. IncreasedPlayersBalance = translationFile[9].replace("<IncreasedPlayersBalance>", "");
  56. IncreasedPlayersBalance = IncreasedPlayersBalance.replace("</IncreasedPlayersBalance>", "");
  57. DecreasedPlayersBalance = translationFile[10].replace("<DecreasedPlayersBalance>", "");
  58. DecreasedPlayersBalance = DecreasedPlayersBalance.replace("</DecreasedPlayersBalance>", "");
  59. ResetPlayersBalance = translationFile[11].replace("<ResetPlayersBalance>", "");
  60. ResetPlayersBalance = ResetPlayersBalance.replace("</ResetPlayersBalance>", "");
  61. // Configuration
  62. configFile = file.read("../uBalance_configuration.txt").split("\n");
  63. startBalance = configFile[0].replace("<startingBalance>", "");
  64. startBalance = startBalance.replace("</startingBalance>", "");
  65. currencyName = configFile[1].replace("<currencyName>", "");
  66. currencyName = currencyName.replace("</currencyName>", "");
  67. zombieKillReward = configFile[2].replace("<zombieKillReward>", "");
  68. zombieKillReward = zombieKillReward.replace("</zombieKillReward>", "");
  69. database.execute("CREATE TABLE IF NOT EXISTS uBalance(
  70. id VARCHAR(17) PRIMARY KEY,
  71. balance INT NOT NULL DEFAULT 0
  72. );");
  73. }
  74. event onZombieKilled(player){
  75. player.message(str.format(zombieKillRewardMessage, zombieKillReward));
  76. balIncrease(player, zombieKillReward);
  77. }
  78. event onMegaZombieKilled(player){
  79. player.message(str.format(MegaZombieKillRewardMessage, MegaZombieKillReward));
  80. balIncrease(player, MegaZombieKillReward);
  81. }
  82. event onPlayerJoined(player){
  83. Result = database.execute("SELECT * FROM uBalance WHERE id = '" + player.id + "';");
  84. if(Result.count == 0){
  85. database.execute("INSERT INTO uBalance (id, balance) VALUES ('" + player.id + "', '" + startBalance + "');");
  86. }
  87. }
  88. function balDecrease(player, amount){
  89. database.execute(str.format("UPDATE uBalance SET balance = balance - '{0}' WHERE id = '{1}';", amount, player.id));
  90. }
  91. function balIncrease(player, amount){
  92. database.execute(str.format("UPDATE uBalance SET balance = balance + '{0}' WHERE id = '{1}';", amount, player.id));
  93. }
  94. function balGet(player){
  95. Result = database.execute(str.format("Select * FROM uBalance WHERE id = '{0}';", player.id));
  96. Player = Result[0];
  97. Balance = Player[1];
  98. Balance = toNumber(Balance);
  99. return Balance;
  100. }
  101. function balreset(player){
  102. database.execute(str.format("UPDATE uBalance SET balance = balance - balance WHERE id = '{0}';", player.id));
  103. }
  104. event onUnload(){
  105. logger.log("uBalance Unloaded!");
  106. }
  107. command pay(target, amount){
  108. permission = "uBalance.pay";
  109. execute(){
  110. if(isSet(target)){
  111. target = toPlayer(target);
  112. if(isSet(target)){
  113. if(isSet(amount)){
  114. if(amount <= balGet(player)){
  115. player.message(str.format(OutgoingPayment, player.name, amount, currencyName));
  116. target.message(str.format(IncomingPayment, player.name, amount, currencyName));
  117. balDecrease(player, amount);
  118. balIncrease(target, amount);
  119. }
  120. else{
  121. player.message(NotEnoughBalance);
  122. }
  123. }
  124. else{
  125. player.message(AmountUnspecified);
  126. }
  127. }
  128. else{
  129. player.message(PlayerNotFound);
  130. }
  131. }
  132. else{
  133. player.message(PlayerNotSpecified);
  134. }
  135. }
  136. }
  137. command balance(){
  138. permission = "uBalance.balance";
  139. execute(){
  140. playerBalance = balGet(player);
  141. player.message(str.format(PlayerCheckBalance, playerBalance, currencyName));
  142. }
  143. }
  144. command bal(){
  145. permission = "uBalance.balance";
  146. execute(){
  147. playerBalance = balGet(player);
  148. player.message(str.format(PlayerCheckBalance, playerBalance, currencyName));
  149. }
  150. }
  151. command addBal(target, amount){
  152. permission = "uBalance.addBal";
  153. execute(){
  154. if(isSet(target)){
  155. target = toPlayer(target);
  156. if(isSet(target)){
  157. if(isSet(amount)){
  158. balIncrease(target, amount);
  159. player.message(str.format(IncreasedPlayersBalance, target.name, amount));
  160. }
  161. else{
  162. player.message(AmountUnspecified);
  163. }
  164. }
  165. else{
  166. player.message(PlayerNotFound);
  167. }
  168. }
  169. else{
  170. player.message(PlayerNotSpecified);
  171. }
  172. }
  173. }
  174. command remBal(target, amount){
  175. permission = "uBalance.remBal";
  176. execute(){
  177. if(isSet(target)){
  178. target = toPlayer(target);
  179. if(isSet(target)){
  180. if(isSet(amount)){
  181. balDecrease(target, amount);
  182. player.message(str.format(DecreasedPlayersBalance, target.name, amount));
  183. }
  184. else{
  185. player.message(AmountUnspecified);
  186. }
  187. }
  188. else{
  189. player.message(PlayerNotFound);
  190. }
  191. }
  192. else{
  193. player.message(PlayerNotSpecified);
  194. }
  195. }
  196. }
  197. command resetBal(target){
  198. permission = "uBalance.resetBal";
  199. execute(){
  200. if(isSet(target)){
  201. target = toPlayer(target);
  202. if(isSet(target)){
  203. balreset(target);
  204. player.message(str.format(ResetPlayersBalance, target.name));
  205. }
  206. else{
  207. player.message(PlayerNotFound);
  208. }
  209. }
  210. else{
  211. player.message(PlayerNotSpecified);
  212. }
  213. }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement