rebuild.txt 7.9 KB

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