all_damage_types.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. event.load("player_join");
  2. event.load("snuvi_click");
  3. event.load("entity_damage");
  4. prefix_challenge = "§aChallenge";
  5. challenge_short = "adtype";
  6. challenge_name = "All Damage Types";
  7. reward = 8192;
  8. sb_id = 13;
  9. lore_list = list.new();
  10. list.add(lore_list, text.new("Receive all types of damage in the given order."));
  11. list.add(lore_list, text.new(string.concat("§fReward: ", money.getString(4096), " + 1 Amber")));
  12. list.add(lore_list, text.new(""));
  13. list.add(lore_list, text.new("§aLeftclick §f= §eStart challenge"));
  14. list.add(lore_list, text.new("§cRightclick §f= §eCancel challenge"));
  15. challenge_item = item.create("CACTUS", 1, "§cAll Damage Types", lore_list);
  16. next_damage_types = map.new(); //player_id -> material
  17. done_damage_types = map.new(); //player_id -> set -> material
  18. todo_damage_types = map.new(); //player_id -> list -> material
  19. sound = sound.get("minecraft:entity.experience_orb.pickup");
  20. category = sound.getCategory("MASTER");
  21. all_damage_types = list.new();
  22. list.add(all_damage_types, "ANVIL");
  23. list.add(all_damage_types, "ARROW");
  24. list.add(all_damage_types, "CACTUS");
  25. list.add(all_damage_types, "DROWN");
  26. list.add(all_damage_types, "EXPLOSION.PLAYER"); //TNT, Creeper
  27. list.add(all_damage_types, "FALL");
  28. list.add(all_damage_types, "FIREBALL");
  29. list.add(all_damage_types, "FLYINTOWALL");
  30. list.add(all_damage_types, "FREEZE");
  31. list.add(all_damage_types, "HOTFLOOR");
  32. list.add(all_damage_types, "INDIRECTMAGIC"); //DRAGON_BREATH
  33. list.add(all_damage_types, "INFIRE");
  34. list.add(all_damage_types, "INWALL");
  35. list.add(all_damage_types, "LAVA");
  36. list.add(all_damage_types, "LIGHTNINGBOLT");
  37. list.add(all_damage_types, "MAGIC"); //Potion
  38. list.add(all_damage_types, "MOB");
  39. list.add(all_damage_types, "PLAYER");
  40. list.add(all_damage_types, "STARVE");
  41. list.add(all_damage_types, "THORNS");
  42. list.add(all_damage_types, "ONFIRE");
  43. list.add(all_damage_types, "OUTOFWORLD");
  44. list.add(all_damage_types, "WITHER");
  45. all_stages = list.getSize(all_damage_types);
  46. online_list = players.toList();
  47. iter = iterator(online_list);
  48. while(hasNext(iter)) {
  49. p = next(iter);
  50. if(challenge.playerHas(p, challenge_short)) {
  51. stage = loadDoneDamageTypes(p);
  52. type = loadNextDamageType(p);
  53. challenge.display(p, sb_id, challenge_name, type, stage, all_stages);
  54. }
  55. }
  56. msg.string("dev", "§bAllDamageTypes §rloaded.");
  57. @wait
  58. wait();
  59. ignoreGoto(event);
  60. goto("wait");
  61. @player_join
  62. if(!challenge.playerHas(player, challenge_short)) {
  63. goto("wait");
  64. }
  65. stage = loadDoneDamageTypes(player);
  66. type = loadNextDamageType(player);
  67. challenge.display(player, sb_id, challenge_name, type, stage, all_stages);
  68. goto("wait");
  69. @snuvi_click
  70. item = inv.getItem(inv, inv_slot);
  71. item.removeFlag(item, "HIDE_DESTROYS");
  72. title_string = string.text(inv_title);
  73. if(item == challenge_item) {
  74. if(click == "LEFT") {
  75. if(challenge.playerHas(player, challenge_short)) {
  76. msg.prefix(player, prefix_challenge, "You already started this challenge.");
  77. goto("wait");
  78. }
  79. player_id = player.getId(player);
  80. map.add(todo_damage_types, player_id, list.copy(all_damage_types));
  81. map.add(done_damage_types, player_id, set.new());
  82. player.addChallenge(player, challenge_short);
  83. type = getRandomDamageType(player);
  84. stage = setNextDamageType(player, type);
  85. challenge.display(player, sb_id, challenge_name, type, stage, all_stages);
  86. msg.prefix(player, prefix_challenge, "Challenge started.");
  87. goto("wait");
  88. }
  89. if(click == "RIGHT") {
  90. if(!challenge.playerHas(player, challenge_short)) {
  91. msg.prefix(player, prefix_challenge, "Challenge not active.");
  92. goto("wait");
  93. }
  94. resetDamageTypes(player);
  95. challenge.removeDisplay(player, sb_id);
  96. player.removeChallenge(player, challenge_short);
  97. msg.prefix(player, prefix_challenge, "Challenge canceled.");
  98. goto("wait");
  99. }
  100. goto("wait");
  101. }
  102. goto("wait");
  103. @entity_damage
  104. if(!isPlayer(entity)) {
  105. goto("wait");
  106. }
  107. player = entity;
  108. if(!challenge.playerHas(player, challenge_short)) {
  109. goto("wait");
  110. }
  111. player_loc = entity.getLocation(player);
  112. world_name = world.getName(loc.getWorld(player_loc));
  113. if(!world.isSurvName(world_name)) {
  114. goto("wait");
  115. }
  116. damage_type = string.toUpperCase(damage.getType(damage_source));
  117. if(!isNextDamageType(player, damage_type)) {
  118. goto("wait");
  119. }
  120. sound.spawnForPlayer(player, sound, category);
  121. new_type = getRandomDamageType(player);
  122. if(new_type == null) {
  123. msg.prefix(player, prefix_challenge, "All damage types received. Challenge done!");
  124. msg.prefix(player, prefix_challenge, string.concat("Reward: ", money.getString(reward)));
  125. money.add(player, reward);
  126. player.giveItem(player, customitem.getAmber());
  127. resetDamageTypes(player);
  128. challenge.removeDisplay(player, sb_id);
  129. player.removeChallenge(player, challenge_short);
  130. player.setADTChallengeAmounts(player, player.getADTChallengeAmounts(player) + 1);
  131. goto("wait");
  132. }
  133. saveDoneDamageType(player, entity_type);
  134. stage = setNextEntity(player, new_type);
  135. msg.prefix(player, prefix_challenge, string.concat("Entity killed. Next entity: ", new_type));
  136. challenge.display(player, sb_id, challenge_name, new_type, stage, all_stages);
  137. goto("wait");
  138. function getRandomDamageType(player) {
  139. player_id = player.getId(player);
  140. l = map.get($todo_damage_types, player_id);
  141. l_size = list.getSize(l);
  142. if(l_size == 0) {
  143. return null;
  144. }
  145. r = math.random(0, l_size - 1);
  146. return list.getIndex(l, r);
  147. }
  148. function isNextDamageType(player, damage_type) {
  149. player_id = player.getId(player);
  150. next_type = map.get($next_damage_types, player_id);
  151. return next_type == damage_type;
  152. }
  153. function setNextDamageType(player_or_id, damage_type) {
  154. player_id = player.getValidId(player_or_id);
  155. map.add($next_damage_types, player_id, damage_type);
  156. saveNextDamageType(player_or_id, damage_type);
  157. l = map.get($todo_damage_types, player_id);
  158. list.remove(l, damage_type);
  159. return $all_stages - list.getSize(l) - 1;
  160. }
  161. function loadNextDamageType(player_or_id) {
  162. config = playerdata.getSurvival(player_or_id);
  163. player_id = player.getValidId(player_or_id);
  164. type = config.getString(config, "cha.dtype.next", "null");
  165. map.add($next_damage_types, player_id, type);
  166. l = map.get($todo_damage_types, player_id);
  167. list.remove(l, type);
  168. return type;
  169. }
  170. function saveNextDamageType(player_or_id, damage_type) {
  171. config = playerdata.getSurvival(player_or_id);
  172. config.set(config, "cha.dtype.next", damage_type);
  173. config.saveAsync(config);
  174. }
  175. function loadDoneDamageTypes(player_or_id) {
  176. config = playerdata.getSurvival(player_or_id);
  177. string = config.getString(config, "cha.dtype.done", "");
  178. s = set.new();
  179. l = list.copy($all_damage_types);
  180. if(string != "") {
  181. a = string.split("%", string);
  182. for(i = 0; i < array.getSize(a); i++) {
  183. type = a[i];
  184. set.add(s, type);
  185. list.remove(l, type);
  186. }
  187. }
  188. player_id = player.getValidId(player_or_id);
  189. map.add($done_damage_types, player_id, s);
  190. map.add($todo_damage_types, player_id, l);
  191. return set.getSize(map.get($done_damage_types, player_id));
  192. }
  193. function saveDoneDamageType(player_or_id, damage_type) {
  194. player_id = player.getValidId(player_or_id);
  195. s = map.get($done_damage_types, player_id);
  196. set.add(s, damage_type);
  197. config = playerdata.getSurvival(player_or_id);
  198. string = config.getString(config, "cha.dtype.done", "");
  199. if(string == "") {
  200. config.set(config, "cha.dtype.done", damage_type);
  201. } else {
  202. config.set(config, "cha.dtype.done", string.concat(string, "%", damage_type));
  203. }
  204. config.saveAsync(config);
  205. }
  206. function resetDamageTypes(player_or_id) {
  207. config = playerdata.getSurvival(player_or_id);
  208. config.set(config, "cha.dtype.done", "");
  209. config.set(config, "cha.dtype.next", "");
  210. config.saveAsync(config);
  211. }