inverting.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. rankingtable = concat("invertranks", map);
  2. game_short = concat("inv", map);
  3. sign.started(gamesignloc);
  4. gamename = "§9Inverting";
  5. x1 = loc.getX(edge1);
  6. y1 = loc.getY(edge1);
  7. z1 = loc.getZ(edge1);
  8. x2 = loc.getX(edge2);
  9. y2 = loc.getY(edge2);
  10. z2 = loc.getZ(edge2);
  11. event.load("block_break");
  12. event.load("block_click");
  13. event.load("player_giveup");
  14. event.load("player_logout");
  15. event.load("player_join");
  16. event.load("living_pre_hurt");
  17. @wait
  18. wait();
  19. if(event == "living_pre_hurt") {
  20. if(!isPlayer(living_entity)) {
  21. goto("wait");
  22. }
  23. player = living_entity;
  24. }
  25. if(!player.hasMinigameId(player, script_id)) {
  26. goto("wait");
  27. }
  28. if(event == "living_pre_hurt") {
  29. cancel = true;
  30. goto("wait");
  31. }
  32. if(event == "player_join") {
  33. entity.teleport(player, tploc);
  34. entity.cleareffects(player);
  35. living.setHealth(player, 20);
  36. player.setHunger(player, 20);
  37. player.setSaturation(player, 5);
  38. player.clearInventory(player);
  39. player.setGamemode(player, "survival");
  40. player.setFly(player, true);
  41. lapis_block_type = "minecraft:lapis_block";
  42. redstone_block_type = "minecraft:redstone_block";
  43. gosub("newfield");
  44. fields = xlength * zlength;
  45. goto("wait");
  46. }
  47. if(event == "player_giveup" || event == "player_logout") {
  48. player.setFly(player, false);
  49. script = script.getFromId(script_id);
  50. minigame.kickPlayer(script, player);
  51. minigame.term(script, gamesignloc);
  52. term();
  53. }
  54. if(event == "block_break") {
  55. cancel = true;
  56. goto("wait");
  57. }
  58. if(event == "block_click") {
  59. if(hand == "OFF_HAND") {
  60. goto("wait");
  61. }
  62. tempx = loc.getCoord(block_loc, "x");
  63. tempy = loc.getCoord(block_loc, "y");
  64. tempz = loc.getCoord(block_loc, "z");
  65. if(tempy != y1) {
  66. goto("wait");
  67. }
  68. if(tempx < x1 || tempx > x2) {
  69. goto("wait");
  70. }
  71. if(tempz < z1 || tempz > z2) {
  72. goto("wait");
  73. }
  74. clicked++;
  75. display.add(player, 2, text.number(clicked));
  76. if(inverting(block_loc)) {
  77. goto("solved");
  78. }
  79. }
  80. goto("wait");
  81. @newfield
  82. display.reset(player);
  83. display.add(player, 0, gamename);
  84. display.add(player, 1, "Swaps:");
  85. clicked = 0;
  86. display.add(player, 2, text.number(clicked));
  87. renewing = true;
  88. for(i = 0; i <= iterations; i++) {
  89. centerloc = loc.new(gamesworld, math.random(x1, x2), y1, math.random(z1, z2));
  90. if(inverting(centerloc)) {
  91. goto("solved");
  92. }
  93. }
  94. renewing = false;
  95. return;
  96. function inverting(centerloc) {
  97. if($classic) {
  98. invertblock(centerloc);
  99. invertblock(loc.mod(centerloc, -1, 0, 0));
  100. invertblock(loc.mod(centerloc, 1, 0, 0));
  101. invertblock(loc.mod(centerloc, 0, 0, 1));
  102. invertblock(loc.mod(centerloc, 0, 0, -1));
  103. } else {
  104. for(x = -1; x <= 1; x++) {
  105. for(z = -1; z <= 1; z++) {
  106. invertblock(loc.mod(centerloc, x, 0, z));
  107. }
  108. }
  109. }
  110. if(!$renewing) {
  111. i = 0;
  112. edgeblock1 = block.getType($edge1);
  113. for(x = 0; x <= $xlength - 1; x++) {
  114. for(z = 0; z <= $zlength - 1; z++) {
  115. if(block.getType(loc.mod($edge1, x, 0, z)) != edgeblock1) {
  116. return false;
  117. }
  118. i++;
  119. }
  120. }
  121. if(i == $fields) {
  122. return true;
  123. }
  124. }
  125. return false;
  126. }
  127. function invertblock(loc) {
  128. if(block.getType(loc) == $lapis_block_type) {
  129. block.set(loc, $redstone_block_type);
  130. } elseif(block.getType(loc) == $redstone_block_type) {
  131. block.set(loc, $lapis_block_type);
  132. }
  133. return;
  134. }
  135. @solved
  136. player_id = player.getId(player);
  137. last_record = ranking.getPoints(rankingtable, player_id);
  138. playedgames = minigame.getPlayed(player_id, game_short) + 1;
  139. minigame.setPlayed(player_id, game_short, playedgames);
  140. if(last_record == 0 || clicked < last_record) {
  141. if(last_record != 0) {
  142. diff = last_record - clicked;
  143. }
  144. last_record = clicked;
  145. }
  146. ranking.setPoints(rankingtable, player_id, last_record);
  147. minigame.statsHeader(player, gamename, "§e");
  148. minigame.statsLine(player, "§e", "Swaps", text.number(clicked));
  149. minigame.statsLine(player, "§e", "Your record", text.number(last_record));
  150. if(diff != null) {
  151. msg(player, " §e- §rBeat own record by §e", text.number(diff));
  152. diff = null;
  153. }
  154. minigame.statsLine(player, "§e", "Won games", text.number(playedgames));
  155. money.addBoost(player, money);
  156. gosub("newfield");
  157. goto("wait");