knockfight.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. rankingtable = "knockranks";
  2. game_short = "knock";
  3. event.load("player_toss");
  4. event.load("function_key");
  5. event.load("living_hurt");
  6. kf_skills = list.new();
  7. addKnockfightSkill("Speed", "km:skill44", 30);
  8. addKnockfightSkill("JumpBoost", "km:skill15", 30);
  9. addKnockfightSkill("Slowness", "km:skill53", 30);
  10. addKnockfightSkill("Blindness", "km:skill55", 30);
  11. addKnockfightSkill("Kick", "km:skill9", 60);
  12. resettime = 180; //Zeit in Ticks, wie lange der letzte Schläger gehalten wird
  13. stick = read.item("minecraft:stick");
  14. enchantment.add(enchantment.get("minecraft:knockback"), stick, 2);
  15. resetblocks = list.new();
  16. gamename = "§cKnockFight";
  17. gosub("setstart");
  18. goto("simplelobby");
  19. @finalstart
  20. player_list = minigame.getPlayers(script_id);
  21. size = list.getSize(player_list);
  22. cooldown_map = map.new();
  23. lifes = map.new();
  24. lastdamage = map.new();
  25. knockedcounter = map.new();
  26. resetlist = list.new();
  27. for(i = 0; i < size; i++) {
  28. p_uuid = list.getIndex(player_list, i);
  29. p = player.get(p_uuid);
  30. msg.prefix(p, gamename, "The game has started.");
  31. resetplayer(p);
  32. entity.teleport(p, list.getIndex(startlocs, i));
  33. player.setGamemode(p, "survival");
  34. player.setFly(p, false);
  35. map.add(knockedcounter, p_uuid, 0);
  36. player.giveItem(p, stick);
  37. map.add(lastdamage, p_uuid, null);
  38. map.add(lifes, p_uuid, startlifes);
  39. setStackIcons(p);
  40. status.add(p, 0, "§cCooldowns");
  41. }
  42. gosub("updatedisplay");
  43. @checkgame
  44. wait();
  45. if(event == "living_hurt") {
  46. if(!isPlayer(living_entity)) {
  47. goto("checkgame");
  48. }
  49. player = living_entity;
  50. }
  51. if(player.hasMinigameId(player, script_id)) {
  52. player_name = player.getName(player);
  53. ignoreGoto(event);
  54. }
  55. goto("checkgame");
  56. @player_toss
  57. cancel = true;
  58. player.giveItem(player, item);
  59. goto("checkgame");
  60. @living_hurt
  61. player_uuid = player.getUuid(player);
  62. damage_type = damage.getType(damage_source);
  63. if(damage_type == "player") {
  64. sec_player = player.getFromDamageSource(damage_source);
  65. if(player.hasMinigameId(sec_player, script_id)) {
  66. cancel = true;
  67. player.setSaturation(sec_player, 5);
  68. map.add(lastdamage, player_uuid, player.getUuid(sec_player));
  69. list.add(resetlist, player_uuid);
  70. sgoto(resettime, "resetdamager");
  71. }
  72. goto("checkgame");
  73. }
  74. if(damage_type == "fall") {
  75. cancel = true;
  76. goto("checkgame");
  77. }
  78. if(damage_type == "outOfWorld") {
  79. cancel = true;
  80. player_uuid = player.getUuid(player);
  81. lastdamager_uuid = map.get(lastdamage, player_uuid);
  82. if(lastdamager_uuid == null) {
  83. minigame.speakAll(gamename, concat("§6", player_name, " §rfell."));
  84. } else {
  85. minigame.speakAll(gamename, concat("§6", player_name, " §rwas knocked down by §6", player.getName(lastdamager_uuid), "."));
  86. map.add(knockedcounter, lastdamager_uuid, map.get(knockedcounter, lastdamager_uuid) + 1);
  87. }
  88. entity.teleport(player, list.getIndex(startlocs, math.random(0, list.getSize(startlocs) - 1)));
  89. new_lifes = map.get(lifes, player_uuid) - 1;
  90. map.add(lifes, player_uuid, new_lifes);
  91. gosub("updatedisplay");
  92. if(new_lifes == 0) {
  93. minigame.speakAll(gamename, concat("§6", player_name, " §rhas been eliminated."));
  94. money.addBoost(player, 32);
  95. goto("leavegame");
  96. }
  97. }
  98. goto("checkgame");
  99. @block_break
  100. @block_place
  101. cancel = true;
  102. goto("checkgame");
  103. @function_key
  104. if(key > list.getSize(kf_skills)) {
  105. goto("checkgame");
  106. }
  107. skill = list.getIndex(kf_skills, key - 1);
  108. skill_name = skill[0];
  109. last_exe_time = getKfLastExeTime(player, skill_name);
  110. needed_cooldown = skill[2];
  111. now_time = time.getMillis();
  112. diff_time = math.roundUp((now_time - last_exe_time) / 1000);
  113. if(diff_time < needed_cooldown) {
  114. player.action(player, concat("§a", text.number(needed_cooldown - diff_time), "s cooldown left"));
  115. goto("checkgame");
  116. }
  117. if(key == 1) {
  118. entity.addEffect(player, "speed", 200, 1);
  119. } elseif(key == 2) {
  120. entity.addEffect(player, "jump_boost", 200, 2);
  121. } elseif(key == 3) {
  122. iter = list.iterator(player_list);
  123. while(hasNext(iter)) {
  124. p = player.get(next(iter));
  125. if(p != player) {
  126. entity.addEffect(p, "slowness", 160, 1);
  127. }
  128. }
  129. } elseif(key == 4) {
  130. iter = list.iterator(player_list);
  131. while(hasNext(iter)) {
  132. p = player.get(next(iter));
  133. if(p != player) {
  134. entity.addEffect(p, "blindness", 160, 1);
  135. }
  136. }
  137. } elseif(key == 5) {
  138. opp = player.getTargetEntity(player, 4, "net.minecraft.entity.player.PlayerEntity");
  139. if(opp == null) {
  140. player.action(player, "§aNo enemy targeted.");
  141. goto("checkgame");
  142. }
  143. array = entity.getLook(player);
  144. x = array[0] * 2;
  145. z = array[2] * 2;
  146. entity.throw(opp, x, 1, z);
  147. }
  148. setKfLastExeTime(player, skill_name);
  149. status.addTimed(player, key, needed_cooldown * 20, concat("Cooldown ", skill_name));
  150. minigame.speakAll(gamename, concat("§6", player_name, "§r used §2", skill_name, "."));
  151. goto("checkgame");
  152. @resetdamager
  153. map.add(lastdamage, list.getIndex(resetlist, 0), null);
  154. list.removeIndex(resetlist, 0);
  155. goto("checkgame");
  156. @player_giveup
  157. @player_logout
  158. minigame.speakAll(gamename, concat("§6", player_name, " §rhas left the game."));
  159. @leavegame
  160. script = script.getFromId(script_id);
  161. minigame.kickPlayer(script, player);
  162. gosub("updatedisplay");
  163. showstats(player, false);
  164. if(list.getSize(player_list) < minplayers) {
  165. winner = player.get(list.getIndex(player_list, 0));
  166. money.addBoost(winner, 128);
  167. showstats(winner, true);
  168. minigame.kickPlayer(script, winner);
  169. minigame.term(script, gamesignloc);
  170. term();
  171. }
  172. goto("checkgame");
  173. function setKfLastExeTime(player, skill_name) {
  174. player_uuid = player.getUuid(player);
  175. player_map = map.getOrDefault($cooldown_map, player_uuid, map.new());
  176. map.add(player_map, skill_name, time.getMillis());
  177. map.add($cooldown_map, player_uuid, player_map);
  178. }
  179. function getKfLastExeTime(player, skill_name) {
  180. player_map = map.get($cooldown_map, player.getUuid(player));
  181. if(player_map == null) {
  182. return 0;
  183. }
  184. return map.getOrDefault(player_map, skill_name, 0);
  185. }
  186. function setStackIcons(player) {
  187. for(h = 0; h < list.getSize($kf_skills); h++) {
  188. skill = list.getIndex($kf_skills, h);
  189. icon = skill[1];
  190. stacks.set(player, h, icon);
  191. }
  192. stacks.setActive(player, true);
  193. }
  194. function addKnockfightSkill(skill_name, icon, cooldown) {
  195. skill = array.new(3);
  196. skill[0] = skill_name;
  197. skill[1] = icon;
  198. skill[2] = cooldown; //s
  199. list.add($kf_skills, skill);
  200. }
  201. function showstats(player, won) { //showstats(Player player, Boolean won)
  202. player_name = player.getName(player);
  203. player_id = player.getId(player);
  204. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  205. minigame.setPlayed(player_id, $game_short, playedgames);
  206. last_record = ranking.getPoints($rankingtable, player_id);
  207. knockedplayers = map.get($knockedcounter, player.getUuid(player));
  208. points = last_record + knockedplayers;
  209. ranking.setPoints($rankingtable, player_id, points);
  210. wongames = minigame.getWon(player, "knock");
  211. if(won) {
  212. wongames++;
  213. minigame.setWon(player, "knock", wongames);
  214. winningtext = "Yes";
  215. } else {
  216. winningtext = "No";
  217. }
  218. minigame.statsHeader(player, $gamename, "§e");
  219. minigame.statsLine(player, "§e", "Kills", text.number(knockedplayers));
  220. minigame.statsLine(player, "§e", "Won games", text.number(wongames));
  221. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  222. if(playedgames != 0) {
  223. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
  224. }
  225. minigame.statsLine(player, "§e", "Won", winningtext);
  226. }
  227. @updatedisplay
  228. minigame.displayResetAll();
  229. minigame.displayAll(0, gamename);
  230. for(i = 0; i < list.getSize(player_list); i++) {
  231. p_uuid = list.getIndex(player_list, i);
  232. minigame.displayAll(i + 1, concat("§c", text.number(map.get(lifes, p_uuid)), " §r", player.getName(p_uuid)));
  233. }
  234. return;