fastbridge.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. placedblocks = list.new();
  2. points = list.new();
  3. spawn_locs = map.new();
  4. rankingtable = "fastbridgeranks";
  5. game_short = "fb";
  6. gamename = "§dFastBridge";
  7. specific_lobby_handling = true;
  8. no_core_reset = true;
  9. start_sound = sound.get("minecraft:block.note_block.harp");
  10. gosub("setstart");
  11. goto("simplelobby");
  12. @specificLobbyHandling
  13. if(event == "player_join") {
  14. entity.cleareffects(player);
  15. living.setHealth(player, 20);
  16. player.setHunger(player, 20);
  17. player.setSaturation(player, 5);
  18. player.clearInventory(player);
  19. display.reset(player);
  20. display.add(player, 0, gamename);
  21. display.add(player, 1, "§7Map:");
  22. display.add(player, 2, "§3", mapname);
  23. }
  24. return;
  25. @finalstart
  26. player_list = minigame.getPlayers(script_id);
  27. minigame.displayResetAll();
  28. minigame.displayAll(0, gamename);
  29. if(seconds < 10) {
  30. minigame.displayAll(1, concat("Time: ", text.number(minutes), ":0", text.number(seconds)));
  31. } else {
  32. minigame.displayAll(1, concat("TIme: ", text.number(minutes), ":", text.number(seconds)));
  33. }
  34. for(i = 0; i < list.getSize(player_list); i++) {
  35. p = player.get(list.getIndex(player_list, i));
  36. p_uuid = player.getUuid(p);
  37. msg.prefix(p, gamename, "The game has started.");
  38. spawnloc = list.getIndex(spawns, i);
  39. map.add(spawn_locs, p, spawnloc);
  40. entity.teleport(p, spawnloc);
  41. sound.spawnForPlayer(p, start_sound, sound_category_ambient);
  42. array = array.new(2);
  43. array[0] = p_uuid;
  44. array[1] = 0;
  45. list.add(points, array);
  46. player.setGamemode(p, "survival");
  47. player.setFly(p, false);
  48. title.clear(p);
  49. title.setTime(p, 0, 20, 0);
  50. }
  51. countdown = 5;
  52. @title
  53. for(i = 0; i < list.getSize(player_list); i++) {
  54. p = player.get(list.getIndex(player_list, i));
  55. title.send(p, concat("§4", text.number(countdown)));
  56. }
  57. if(countdown == 0) {
  58. sgoto(20, "loadevents");
  59. } else {
  60. sgoto(20, "title");
  61. countdown--;
  62. }
  63. @checkstart
  64. wait();
  65. if(event == "block_click") {
  66. cancel = true;
  67. }
  68. if(event == "player_logout" || event == "player_giveup") {
  69. removeFromPoints(player.getUuid(player));
  70. script = script.getFromId(script_id);
  71. minigame.kickPlayer(script, player);
  72. minigame.speakAll(gamename, concat(player.getName(player), " §rhas left the game."));
  73. if(list.getSize(player_list) < minplayers) {
  74. p = player.get(list.getIndex(player_list, 0));
  75. wincore(p);
  76. }
  77. }
  78. goto("checkstart");
  79. @loadevents
  80. minigame.speakAll(gamename, "Build faster than the others in one line.");
  81. event.load("player_post_respawn");
  82. sgoto(20, "loop");
  83. @checkgame
  84. wait();
  85. if(event == "living_pre_hurt") {
  86. if(!isPlayer(living_entity)) {
  87. goto("checkgame");
  88. }
  89. player = living_entity;
  90. }
  91. if(player.hasMinigameId(player, script_id)) {
  92. ignoreGoto(event);
  93. }
  94. goto("checkgame");
  95. @block_break
  96. cancel = true;
  97. goto("checkgame");
  98. @player_post_respawn
  99. entity.teleport(player, map.get(spawn_locs, player));
  100. goto("checkgame");
  101. @living_pre_hurt
  102. damage_type = damage.getType(damage_source);
  103. if(damage_type == "player") {
  104. cancel = true;
  105. }
  106. goto("checkgame");
  107. @loop
  108. if(seconds == 0) {
  109. seconds = 59;
  110. minutes--;
  111. if(minutes == -1) {
  112. sortPoints();
  113. array = list.getIndex(points, 0);
  114. winner = player.get(array[0]);
  115. for(i = 0; i < list.getSize(player_list); i++) {
  116. p = player.get(list.getIndex(player_list, i));
  117. if(p == winner) {
  118. money.addBoost(p, 64);
  119. } else {
  120. money.addBoost(p, 16);
  121. }
  122. }
  123. wincore(winner);
  124. }
  125. } else {
  126. seconds--;
  127. }
  128. if(seconds < 10) {
  129. minigame.displayAll(1, concat("Time: ", text.number(minutes), ":0", text.number(seconds)));
  130. } else {
  131. minigame.displayAll(1, concat("Time: ", text.number(minutes), ":", text.number(seconds)));
  132. }
  133. for(i = 0; i < list.getSize(player_list); i++) {
  134. item.drop(list.getIndex(spawns, i), list.getIndex(colors, i));
  135. ycheck = list.getIndex(ycheck_list, i);
  136. p = player.get(list.getIndex(player_list, i));
  137. y = loc.getY(entity.getLocation(p));
  138. if(y < ycheck) {
  139. entity.teleport(p, map.get(spawn_locs, p));
  140. entity.addEffect(p, "slowness", 240, 2);
  141. player.clearInventory(p);
  142. }
  143. }
  144. sgoto(20, "loop");
  145. goto("checkgame");
  146. @block_place
  147. spawnloc = map.get(spawn_locs, player);
  148. starty = loc.getY(spawnloc, "y") - 1;
  149. y = loc.getY(block_loc);
  150. if(starty == y) {
  151. startx = loc.getX(spawnloc, "x");
  152. startz = loc.getZ(spawnloc, "z");
  153. x = loc.getX(block_loc);
  154. z = loc.getZ(block_loc);
  155. if(coord == "x" && startx != x) {
  156. goto("cancelPlacement");
  157. } elseif(coord == "z" && startz != z) {
  158. goto("cancelPlacement");
  159. } else {
  160. cancel = false;
  161. raiseNumber(player.getUuid(player));
  162. list.add(placedblocks, block_loc);
  163. goto("checkgame");
  164. }
  165. }
  166. @cancelPlacement
  167. cancel = true;
  168. inv.update(player);
  169. goto("checkgame");
  170. @player_logout
  171. @player_giveup
  172. script = script.getFromId(script_id);
  173. minigame.kickPlayer(script, player);
  174. minigame.speakAll(gamename, concat(player.getName(player), " §rhas left the game."));
  175. if(list.getSize(player_list) < minplayers) {
  176. p = player.get(list.getIndex(player_list, 0));
  177. wincore(p);
  178. }
  179. goto("checkgame");
  180. function wincore(winner) {
  181. winner_name = player.getName(winner);
  182. minigame.speakAll($gamename, concat("§b", winner_name, " §rhas won!"));
  183. //Spielern das Inventar leeren, damit sie keine Blöcke mehr setzen können
  184. for(i = 0; i < list.getSize($player_list); i++) {
  185. player_uuid = list.getIndex($player_list, i);
  186. player = player.get(player_uuid);
  187. player.clearInventory(player);
  188. }
  189. //Blöcke resetten, während Spieler noch da sind, weil Chunks somit noch geladen sind
  190. for(i = 0; i < list.getSize($placedblocks); i++) {
  191. block.set(list.getIndex($placedblocks, i), "minecraft:air");
  192. }
  193. //Erst jetzt Spieler kicken/resetten/rausteleportieren
  194. for(i = 0; i < list.getSize($player_list); i++) {
  195. player_uuid = list.getIndex($player_list, i);
  196. player = player.get(player_uuid);
  197. player_id = player.getId(player);
  198. last_record = ranking.getPoints($rankingtable, player_id);
  199. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  200. minigame.setPlayed(player_id, $game_short, playedgames);
  201. record = getNumber(player_uuid);
  202. if(record < last_record) {
  203. record = last_record;
  204. }
  205. ranking.setPoints($rankingtable, player_id, record);
  206. fbwon = minigame.getWon(player, "fb");
  207. if(player == winner) {
  208. fbwon++;
  209. minigame.setWon(player, "fb", fbwon);
  210. }
  211. minigame.statsHeader(player, $gamename, "§e");
  212. for(h = 0; h < list.getSize($points); h++) {
  213. array = list.getIndex($points, h);
  214. msg(player, " §e- §r", text.number(array[1]), " §e", player.getName(array[0]));
  215. }
  216. msg(player, "");
  217. minigame.statsLine(player, "§e", "Won games", text.number(fbwon));
  218. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  219. if(playedgames != 0) {
  220. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((fbwon / playedgames) * 100, 2)), "%"));
  221. }
  222. }
  223. entity.removeAll("net.minecraft.entity.item.ItemEntity", $middleloc, $radius);
  224. script = script.getFromId($script_id);
  225. minigame.kickAllPlayers(script);
  226. minigame.term(script, $gamesignloc);
  227. }
  228. function removeFromPoints(player_uuid) {
  229. for(i = 0; i < list.getSize($points); i++) {
  230. array = list.getIndex($points, i);
  231. if(array[0] == player_uuid) {
  232. list.removeIndex($points, i);
  233. break;
  234. }
  235. }
  236. }
  237. function sortPoints() {
  238. size = list.getSize($points);
  239. swapped = true;
  240. while(swapped) {
  241. swapped = false;
  242. for(i = 0; i < size - 1; i++) {
  243. array = list.getIndex($points, i);
  244. array2 = list.getIndex($points, i + 1);
  245. zahl1 = array[1];
  246. zahl2 = array2[1];
  247. if(zahl1 < zahl2) {
  248. list.setIndex($points, i, array2);
  249. list.setIndex($points, i + 1, array);
  250. swapped = true;
  251. }
  252. }
  253. }
  254. }
  255. function raiseNumber(player_uuid) {
  256. for(i = 0; i < list.getSize($points); i++) {
  257. array = list.getIndex($points, i);
  258. if(array[0] == player_uuid) {
  259. array[1] = array[1] + 1;
  260. break;
  261. }
  262. }
  263. }
  264. function getNumber(player_uuid) {
  265. for(i = 0; i < list.getSize($points); i++) {
  266. array = list.getIndex($points, i);
  267. if(array[0] == player_uuid) {
  268. return array[1];
  269. }
  270. }
  271. }