123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- rankingtable = "knockranks";
- game_short = "knock";
- event.load("player_toss");
- event.load("function_key");
- event.load("living_hurt");
- kf_skills = list.new();
- addKnockfightSkill("Speed", "km:skill44", 30);
- addKnockfightSkill("JumpBoost", "km:skill15", 30);
- addKnockfightSkill("Slowness", "km:skill53", 30);
- addKnockfightSkill("Blindness", "km:skill55", 30);
- addKnockfightSkill("Kick", "km:skill9", 60);
- resettime = 180; //Zeit in Ticks, wie lange der letzte Schläger gehalten wird
- stick = read.item("minecraft:stick");
- enchantment.add(enchantment.get("minecraft:knockback"), stick, 2);
- resetblocks = list.new();
- gamename = "§cKnockFight";
- gosub("setstart");
- goto("simplelobby");
- @finalstart
- player_list = minigame.getPlayers(script_id);
- size = list.getSize(player_list);
- cooldown_map = map.new();
- lifes = map.new();
- lastdamage = map.new();
- knockedcounter = map.new();
- resetlist = list.new();
- for(i = 0; i < size; i++) {
- p_uuid = list.getIndex(player_list, i);
- p = player.get(p_uuid);
- msg.prefix(p, gamename, "The game has started.");
- resetplayer(p);
- entity.teleport(p, list.getIndex(startlocs, i));
- player.setGamemode(p, "survival");
- player.setFly(p, false);
- map.add(knockedcounter, p_uuid, 0);
- player.giveItem(p, stick);
- map.add(lastdamage, p_uuid, null);
- map.add(lifes, p_uuid, startlifes);
- setStackIcons(p);
- status.add(p, 0, "§cCooldowns");
- }
- gosub("updatedisplay");
- @checkgame
- wait();
- if(event == "living_hurt") {
- if(!isPlayer(living_entity)) {
- goto("checkgame");
- }
- player = living_entity;
- }
- if(player.hasMinigameId(player, script_id)) {
- player_name = player.getName(player);
- ignoreGoto(event);
- }
- goto("checkgame");
- @player_toss
- cancel = true;
- player.giveItem(player, item);
- goto("checkgame");
- @living_hurt
- player_uuid = player.getUuid(player);
- damage_type = damage.getType(damage_source);
- if(damage_type == "player") {
- sec_player = player.getFromDamageSource(damage_source);
- if(player.hasMinigameId(sec_player, script_id)) {
- cancel = true;
- player.setSaturation(sec_player, 5);
- map.add(lastdamage, player_uuid, player.getUuid(sec_player));
- list.add(resetlist, player_uuid);
- sgoto(resettime, "resetdamager");
- }
- goto("checkgame");
- }
- if(damage_type == "fall") {
- cancel = true;
- goto("checkgame");
- }
- if(damage_type == "outOfWorld") {
- cancel = true;
- player_uuid = player.getUuid(player);
- lastdamager_uuid = map.get(lastdamage, player_uuid);
- if(lastdamager_uuid == null) {
- minigame.speakAll(gamename, concat("§6", player_name, " §rfell."));
- } else {
- minigame.speakAll(gamename, concat("§6", player_name, " §rwas knocked down by §6", player.getName(lastdamager_uuid), "."));
- map.add(knockedcounter, lastdamager_uuid, map.get(knockedcounter, lastdamager_uuid) + 1);
- }
- entity.teleport(player, list.getIndex(startlocs, math.random(0, list.getSize(startlocs) - 1)));
- new_lifes = map.get(lifes, player_uuid) - 1;
- map.add(lifes, player_uuid, new_lifes);
- gosub("updatedisplay");
- if(new_lifes == 0) {
- minigame.speakAll(gamename, concat("§6", player_name, " §rhas been eliminated."));
- money.addBoost(player, 32);
- goto("leavegame");
- }
- }
- goto("checkgame");
- @block_break
- @block_place
- cancel = true;
- goto("checkgame");
- @function_key
- if(key > list.getSize(kf_skills)) {
- goto("checkgame");
- }
- skill = list.getIndex(kf_skills, key - 1);
- skill_name = skill[0];
- last_exe_time = getKfLastExeTime(player, skill_name);
- needed_cooldown = skill[2];
- now_time = time.getMillis();
- diff_time = math.roundUp((now_time - last_exe_time) / 1000);
- if(diff_time < needed_cooldown) {
- player.action(player, concat("§a", text.number(needed_cooldown - diff_time), "s cooldown left"));
- goto("checkgame");
- }
- if(key == 1) {
- entity.addEffect(player, "speed", 200, 1);
- } elseif(key == 2) {
- entity.addEffect(player, "jump_boost", 200, 2);
- } elseif(key == 3) {
- iter = list.iterator(player_list);
- while(hasNext(iter)) {
- p = player.get(next(iter));
- if(p != player) {
- entity.addEffect(p, "slowness", 160, 1);
- }
- }
- } elseif(key == 4) {
- iter = list.iterator(player_list);
- while(hasNext(iter)) {
- p = player.get(next(iter));
- if(p != player) {
- entity.addEffect(p, "blindness", 160, 1);
- }
- }
- } elseif(key == 5) {
- opp = player.getTargetEntity(player, 4, "net.minecraft.entity.player.PlayerEntity");
- if(opp == null) {
- player.action(player, "§aNo enemy targeted.");
- goto("checkgame");
- }
- array = entity.getLook(player);
- x = array[0] * 2;
- z = array[2] * 2;
- entity.throw(opp, x, 1, z);
- }
- setKfLastExeTime(player, skill_name);
- status.addTimed(player, key, needed_cooldown * 20, concat("Cooldown ", skill_name));
- minigame.speakAll(gamename, concat("§6", player_name, "§r used §2", skill_name, "."));
- goto("checkgame");
- @resetdamager
- map.add(lastdamage, list.getIndex(resetlist, 0), null);
- list.removeIndex(resetlist, 0);
- goto("checkgame");
- @player_giveup
- @player_logout
- minigame.speakAll(gamename, concat("§6", player_name, " §rhas left the game."));
- @leavegame
- script = script.getFromId(script_id);
- minigame.kickPlayer(script, player);
- gosub("updatedisplay");
- showstats(player, false);
- if(list.getSize(player_list) < minplayers) {
- winner = player.get(list.getIndex(player_list, 0));
- money.addBoost(winner, 128);
- showstats(winner, true);
- minigame.kickPlayer(script, winner);
- minigame.term(script, gamesignloc);
- term();
- }
- goto("checkgame");
- function setKfLastExeTime(player, skill_name) {
- player_uuid = player.getUuid(player);
- player_map = map.getOrDefault($cooldown_map, player_uuid, map.new());
- map.add(player_map, skill_name, time.getMillis());
- map.add($cooldown_map, player_uuid, player_map);
- }
- function getKfLastExeTime(player, skill_name) {
- player_map = map.get($cooldown_map, player.getUuid(player));
- if(player_map == null) {
- return 0;
- }
- return map.getOrDefault(player_map, skill_name, 0);
- }
- function setStackIcons(player) {
- for(h = 0; h < list.getSize($kf_skills); h++) {
- skill = list.getIndex($kf_skills, h);
- icon = skill[1];
- stacks.set(player, h, icon);
- }
- stacks.setActive(player, true);
- }
- function addKnockfightSkill(skill_name, icon, cooldown) {
- skill = array.new(3);
- skill[0] = skill_name;
- skill[1] = icon;
- skill[2] = cooldown; //s
- list.add($kf_skills, skill);
- }
- function showstats(player, won) { //showstats(Player player, Boolean won)
- player_name = player.getName(player);
- player_id = player.getId(player);
- playedgames = minigame.getPlayed(player_id, $game_short) + 1;
- minigame.setPlayed(player_id, $game_short, playedgames);
- last_record = ranking.getPoints($rankingtable, player_id);
- knockedplayers = map.get($knockedcounter, player.getUuid(player));
- points = last_record + knockedplayers;
- ranking.setPoints($rankingtable, player_id, points);
-
- wongames = minigame.getWon(player, "knock");
- if(won) {
- wongames++;
- minigame.setWon(player, "knock", wongames);
- winningtext = "Yes";
- } else {
- winningtext = "No";
- }
-
- minigame.statsHeader(player, $gamename, "§e");
- minigame.statsLine(player, "§e", "Kills", text.number(knockedplayers));
- minigame.statsLine(player, "§e", "Won games", text.number(wongames));
- minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
- if(playedgames != 0) {
- minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
- }
- minigame.statsLine(player, "§e", "Won", winningtext);
- }
- @updatedisplay
- minigame.displayResetAll();
- minigame.displayAll(0, gamename);
- for(i = 0; i < list.getSize(player_list); i++) {
- p_uuid = list.getIndex(player_list, i);
- minigame.displayAll(i + 1, concat("§c", text.number(map.get(lifes, p_uuid)), " §r", player.getName(p_uuid)));
- }
- return;
|