mengerrun.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. rankingtable = "mrranks";
  2. game_short = "mr";
  3. times = map.new();
  4. jump_strength = map.new();
  5. tp_times = map.new();
  6. seekerlist = list.new();
  7. escaperlist = list.new();
  8. specific_lobby_handling = true;
  9. no_core_reset = true;
  10. gamename = "§9Menger-Run";
  11. gosub("setstart");
  12. goto("simplelobby");
  13. @specificLobbyHandling
  14. if(event == "player_join") {
  15. entity.cleareffects(player);
  16. living.setHealth(player, 20);
  17. player.setHunger(player, 20);
  18. player.setSaturation(player, 5);
  19. player.clearInventory(player);
  20. display.reset(player);
  21. }
  22. return;
  23. @finalstart
  24. player_list = minigame.getPlayers(script_id);
  25. event.load("function_key");
  26. event.load("living_jump");
  27. strength = 0;
  28. //Temp-Kopie von player_list erstellen
  29. templist = list.new();
  30. amount_players = list.getSize(player_list);
  31. for(i = 0; i < amount_players; i++) {
  32. p_uuid = list.getIndex(player_list, i);
  33. p = player.get(p_uuid);
  34. msg.prefix(p, gamename, "The game has started.");
  35. list.add(templist, p_uuid);
  36. map.add(times, p_uuid, start_life_time);
  37. map.add(jump_strength, p_uuid, 0);
  38. player.setGamemode(p, "adventure");
  39. player.setFly(p, false);
  40. menger.tpPlayer(p);
  41. }
  42. if(seeker_amount == minplayers && amount_players == minplayers) {
  43. seeker_amount--;
  44. }
  45. for(i = 0; i < seeker_amount; i++) {
  46. p_uuid = list.getIndex(templist, math.random(0, list.getSize(templist) - 1));
  47. p = player.get(p_uuid);
  48. list.remove(templist, p_uuid);
  49. setSeeker(p);
  50. msg.prefix(p, gamename, "Catch other players!");
  51. }
  52. for(i = 0; i < list.getSize(templist); i++) {
  53. p_uuid = list.getIndex(templist, i);
  54. p = player.get(p_uuid);
  55. setEscaper(p);
  56. msg.prefix(p, gamename, "Run away!!!");
  57. }
  58. sgoto(20, "loop");
  59. @checkgame
  60. wait();
  61. if(event == "living_pre_hurt" || event == "living_jump") {
  62. if(!isPlayer(living_entity)) {
  63. goto("checkgame");
  64. }
  65. player = living_entity;
  66. }
  67. if(player.hasMinigameId(player, script_id)) {
  68. ignoreGoto(event);
  69. }
  70. goto("checkgame");
  71. @function_key
  72. if(key > list.getSize(jan_mr_skills)) {
  73. goto("checkgame");
  74. }
  75. p_uuid = player.getUuid(player);
  76. skill = list.getIndex(jan_mr_skills, key - 1);
  77. skill_name = skill[0];
  78. strength = skill[2];
  79. if(map.get(jump_strength, p_uuid) == strength){
  80. message = text.concat("Your Jump Strength is already set to ", skill_name, ".");
  81. }else{
  82. map.add(jump_strength, p_uuid, strength);
  83. message = text.concat("Your Jump Strength is now set to ", skill_name, ".");
  84. }
  85. msg.prefix(player, gamename, message);
  86. goto("checkgame");
  87. @living_jump
  88. jump = map.get(jump_strength, player.getUuid(player));
  89. if(jump > 0){
  90. array = entity.getLook(living_entity);
  91. array2 = entity.getMotion(living_entity);
  92. x = array[0] * strength + array2[0];
  93. y = math.abs(array[1]) * strength + array2[1];
  94. z = array[2] * strength + array2[2];
  95. entity.throw(living_entity, x, y, z);
  96. }
  97. goto("checkgame");
  98. @living_pre_hurt
  99. defender = player;
  100. attacker = player.getFromDamageSource(damage_source);
  101. if(attacker == null) {
  102. damage_type = damage.getType(damage_source);
  103. if(damage_type == "fall") {
  104. cancel = true;
  105. goto("checkgame");
  106. }
  107. if(damage_type == "outOfWorld") {
  108. cancel = true;
  109. if(list.contains(escaperlist, player.getUuid(defender))) {
  110. //Random-Seeker zum Escaper machen
  111. p_uuid = list.getIndex(seekerlist, math.random(0, list.getSize(seekerlist) - 1));
  112. p = player.get(p_uuid);
  113. setEscaper(p);
  114. msg.prefix(p, gamename, "Run away!!!");
  115. //Escaper wird zum Seeker
  116. setSeeker(defender);
  117. msg.prefix(defender, gamename, "Catch other players!");
  118. menger.tpPlayer(defender);
  119. } else {
  120. menger.tpPlayer(defender);
  121. }
  122. }
  123. goto("checkgame");
  124. }
  125. defender_uuid = player.getUuid(defender);
  126. if(!list.contains(player_list, defender_uuid)) {
  127. cancel = true;
  128. msg.prefix(attacker, gamename, "§eIllegal player in game.");
  129. goto("checkgame");
  130. }
  131. if(!player.hasMinigameId(attacker, script_id)) {
  132. goto("checkgame");
  133. }
  134. attacker_uuid = player.getUuid(attacker);
  135. if(defender_uuid == attacker_uuid) {
  136. goto("checkgame");
  137. }
  138. if(!list.contains(player_list, attacker_uuid)) {
  139. msg.prefix(defender, gamename, "§eIllegal player in game.");
  140. cancel = true;
  141. goto("checkgame");
  142. }
  143. if(list.contains(seekerlist, attacker_uuid) && list.contains(escaperlist, defender_uuid)) {
  144. cancel = true;
  145. menger.tpPlayer(defender);
  146. setSeeker(defender);
  147. msg.prefix(defender, gamename, "Catch other players!");
  148. setEscaper(attacker);
  149. msg.prefix(attacker, gamename, "Run away!!!");
  150. new_time = map.get(times, attacker_uuid) + 30;
  151. if(new_time > max_life_time) {
  152. new_time = max_life_time;
  153. }
  154. map.add(times, attacker_uuid, new_time);
  155. }
  156. if(list.contains(escaperlist, attacker_uuid) && list.contains(seekerlist, defender_uuid)) {
  157. cancel = true;
  158. }
  159. goto("checkgame");
  160. @block_break
  161. cancel = true;
  162. goto("checkgame");
  163. @block_place
  164. cancel = true;
  165. goto("checkgame");
  166. @loop
  167. for(i = 0; i < list.getSize(seekerlist); i++) {
  168. player_uuid = list.getIndex(seekerlist, i);
  169. player = player.get(player_uuid);
  170. seconds = map.get(times, player_uuid) - 1;
  171. map.add(times, player_uuid, seconds);
  172. if(seconds == 0) {
  173. minigame.speakAll(gamename, concat("§6", player.getName(player), "§r's time has run out."));
  174. gosub("menger_kick");
  175. }
  176. display.reset(player);
  177. display.add(player, 0, gamename);
  178. display_index = 1;
  179. for(h = 0; h < list.getSize(player_list); h++) {
  180. p_uuid = list.getIndex(player_list, h);
  181. p = player.get(p_uuid);
  182. seconds = map.get(times, p_uuid);
  183. minutes = text.number(math.roundDown(seconds / 60));
  184. seconds = seconds % 60;
  185. if(seconds < 10) {
  186. seconds = concat("0", text.number(seconds));
  187. } else {
  188. seconds = text.number(seconds);
  189. }
  190. time_string = concat(minutes, ":", seconds);
  191. if(list.contains(seekerlist, p_uuid)) {
  192. minigame.displayAll(display_index++, concat(time_string, " §e", player.getName(p)));
  193. } else {
  194. minigame.displayAll(display_index++, concat(time_string, " ", player.getName(p)));
  195. }
  196. }
  197. }
  198. sgoto(20, "loop");
  199. goto("checkgame");
  200. function setSeeker(player) {
  201. setStackIcons(player);
  202. player_uuid = player.getUuid(player);
  203. living.setHealth(player, 20);
  204. player.setHunger(player, 20);
  205. player.setSaturation(player, 100);
  206. entity.clearEffects(player);
  207. player.clearInventory(player);
  208. list.add($seekerlist, player_uuid);
  209. list.remove($escaperlist, player_uuid);
  210. entity.addEffect(player, "glowing", $max_life_time * 20 * $maxplayers, 1, false);
  211. player.setSpeed(player, 2.6);
  212. }
  213. function setEscaper(player) {
  214. setStackIcons(player);
  215. player_uuid = player.getUuid(player);
  216. living.setHealth(player, 20);
  217. player.setHunger(player, 20);
  218. player.setSaturation(player, 100);
  219. entity.clearEffects(player);
  220. player.clearInventory(player);
  221. list.add($escaperlist, player_uuid);
  222. list.remove($seekerlist, player_uuid);
  223. entity.addEffect(player, "glowing", $max_life_time * 20 * $maxplayers, 1, false);
  224. player.setSpeed(player, 2.5);
  225. }
  226. function setStackIcons(player) {
  227. for(h = 0; h < list.getSize($jan_mr_skills); h++) {
  228. skill = list.getIndex($jan_mr_skills, h);
  229. icon = skill[1];
  230. stacks.set(player, h, icon);
  231. }
  232. stacks.setActive(player, true);
  233. }
  234. function addMengerSkill(skill_name, icon, menger_strength) {
  235. skill = array.new(3);
  236. skill[0] = skill_name;
  237. skill[1] = icon;
  238. skill[2] = menger_strength;
  239. list.add($jan_mr_skills, skill);
  240. }
  241. @player_logout
  242. @player_giveup
  243. minigame.speakAll(gamename, concat("§6", player.getName(player), " §rhas left the game."));
  244. gosub("menger_kick");
  245. goto("checkgame");
  246. @menger_kick
  247. script = script.getFromId(script_id);
  248. player.setSpeed(player, 1);
  249. minigame.kickPlayer(script, player);
  250. player_uuid = player.getUuid(player);
  251. showStats(player, false);
  252. current_seekers = list.getSize(seekerlist);
  253. current_escapers = list.getSize(escaperlist);
  254. if(list.contains(seekerlist, player_uuid)) {
  255. is_seeker = true;
  256. } else {
  257. is_seeker = false;
  258. }
  259. list.remove(seekerlist, player_uuid);
  260. list.remove(escaperlist, player_uuid);
  261. if(current_seekers == 2 && current_escapers >= 2) {
  262. if(is_seeker) {
  263. p = player.get(list.getIndex(escaperlist, math.random(0, list.getSize(escaperlist) - 1)));
  264. setSeeker(p);
  265. msg.prefix(p, gamename, "A seeker has left. You are a seeker now.");
  266. }
  267. return;
  268. }
  269. if(current_seekers == 2 && current_escapers == 1) {
  270. if(!is_seeker) {
  271. p = player.get(list.getIndex(seekerlist, math.random(0, list.getSize(seekerlist) - 1)));
  272. setEscaper(p);
  273. msg.prefix(p, gamename, "An escaper has left. You are an escaper now.");
  274. }
  275. seeker_amount--;
  276. return;
  277. }
  278. if(list.getSize(player_list) < minplayers) {
  279. winner_uuid = list.getIndex(player_list, 0);
  280. goto("win");
  281. }
  282. return;
  283. @win
  284. winner_name = player.getName(winner_uuid);
  285. winner = player.get(winner_uuid);
  286. msg.prefix(winner, gamename, "§6You won the game.");
  287. showStats(winner, true);
  288. player.setSpeed(winner, 1);
  289. script = script.getFromId(script_id);
  290. minigame.kickPlayer(script, winner);
  291. minigame.term(script, gamesignloc);
  292. term();
  293. function showStats(player, won) {
  294. player_id = player.getId(player);
  295. last_record = ranking.getPoints($rankingtable, player_id);
  296. if(won) {
  297. last_record++;
  298. }
  299. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  300. minigame.setPlayed(player_id, $game_short, playedgames);
  301. ranking.setPoints($rankingtable, player_id, last_record);
  302. minigame.statsHeader(player, $gamename, "§e");
  303. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  304. minigame.statsLine(player, "§e", "Won games", text.number(last_record));
  305. if(playedgames != 0) {
  306. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((last_record / playedgames) * 100, 2)), "%"));
  307. }
  308. }
  309. function menger.tpPlayer(player) {
  310. now_time = time.getMillis();
  311. player_uuid = player.getUuid(player);
  312. tp_time = map.getOrDefault($tp_times, player_uuid, 0);
  313. if(now_time - tp_time < 1000) {
  314. return;
  315. }
  316. map.add($tp_times, player_uuid, now_time);
  317. tp_time = now_time;
  318. world = world.getGames();
  319. @do
  320. x = math.random(loc.getX($edge_loc_1), loc.getX($edge_loc_2));
  321. y = math.random(loc.getY($edge_loc_1), loc.getY($edge_loc_2));
  322. z = math.random(loc.getZ($edge_loc_1), loc.getZ($edge_loc_2));
  323. loc1 = loc.new(world, x, y, z);
  324. loc2 = loc.mod(loc1, 0, 1, 0);
  325. loc3 = loc.mod(loc1, 0, 2, 0);
  326. if(block.isSolid(loc1) && block.isAir(loc2) && block.isAir(loc3)) {
  327. entity.teleport(player, loc.mod(loc2, 0.5, 0, 0.5));
  328. return;
  329. }
  330. goto("do");
  331. }