Advertisement
AutismAlex

uBalance

Jan 15th, 2020
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.62 KB | None | 0 0
  1. startBalance = 0;
  2. currencyName = 0;
  3. zombieKillReward = 0;
  4. MegaZombieKillReward = 0;
  5. useUI = "False";
  6. zombieKillRewardMessage = "Message Not Set!";
  7. MegaZombieKillRewardMessage = "Message Not Set!";
  8. PlayerNotSpecified = "Message Not Set!";
  9. PlayerNotFound = "Message Not Found!";
  10. AmountUnspecified = "Message Not Found!";
  11. NotEnoughBalance = "Message Not Found!";
  12. IncomingPayment = "Message Not Found!";
  13. OutgoingPayment = "Message Not Found!";
  14. PlayerCheckBalance = "Message Not Found!";
  15. IncreasedPlayersBalance = "Message Not Found!";
  16. DecreasedPlayersBalance = "Message Not Found!";
  17. ResetPlayersBalance = "Message Not Found!";
  18. uAddUsage = "Message Not Found!";
  19. uAddSuccess = "Message Not Found!";
  20. uBuyUsage = "Message Not Found!";;
  21. uBuySuccess = "Message Not Found!";
  22. uBuyItemNotForSale = "Message Not Found!";
  23. uBuyNotEnoughFunds = "Message Not Found!";
  24. uSellUsage = "Message Not Found!";
  25. uSellItemNotSellable = "Message Not Found!";
  26. uSellNotHaveItem = "Message Not Found!";
  27. uSellSuccess = "Message Not Found!";
  28. event onLoad(){
  29. logger.log("uBalance Loaded!");
  30. file.write("../uBalance_configuration.txt","");
  31. if(file.read("../uBalance_configuration.txt") != ""){
  32. logger.log("uBalance Configuration Found!");
  33. }
  34. else{
  35. logger.log("uBalance Configuration Created!");
  36. file.writeAll("../uBalance_configuration.txt", "<startingBalance>0</startingBalance>\n<currencyName>Credits</currencyName>\n<zombieKillReward>15</zombieKillReward>\n<MegaZombieKillReward>50</MegaZombieKillReward>\n<useUI>False</useUI>");
  37. }
  38. file.write("../uBalance_translations.txt","");
  39. if(file.read("../uBalance_translations.txt") != ""){
  40. logger.log("uBalance Translations Found!");
  41. }
  42. else{
  43. logger.log("uBalance Translations Created!");
  44. 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>\n<uAddUsage>Correct Usage: /Add ItemID BuyPrice SellPrice</uAddUsage>\n<uAddSuccess>Set cost of {0} to {1} {3} and sell price to {2} {3}!</uAddSuccess>\n<uBuyUsage>Correct Usage: /Buy ItemID</uBuyUsage>\n<uBuySuccess>Purchased {0} for {1} {2}</uBuySuccess>\n<uBuyItemNotForSale>{0} is not for sale!</uBuyItemNotForSale>\n<uBuyNotEnoughFunds>You do not have enough {0} to purchase {1}</uBuyNotEnoughFunds>\n<uSellUsage>Correct Usage: /sell ItemID</uSellUsage>\n<uSellItemNotSellable>{0} cannot be sold!</uSellItemNotSellable>\n<uSellNotHaveItem>You do not have any {0} in your inventory!</uSellNotHaveItem>\n<uSellSuccess>You have sold {0} for {1} {2}!</uSellSuccess>");
  45. }
  46. // Translations
  47. translationFile = file.read("../uBalance_translations.txt").split("\n");
  48. zombieKillRewardMessage = translationFile[0].replace("<zombieKillRewardMessage>", "");
  49. zombieKillRewardMessage = zombieKillRewardMessage.replace("</zombieKillRewardMessage>", "");
  50. MegaZombieKillRewardMessage = translationFile[1].replace("<MegaZombieKillRewardMessage>", "");
  51. MegaZombieKillRewardMessage = MegaZombieKillRewardMessage.replace("</MegaZombieKillRewardMessage>", "");
  52. PlayerNotSpecified = translationFile[2].replace("<PlayerNotSpecified>", "");
  53. PlayerNotSpecified = PlayerNotSpecified.replace("</PlayerNotSpecified>", "");
  54. PlayerNotFound = translationFile[3].replace("<PlayerNotFound>", "");
  55. PlayerNotFound = PlayerNotFound.replace("</PlayerNotFound>", "");
  56. AmountUnspecified = translationFile[4].replace("<AmountUnspecified>", "");
  57. AmountUnspecified = AmountUnspecified.replace("</AmountUnspecified>", "");
  58. NotEnoughBalance = translationFile[5].replace("<NotEnoughBalance>", "");
  59. NotEnoughBalance = NotEnoughBalance.replace("</NotEnoughBalance>", "");
  60. IncomingPayment = translationFile[6].replace("<IncomingPayment>", "");
  61. IncomingPayment = IncomingPayment.replace("</IncomingPayment>", "");
  62. OutgoingPayment = translationFile[7].replace("<OutgoingPayment>", "");
  63. OutgoingPayment = OutgoingPayment.replace("</OutgoingPayment>", "");
  64. PlayerCheckBalance = translationFile[8].replace("<PlayerCheckBalance>", "");
  65. PlayerCheckBalance = PlayerCheckBalance.replace("</PlayerCheckBalance>", "");
  66. IncreasedPlayersBalance = translationFile[9].replace("<IncreasedPlayersBalance>", "");
  67. IncreasedPlayersBalance = IncreasedPlayersBalance.replace("</IncreasedPlayersBalance>", "");
  68. DecreasedPlayersBalance = translationFile[10].replace("<DecreasedPlayersBalance>", "");
  69. DecreasedPlayersBalance = DecreasedPlayersBalance.replace("</DecreasedPlayersBalance>", "");
  70. ResetPlayersBalance = translationFile[11].replace("<ResetPlayersBalance>", "");
  71. ResetPlayersBalance = ResetPlayersBalance.replace("</ResetPlayersBalance>", "");
  72. uAddUsage = translationFile[12].replace("<uAddUsage>", "");
  73. uAddUsage = uAddUsage.replace("</uAddUsage>", "");
  74. uAddSuccess = translationFile[13].replace("<uAddSuccess>", "");
  75. uAddSuccess = uAddSuccess.replace("</uAddSuccess>", "");
  76. uBuyUsage = translationFile[14].replace("<uBuyUsage>", "");
  77. uBuyUsage = uBuyUsage.replace("</uBuyUsage>", "");
  78. uBuySuccess = translationFile[15].replace("<uBuySuccess>", "");
  79. uBuySuccess = uBuySuccess.replace("</uBuySuccess>", "");
  80. uBuyItemNotForSale = translationFile[16].replace("<uBuyItemNotForSale>", "");
  81. uBuyItemNotForSale = uBuyItemNotForSale.replace("</uBuyItemNotForSale>", "");
  82. uBuyNotEnoughFunds = translationFile[17].replace("<uBuyNotEnoughFunds>", "");
  83. uBuyNotEnoughFunds = uBuyNotEnoughFunds.replace("</uBuyNotEnoughFunds>", "");
  84. uSellUsage = translationFile[18].replace("<uSellUsage>", "");
  85. uSellUsage = uSellUsage.replace("</uSellUsage>", "");
  86. uSellItemNotSellable = translationFile[19].replace("<uSellItemNotSellable>", "");
  87. uSellItemNotSellable = uSellItemNotSellable.replace("</uSellItemNotSellable>", "");
  88. uSellNotHaveItem = translationFile[20].replace("<uSellNotHaveItem>", "");
  89. uSellNotHaveItem = uSellNotHaveItem.replace("</uSellNotHaveItem>", "");
  90. uSellSuccess = translationFile[21].replace("<uSellSuccess>", "");
  91. uSellSuccess = uSellSuccess.replace("</uSellSuccess>", "");
  92. // Configuration
  93. configFile = file.read("../uBalance_configuration.txt").split("\n");
  94. startBalance = configFile[0].replace("<startingBalance>", "");
  95. startBalance = startBalance.replace("</startingBalance>", "");
  96. currencyName = configFile[1].replace("<currencyName>", "");
  97. currencyName = currencyName.replace("</currencyName>", "");
  98. zombieKillReward = configFile[2].replace("<zombieKillReward>", "");
  99. zombieKillReward = zombieKillReward.replace("</zombieKillReward>", "");
  100. MegaZombieKillReward = configFile[3].replace("<MegaZombieKillReward>", "");
  101. MegaZombieKillReward = MegaZombieKillReward.replace("</MegaZombieKillReward>", "");
  102. useUI = configFile[4].replace("<useUI>", "");
  103. useUI = useUI.replace("</useUI>", "");
  104. logger.log(currencyName);
  105. database.execute("CREATE TABLE IF NOT EXISTS uBalance(
  106. id VARCHAR(17) PRIMARY KEY,
  107. balance INT NOT NULL DEFAULT 0
  108. );");
  109. database.execute("CREATE TABLE IF NOT EXISTS uBalanceShop(
  110. itemid INT PRIMARY KEY,
  111. buyPrice INT NOT NULL DEFAULT 0,
  112. sellPrice INT NOT NULL DEFAULT 0
  113. );");
  114. foreach(player in server.players){
  115. player.setData("zombieCooldown", false);
  116. player.setData("MegazombieCooldown", false);
  117. player.setData("uBuyCooldown", false);
  118. player.setData("uSellCooldown", false);
  119. }
  120. }
  121. event onInterval(10){
  122. if(useUI == "True"){
  123. foreach(player in server.players){
  124. balance = balGet(player);
  125. effectManager.sendUI(24107, 24107, player.id, " $" + toString(balance));
  126. }
  127. }
  128. }
  129. function balui(player){
  130. if(useUI == "True"){
  131. balance = balGet(player);
  132. effectManager.sendUI(24107, 24107, player.id, " $" + toString(balance));
  133. }
  134. }
  135. command add(itemID, bPrice, sPrice){
  136. allowedCaller = "both";
  137. permission = "uBalance.add";
  138. execute(){
  139. if(isSet(itemID) and isSet(bPrice) and isSet(sPrice)){
  140. Result = database.execute("SELECT * FROM uBalanceShop WHERE itemid = '" + itemID + "';");
  141. foreach(listing in Result){
  142. database.execute("DELETE FROM uBalanceShop WHERE itemid = '" + itemID + "';");
  143. }
  144. database.execute("INSERT INTO uBalanceShop (itemid, buyPrice, sellPrice) VALUES ('" + itemID + "', '" + bPrice + "', '" + sPrice + "');");
  145. player.message(str.format(uAddSuccess, itemManager.getItemName(itemID), bPrice, sPrice, currencyName));
  146. }
  147. else{
  148. player.message(uAddUsage);
  149. }
  150. }
  151. }
  152. command Buy(itemID){
  153. permission = "uBalance.buy";
  154. execute(){
  155. if(isSet(itemID)){
  156. Result = array();
  157. if(player.getData("uBuyCooldown") == false){
  158. Result = database.execute("SELECT * FROM uBalanceShop WHERE itemid = '" + itemID + "';");
  159. }
  160. if(Result.count != 0){
  161. Item = Result[0];
  162. if(toNumber(balGet(player)) >= toNumber(Item[1])){
  163. balDecrease(player, Item[1]);
  164. player.give(Item[0], 1);
  165. player.message(str.format(uBuySuccess, itemManager.getItemName(itemID), Item[1], currencyName));
  166. }
  167. else{
  168. player.message(str.format(uBuyNotEnoughFunds, currencyName, itemManager.getItemName(itemID)));
  169. }
  170. }
  171. else{
  172. player.message(str.format(uBuyItemNotForSale, itemManager.getItemName(itemID)));
  173. }
  174. player.setData("uBuyCooldown", true);
  175. wait.seconds(1, player.setData("uBuyCooldown", false));
  176. }
  177. else{
  178. player.message(uBuyUsage);
  179. }
  180. }
  181. }
  182. command Sell(itemID){
  183. permission = "uBalance.sell";
  184. execute(){
  185. if(isSet(itemID)){
  186. Result = array();
  187. if(player.getData("uSellCooldown") == false){
  188. Result = database.execute("SELECT * FROM uBalanceShop WHERE itemid = '" + itemID + "';");
  189. }
  190. if(Result.count != 0){
  191. Item = Result[0];
  192. if(player.inventory.hasItem(itemID)){
  193. player.inventory.removeItem(itemID, 1);
  194. balIncrease(player, Item[2]);
  195. player.message(str.format(uSellSuccess, itemManager.getItemName(itemID), Item[2], currencyName));
  196. }
  197. else{
  198. player.message(str.format(uSellNotHaveItem, itemManager.getItemName(itemID)));
  199. }
  200. }
  201. else{
  202. player.message(str.format(uSellItemNotSellable, itemManager.getItemName(itemID)));
  203. }
  204. player.setData("uSellCooldown", true);
  205. wait.seconds(1, player.setData("uSellCooldown", false));
  206. }
  207. else{
  208. player.message(uSellUsage);
  209. }
  210. }
  211. }
  212. event onZombieKilled(player){
  213. if(player.getData("zombieCooldown") == false){
  214. player.message(str.format(zombieKillRewardMessage, zombieKillReward));
  215. balIncrease(player, zombieKillReward);
  216. player.setData("zombieCooldown", true);
  217. wait.seconds(1, player.setData("zombieCooldown", false));
  218. }
  219. }
  220. event onMegaZombieKilled(player){
  221. if(player.getData("MegazombieCooldown") == false){
  222. player.message(str.format(MegaZombieKillRewardMessage, MegaZombieKillReward));
  223. balIncrease(player, MegaZombieKillReward);
  224. player.setData("MegazombieCooldown", true);
  225. wait.seconds(1, player.setData("MegazombieCooldown", false));
  226. }
  227. }
  228. event onPlayerJoined(player){
  229. player.setData("zombieCooldown", false);
  230. Result = database.execute("SELECT * FROM uBalance WHERE id = '" + player.id + "';");
  231. if(Result.count == 0){
  232. database.execute("INSERT INTO uBalance (id, balance) VALUES ('" + player.id + "', '" + startBalance + "');");
  233. }
  234. balui(player);
  235. }
  236. function balDecrease(player, amount){
  237. database.execute(str.format("UPDATE uBalance SET balance = balance - '{0}' WHERE id = '{1}';", amount, player.id));
  238. }
  239. function balIncrease(player, amount){
  240. database.execute(str.format("UPDATE uBalance SET balance = balance + '{0}' WHERE id = '{1}';", amount, player.id));
  241. }
  242. function balGet(player){
  243. Result = database.execute(str.format("Select * FROM uBalance WHERE id = '{0}';", player.id));
  244. Player = Result[0];
  245. Balance = Player[1];
  246. Balance = toNumber(Balance);
  247. return Balance;
  248. }
  249. function balreset(player){
  250. database.execute(str.format("UPDATE uBalance SET balance = balance - balance WHERE id = '{0}';", player.id));
  251. }
  252. event onUnload(){
  253. logger.log("uBalance Unloaded!");
  254. }
  255. command pay(target, amount){
  256. permission = "uBalance.pay";
  257. execute(){
  258. if(isSet(target)){
  259. target = toPlayer(target);
  260. if(isSet(target)){
  261. if(isSet(amount)){
  262. if(amount <= balGet(player)){
  263. player.message(str.format(OutgoingPayment, player.name, amount, currencyName));
  264. target.message(str.format(IncomingPayment, player.name, amount, currencyName));
  265. balDecrease(player, amount);
  266. balIncrease(target, amount);
  267. }
  268. else{
  269. player.message(NotEnoughBalance);
  270. }
  271. }
  272. else{
  273. player.message(AmountUnspecified);
  274. }
  275. }
  276. else{
  277. player.message(PlayerNotFound);
  278. }
  279. }
  280. else{
  281. player.message(PlayerNotSpecified);
  282. }
  283. }
  284. }
  285. command balance(){
  286. permission = "uBalance.balance";
  287. execute(){
  288. playerBalance = balGet(player);
  289. player.message(str.format(PlayerCheckBalance, playerBalance, currencyName));
  290. }
  291. }
  292. command bal(){
  293. permission = "uBalance.balance";
  294. execute(){
  295. playerBalance = balGet(player);
  296. player.message(str.format(PlayerCheckBalance, playerBalance, currencyName));
  297. }
  298. }
  299. command addBal(target, amount){
  300. permission = "uBalance.addBal";
  301. execute(){
  302. if(isSet(target)){
  303. target = toPlayer(target);
  304. if(isSet(target)){
  305. if(isSet(amount)){
  306. balIncrease(target, amount);
  307. player.message(str.format(IncreasedPlayersBalance, target.name, amount));
  308. }
  309. else{
  310. player.message(AmountUnspecified);
  311. }
  312. }
  313. else{
  314. player.message(PlayerNotFound);
  315. }
  316. }
  317. else{
  318. player.message(PlayerNotSpecified);
  319. }
  320. }
  321. }
  322. command remBal(target, amount){
  323. permission = "uBalance.remBal";
  324. execute(){
  325. if(isSet(target)){
  326. target = toPlayer(target);
  327. if(isSet(target)){
  328. if(isSet(amount)){
  329. balDecrease(target, amount);
  330. player.message(str.format(DecreasedPlayersBalance, target.name, amount));
  331. }
  332. else{
  333. player.message(AmountUnspecified);
  334. }
  335. }
  336. else{
  337. player.message(PlayerNotFound);
  338. }
  339. }
  340. else{
  341. player.message(PlayerNotSpecified);
  342. }
  343. }
  344. }
  345. command resetBal(target){
  346. permission = "uBalance.resetBal";
  347. execute(){
  348. if(isSet(target)){
  349. target = toPlayer(target);
  350. if(isSet(target)){
  351. balreset(target);
  352. player.message(str.format(ResetPlayersBalance, target.name));
  353. }
  354. else{
  355. player.message(PlayerNotFound);
  356. }
  357. }
  358. else{
  359. player.message(PlayerNotSpecified);
  360. }
  361. }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement