123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- rankingtable = concat("invertranks", map);
- game_short = concat("inv", map);
- sign.started(gamesignloc);
- gamename = "§9Inverting";
- x1 = loc.getX(edge1);
- y1 = loc.getY(edge1);
- z1 = loc.getZ(edge1);
- x2 = loc.getX(edge2);
- y2 = loc.getY(edge2);
- z2 = loc.getZ(edge2);
- event.load("block_break");
- event.load("block_click");
- event.load("player_giveup");
- event.load("player_logout");
- event.load("player_join");
- event.load("living_pre_hurt");
- @wait
- wait();
- if(event == "living_pre_hurt") {
- if(!isPlayer(living_entity)) {
- goto("wait");
- }
- player = living_entity;
- }
- if(!player.hasMinigameId(player, script_id)) {
- goto("wait");
- }
- if(event == "living_pre_hurt") {
- cancel = true;
- goto("wait");
- }
- if(event == "player_join") {
- entity.teleport(player, tploc);
- entity.cleareffects(player);
- living.setHealth(player, 20);
- player.setHunger(player, 20);
- player.setSaturation(player, 5);
- player.clearInventory(player);
- player.setGamemode(player, "survival");
- player.setFly(player, true);
- lapis_block_type = "minecraft:lapis_block";
- redstone_block_type = "minecraft:redstone_block";
- gosub("newfield");
- fields = xlength * zlength;
- goto("wait");
- }
- if(event == "player_giveup" || event == "player_logout") {
- player.setFly(player, false);
- script = script.getFromId(script_id);
- minigame.kickPlayer(script, player);
- minigame.term(script, gamesignloc);
- term();
- }
- if(event == "block_break") {
- cancel = true;
- goto("wait");
- }
- if(event == "block_click") {
- if(hand == "OFF_HAND") {
- goto("wait");
- }
- tempx = loc.getCoord(block_loc, "x");
- tempy = loc.getCoord(block_loc, "y");
- tempz = loc.getCoord(block_loc, "z");
- if(tempy != y1) {
- goto("wait");
- }
- if(tempx < x1 || tempx > x2) {
- goto("wait");
- }
- if(tempz < z1 || tempz > z2) {
- goto("wait");
- }
- clicked++;
- display.add(player, 2, text.number(clicked));
- if(inverting(block_loc)) {
- goto("solved");
- }
- }
- goto("wait");
- @newfield
- display.reset(player);
- display.add(player, 0, gamename);
- display.add(player, 1, "Swaps:");
- clicked = 0;
- display.add(player, 2, text.number(clicked));
- renewing = true;
- for(i = 0; i <= iterations; i++) {
- centerloc = loc.new(gamesworld, math.random(x1, x2), y1, math.random(z1, z2));
- if(inverting(centerloc)) {
- goto("solved");
- }
- }
- renewing = false;
- return;
- function inverting(centerloc) {
- if($classic) {
- invertblock(centerloc);
- invertblock(loc.mod(centerloc, -1, 0, 0));
- invertblock(loc.mod(centerloc, 1, 0, 0));
- invertblock(loc.mod(centerloc, 0, 0, 1));
- invertblock(loc.mod(centerloc, 0, 0, -1));
- } else {
- for(x = -1; x <= 1; x++) {
- for(z = -1; z <= 1; z++) {
- invertblock(loc.mod(centerloc, x, 0, z));
- }
- }
- }
- if(!$renewing) {
- i = 0;
- edgeblock1 = block.getType($edge1);
- for(x = 0; x <= $xlength - 1; x++) {
- for(z = 0; z <= $zlength - 1; z++) {
- if(block.getType(loc.mod($edge1, x, 0, z)) != edgeblock1) {
- return false;
- }
- i++;
- }
- }
- if(i == $fields) {
- return true;
- }
- }
- return false;
- }
- function invertblock(loc) {
- if(block.getType(loc) == $lapis_block_type) {
- block.set(loc, $redstone_block_type);
- } elseif(block.getType(loc) == $redstone_block_type) {
- block.set(loc, $lapis_block_type);
- }
- return;
- }
- @solved
- player_id = player.getId(player);
- last_record = ranking.getPoints(rankingtable, player_id);
- playedgames = minigame.getPlayed(player_id, game_short) + 1;
- minigame.setPlayed(player_id, game_short, playedgames);
- if(last_record == 0 || clicked < last_record) {
- if(last_record != 0) {
- diff = last_record - clicked;
- }
- last_record = clicked;
- }
- ranking.setPoints(rankingtable, player_id, last_record);
- minigame.statsHeader(player, gamename, "§e");
- minigame.statsLine(player, "§e", "Swaps", text.number(clicked));
- minigame.statsLine(player, "§e", "Your record", text.number(last_record));
- if(diff != null) {
- msg(player, " §e- §rBeat own record by §e", text.number(diff));
- diff = null;
- }
- minigame.statsLine(player, "§e", "Won games", text.number(playedgames));
- money.addBoost(player, money);
- gosub("newfield");
- goto("wait");
|