jumpnrun.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. event.load("living_pre_hurt");
  2. event.load("player_move");
  3. event.load("player_logout");
  4. event.load("player_giveup");
  5. event.load("player_join");
  6. rankingtable = "jumpranks";
  7. game_short = "jr";
  8. maxplayers = 1;
  9. gamesignloc = minigame.getSignLoc("jrmap");
  10. sign.started(gamesignloc);
  11. gamename = "§aJump'n'Run";
  12. jump_sound = sound.get("entity.item.pickup");
  13. sound_category_ambient = sound.getCategory("ambient");
  14. color_list = list.new();
  15. list.add(color_list, "blue");
  16. list.add(color_list, "red");
  17. list.add(color_list, "yellow");
  18. list.add(color_list, "green");
  19. list.add(color_list, "orange");
  20. list.add(color_list, "purple");
  21. list.add(color_list, "white");
  22. list.add(color_list, "black");
  23. list.add(color_list, "light_gray");
  24. list.add(color_list, "gray");
  25. list.add(color_list, "magenta");
  26. list.add(color_list, "brown");
  27. list.add(color_list, "lime");
  28. list.add(color_list, "cyan");
  29. list.add(color_list, "light_blue");
  30. list.add(color_list, "pink");
  31. wool_list = list.new();
  32. concrete_list = list.new();
  33. iter = list.iterator(color_list);
  34. while(hasNext(iter)) {
  35. color_string = next(iter);
  36. list.add(wool_list, concat("minecraft:", color_string, "_wool"));
  37. list.add(concrete_list, concat("minecraft:", color_string, "_concrete"));
  38. }
  39. @wait
  40. wait();
  41. if(event == "living_pre_hurt") {
  42. if(!isPlayer(living_entity)) {
  43. goto("wait");
  44. }
  45. player = living_entity;
  46. }
  47. if(player.hasMinigameId(player, script_id)) {
  48. ignoreGoto(event);
  49. }
  50. goto("wait");
  51. @player_join
  52. player_record = ranking.getPoints(rankingtable, player);
  53. server_record = ranking.getPointsFromRank(rankingtable, 1, "DESC", null);
  54. goto("newgame");
  55. @newgame
  56. index = math.random(0, 15);
  57. wool_block = list.getIndex(wool_list, index);
  58. concrete_block = list.getIndex(concrete_list, index);
  59. points = 0;
  60. display.reset(player);
  61. display.add(player, 0, "§6Jump'n'Run");
  62. display.add(player, 1, "Your Points: §e", text.number(points));
  63. updateDisplayRecords(player, player_record, server_record);
  64. player.setGamemode(player, "adventure");
  65. title.clear(player);
  66. title.setTime(player, 20, 20, 20);
  67. title.send(player, gamename);
  68. player.clearInventory(player);
  69. living.setHealth(player, 20);
  70. player.setHunger(player, 20);
  71. player.setSaturation(player, 5);
  72. x = math.random(5000, 5100);
  73. z = math.random(5000, 5100);
  74. previous_loc = loc.new(world.get("games"), x, 15, z);
  75. entity.teleport(player, loc.mod(previous_loc, 0.5, 1, 0.5));
  76. goto("newblock");
  77. @newblock
  78. a = getRelativeJumpCoords();
  79. new_loc = getNewLoc(previous_loc, a[0], a[1], a[2]);
  80. block.set(new_loc, wool_block);
  81. block.set(previous_loc, concrete_block);
  82. sound.spawn(new_loc, jump_sound, sound_category_ambient);
  83. setMoveEvent(new_loc, player.getUuid(player));
  84. goto("wait");
  85. @living_pre_hurt
  86. cancel = true;
  87. damage_source_type = damage.getType(damage_source);
  88. if(damage_source_type == "outOfWorld") {
  89. //sollte der spieler durch das auffangnetz MoveData:fall_id durchfallen und im Void landen, wird er zurückgesetzt
  90. resetBlocks(previous_loc, new_loc);
  91. showStats(player, points);
  92. goto("newgame");
  93. }
  94. goto("wait");
  95. @player_move
  96. if(id == fall_id) {
  97. resetBlocks(previous_loc, new_loc);
  98. showStats(player, points);
  99. goto("newgame");
  100. }
  101. block.set(previous_loc, "minecraft:air");
  102. previous_loc = new_loc;
  103. points++;
  104. display.add(player, 1, "Your Points: §e", text.number(points));
  105. player.setHunger(player, 20);
  106. player.setSaturation(player, 5);
  107. goto("newblock");
  108. @player_giveup
  109. @player_logout
  110. resetBlocks(previous_loc, new_loc);
  111. showStats(player, points);
  112. player.setGamemode(player, "survival");
  113. script = script.getFromId(script_id);
  114. minigame.kickPlayer(script, player);
  115. minigame.term(script, gamesignloc);
  116. term();
  117. function showStats(player, points) {
  118. minigame.addPlayed(player, $game_short, 1);
  119. minigame.statsHeader(player, $gamename, "§e");
  120. minigame.statsLine(player, "§e", "Points", text.number(points));
  121. if($player_record < points) {
  122. ranking.setPoints($rankingtable, player, points);
  123. minigame.statsLine(player, "§e", "Beat own record by", text.number(points - $player_record));
  124. $player_record = points;
  125. }
  126. if($player_record > $server_record) {
  127. $server_record = $player_record;
  128. }
  129. minigame.statsLine(player, "§e", "Your Record", text.number($player_record));
  130. minigame.statsLine(player, "§e", "Server Record", text.number($server_record));
  131. money.addBoost(player, math.round(points));
  132. }
  133. function resetBlocks(old_loc, new_loc) {
  134. block.set(old_loc, "minecraft:air");
  135. block.set(new_loc, "minecraft:air");
  136. }
  137. function updateDisplayRecords(player, player_record, server_record) {
  138. display.add(player, 2, "Your Record: §e", text.number(player_record));
  139. display.add(player, 3, "Server Record: §e", text.number(server_record));
  140. }
  141. function setMoveEvent(loc, player_uuid) {
  142. move_loc1 = loc.mod(loc, 0, 1, 0);
  143. move_loc2 = loc.mod(loc, 1, 2, 1);
  144. event.addMoveData(move_loc1, move_loc2, -1, -1, player_uuid);
  145. if($fall_id != null) {
  146. event.removeMoveData($fall_id);
  147. }
  148. fall_loc1 = loc.mod(move_loc1, -10, -10, -10);
  149. fall_loc2 = loc.mod(move_loc1, 10, -2, 10);
  150. $fall_id = event.addMoveData(fall_loc1, fall_loc2, -1, -1, player_uuid);
  151. }
  152. function getNewLoc(old_loc, x, y, z) {
  153. new_loc = loc.mod(old_loc, x, y, z);
  154. if(!block.isAir(new_loc)) {
  155. new_loc = getNewLoc(old_loc, x, y, z);
  156. }
  157. if(loc.getY(new_loc) > 256) {
  158. loc.setY(new_loc, 256);
  159. }
  160. return new_loc;
  161. }
  162. function getRelativeJumpCoords() {
  163. y = math.random(0, 1);
  164. x = math.random(0, 4);
  165. if(y == 0) {
  166. if(x < 2) {
  167. z = math.random(2, 4);
  168. } elseif(x < 4) {
  169. z = math.random(0, 4);
  170. } elseif(x == 4) {
  171. z = math.random(0, 3);
  172. }
  173. } else {
  174. if(x == 0) {
  175. z = math.random(2, 4);
  176. } elseif(x == 1) {
  177. z = math.random(2, 3);
  178. } elseif(x < 4) {
  179. z = math.random(0, 3);
  180. } elseif(x == 4) {
  181. z = 0;
  182. }
  183. }
  184. x = randomSign(x);
  185. z = randomSign(z);
  186. a = array.new(3);
  187. a[0] = x;
  188. a[1] = y;
  189. a[2] = z;
  190. return a;
  191. }
  192. function randomSign(value) {
  193. sign = math.random(0, 1);
  194. if(sign == 0) {
  195. return value *= -1;
  196. }
  197. return value;
  198. }