rebuild.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. rankingtable = "rebuildranks";
  2. game_short = "rebuild";
  3. gamename = "§5Rebuild";
  4. specific_lobby_handling = true;
  5. no_core_reset = true;
  6. gosub("setstart");
  7. goto("simplelobby");
  8. @specificLobbyHandling
  9. if(event == "player_join") {
  10. entity.cleareffects(player);
  11. living.setHealth(player, 20);
  12. player.setHunger(player, 20);
  13. player.setSaturation(player, 5);
  14. player.clearInventory(player);
  15. display.reset(player);
  16. display.add(player, 1, gamename);
  17. display.add(player, 2, "§7Map:");
  18. display.add(player, 3, mapname);
  19. }
  20. return;
  21. @finalstart
  22. player_list = minigame.getPlayers(script_id);
  23. buildingarea = map.new();
  24. solved = map.new();
  25. check_list = list.new();
  26. if(list.getSize(player_list) == 1) {
  27. singleteam = true;
  28. for(i = 0; i < list.getSize(player_list); i++) {
  29. p = player.get(list.getIndex(player_list, i));
  30. msg.prefix(p, gamename, "Singleteam. Not ranked");
  31. }
  32. } else {
  33. singleteam = false;
  34. }
  35. for(i = 0; i < list.getSize(player_list); i++) {
  36. p_uuid = list.getIndex(player_list, i);
  37. p = player.get(p_uuid);
  38. map.add(solved, p_uuid, 0);
  39. msg.prefix(p, gamename, "The game has started.");
  40. list = list.new();
  41. map.add(buildingarea, p_uuid, list);
  42. edge = list.getIndex(bottom_edge, i);
  43. for(z = 0; z < picture_length; z++) {
  44. for(x = 0; x < picture_length; x++) {
  45. list.add(list, loc.mod(edge, x * -1, 0, z));
  46. }
  47. }
  48. }
  49. minigame.displayResetAll();
  50. minigame.displayAll(1, gamename);
  51. tobuild = list.getIndex(to_build_edges, 0);
  52. for(i = 0; i < list.getSize(player_list); i++) {
  53. p_uuid = list.getIndex(player_list, i);
  54. p = player.get(p_uuid);
  55. pname = player.getName(p);
  56. minigame.displayAll(i + 2, concat("§6", 0, " §c", pname));
  57. entity.teleport(p, list.getIndex(spawns, i));
  58. sound.spawnForPlayer(p, pling_sound, sound_category_ambient);
  59. player.setGamemode(p, "creative");
  60. title.clear(p);
  61. title.setTime(p, 0, 20, 0);
  62. //Vorlagen und Barriers setzen
  63. edge = list.getIndex(picture_edge, i); //Die erste Vorlage bekommt jeder
  64. for(y = 0; y < picture_length; y++) {
  65. for(x = 0; x > picture_length * -1; x--) {
  66. block.clone(loc.mod(tobuild, x, y, 0), loc.mod(edge, x, y, 0));
  67. block.set(loc.mod(edge, x, y, -1), "minecraft:barrier");
  68. }
  69. }
  70. }
  71. countdown = 5;
  72. @title
  73. for(i = 0; i < list.getSize(player_list); i++) {
  74. p = player.get(list.getIndex(player_list, i));
  75. title.send(p, concat("§c", text.number(countdown)));
  76. }
  77. if(countdown == 0) {
  78. sgoto(20, "setstarttime");
  79. } else {
  80. sgoto(20, "title");
  81. countdown--;
  82. }
  83. @checkstart
  84. wait();
  85. if(event == "block_click") {
  86. cancel = true;
  87. goto("checkstart");
  88. }
  89. if(event == "player_giveup" || event == "player_logout") {
  90. minigame.speakAll(gamename, concat("§6", player.getName(player), " §rhas left the game."));
  91. player.setGamemode(player, "survival");
  92. list = map.get(buildingarea, player.getUuid(player));
  93. for(i = 0; i < list.getSize(list); i++) {
  94. block.set(list.getIndex(list, i), "minecraft:air");
  95. }
  96. script = script.getFromId(script_id);
  97. minigame.kickplayer(script, player);
  98. if(list.getSize(player_list) < 2) {
  99. if(singleteam) {
  100. p = player;
  101. } else {
  102. p_uuid = list.getIndex(player_list, 0);
  103. p = player.get(p_uuid);
  104. }
  105. wincore(p);
  106. }
  107. }
  108. goto("checkstart");
  109. @setstarttime
  110. starttime = time.getMillis();
  111. for(i = 0; i < list.getSize(player_list); i++) {
  112. edge = list.getIndex(picture_edge, i);
  113. for(y = 0; y < picture_length; y++) {
  114. for(x = 0; x > picture_length * -1; x--) {
  115. block.set(loc.mod(edge, x, y, -1), "minecraft:air");
  116. }
  117. }
  118. }
  119. @checkgame
  120. wait();
  121. if(player.hasMinigameId(player, script_id)) {
  122. ignoreGoto(event);
  123. }
  124. goto("checkgame");
  125. @player_logout
  126. @player_giveup
  127. minigame.speakAll(gamename, concat("§6", player.getName(player), " §rhas left the game."));
  128. player.setGamemode(player, "survival");
  129. list = map.get(buildingarea, player.getUuid(player));
  130. for(i = 0; i < list.getSize(list); i++) {
  131. block.set(list.getIndex(list, i), "minecraft:air");
  132. }
  133. script = script.getFromId(script_id);
  134. minigame.kickplayer(script, player);
  135. if(list.getSize(player_list) < 2) {
  136. if(singleteam) {
  137. p = player;
  138. } else {
  139. p_uuid = list.getIndex(player_list, 0);
  140. p = player.get(p_uuid);
  141. }
  142. wincore(p);
  143. }
  144. goto("checkgame");
  145. @block_place
  146. @block_break
  147. player_uuid = player.getUuid(player);
  148. list = map.get(buildingarea, player_uuid);
  149. if(!list.contains(list, block_loc)) {
  150. cancel = true;
  151. goto("checkgame");
  152. }
  153. cancel = false;
  154. list.add(check_list, player_uuid);
  155. sgoto(2, "checkpicture");
  156. goto("checkgame");
  157. @checkpicture
  158. p_uuid = list.getIndex(check_list, 0);
  159. list.removeIndex(check_list, 0);
  160. p = player.get(p_uuid);
  161. temp_solved = map.get(solved, p_uuid);
  162. temploc = list.getIndex(bottom_check_edges, temp_solved);
  163. list = map.get(buildingarea, p_uuid);
  164. picture = list.getIndex(list, 0);
  165. for(z = 0; z < picture_length; z++) {
  166. for(x = 0; x > picture_length * -1; x--) {
  167. loc1 = loc.mod(temploc, x, 0, z);
  168. loc2 = loc.mod(picture, x, 0, z);
  169. if(block.getType(loc1) != block.getType(loc2)) {
  170. goto("checkgame");
  171. }
  172. }
  173. }
  174. temp_solved++;
  175. map.add(solved, p_uuid, temp_solved);
  176. player.clearInventory(p);
  177. for(i = 0; i < list.getSize(player_list); i++) {
  178. uuid = list.getIndex(player_list, i);
  179. minigame.displayAll(i + 2, concat("§6", text.number(map.get(solved, uuid)), "§c ", player.getName(uuid)));
  180. }
  181. if(temp_solved >= solve_to_win) {
  182. wincore(p);
  183. }
  184. list = map.get(buildingarea, p_uuid);
  185. for(i = 0; i < list.getSize(list); i++) {
  186. block.set(list.getIndex(list, i), "minecraft:air");
  187. }
  188. tobuild = list.getIndex(to_build_edges, temp_solved);
  189. edge = list.getIndex(picture_edge, list.getIndexOf(player_list, p_uuid));
  190. for(y = 0; y < picture_length; y++) {
  191. for(x = 0; x > picture_length * -1; x--) {
  192. block.clone(loc.mod(tobuild, x, y, 0), loc.mod(edge, x, y, 0));
  193. }
  194. }
  195. goto("checkgame");
  196. function wincore(winner) {
  197. winner_name = player.getName(winner);
  198. if(!$singleteam) {
  199. minigame.speakAll($gamename, concat("§b", winner_name, "§r has won!"));
  200. }
  201. for(h = 0; h < list.getSize($player_list); h++) {
  202. p_uuid = list.getIndex($player_list, h);
  203. list = map.get($buildingarea, p_uuid);
  204. for(i = 0; i < list.getSize(list); i++) {
  205. block.set(list.getIndex(list, i), "minecraft:air");
  206. }
  207. }
  208. for(i = 0; i < 5; i++) {
  209. edge = list.getIndex($picture_edge, i);
  210. for(y = 0; y < $picture_length; y++) {
  211. for(x = 0; x > $picture_length * -1; x--) {
  212. block.set(loc.mod(edge, x, y, 0), "minecraft:air");
  213. }
  214. }
  215. }
  216. entity.removeAll("net.minecraft.entity.item.ItemEntity", $middleloc, $radius);
  217. for(i = 0; i < list.getSize($player_list); i++) {
  218. p_uuid = list.getIndex($player_list, i);
  219. p = player.get(p_uuid);
  220. p_id = player.getId(p);
  221. player.setGamemode(p, "survival");
  222. if(!$singleteam) {
  223. last_record = ranking.getPoints($rankingtable, p_id);
  224. playedgames = minigame.getPlayed(p_id, $game_short) + 1;
  225. minigame.setPlayed(p_id, $game_short, playedgames);
  226. record = last_record + map.get($solved, p_uuid);
  227. ranking.setPoints($rankingtable, p_id, record);
  228. rebuildwon = minigame.getWon(p, "rebuild");
  229. if(p == winner) {
  230. rebuildwon++;
  231. minigame.setWon(p, "rebuild", rebuildwon);
  232. }
  233. msg(p, "");
  234. }
  235. minigame.statsHeader(p, $gamename, "§e");
  236. if($starttime != null) {
  237. endtime = time.getMillis();
  238. time = (endtime - $starttime) / 1000;
  239. minigame.statsLine(p, "§e", "Time", concat(text.number(math.round(time / 60)), " min ", text.number(math.round(time % 60)), " s"));
  240. }
  241. if(!$singleteam) {
  242. minigame.statsLine(p, "§e", "Solved Fields", text.number(record));
  243. minigame.statsLine(p, "§e", "Won games", text.number(rebuildwon));
  244. minigame.statsLine(p, "§e", "Played games", text.number(playedgames));
  245. if(playedgames != 0) {
  246. minigame.statsLine(p, "§e", "Win ratio", concat(text.number(math.roundComma((rebuildwon / playedgames) * 100, 2)), "%"));
  247. }
  248. }
  249. }
  250. script = script.getFromId($script_id);
  251. minigame.kickAllPlayers(script);
  252. minigame.term(script, $gamesignloc);
  253. term();
  254. }