123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- rankingtable = "Volleyranks";
- game_short = "Volley";
- specific_lobby_handling = true;
- no_core_reset = true;
- gamename = "§6Volleyball";
- colorcodes = map.new();
- map.add(colorcodes, 0, "§1");
- map.add(colorcodes, 1, "§4");
- teamcolortext = map.new();
- map.add(teamcolortext, 0, "§1blue");
- map.add(teamcolortext, 1, "§4red");
- teamcolortext2 = map.new();
- map.add(teamcolortext2, 0, "§1Blue");
- map.add(teamcolortext2, 1, "§4Red");
- team_lists = map.new(); //Map mit Spielerlisten für jedes Team
- map.add(team_lists, 0, list.new());
- map.add(team_lists, 1, list.new());
- players = map.new(); //Alle Spieler (key) des Spiels und deren Teamzugehörigkeit (value)
- playersinteam = map.new(); //Anzahl der Spieler im Team
- allteams = list.new(); //Alle Teams, die noch im Spiel sind
- waiters = list.new(); //Spieler in der Lobby ohne Teamzugehörigkeit
- points = map.new(); //Punktestand der Teams
- gosub("setstart");
- goto("simplelobby");
- randblock_x1 = 5; //vorerst weil noch keine map vorhanden ist
- randblock_x2 = -5;
- randblock_z1 = 5;
- randblock_z2 = -5;
- @specificLobbyHandling
- player_name = player.getName(player);
- if(event == "player_join") {
- list.add(waiters, player_name);
- living.setHealth(player, 20);
- player.setHunger(player, 20);
- player.setSaturation(player, 5);
- player.clearInventory(player);
- display.reset(player);
- display.add(player, 1, gamename);
- display.add(player, 2, mapname);
- display.add(player, 3, "Spieler: 2x6");
- return;
- }
- if(event == "player_logout" || event == "player_giveup") {
- list.remove(waiters, player_name);
- team = map.get(players, player_name);
- if(team != null) {
- teamlist = map.get(team_lists, team);
- list.remove(teamlist, player_name);
- }
- map.remove(players, player_name);
- return;
- }
- if(event == "block_click") {
- if(hand == "OFF_HAND" || action == "left") {
- return;
- }
- if(list.contains(joinblocks, block_loc)) {
- newteam = list.getIndexOf(joinblocks, block_loc);
- newteamlist = map.get(team_lists, newteam);
- if(list.contains(newteamlist, player_name)) {
- msg.prefix(player, gamename, "§eYou are already in this team.");
- return;
- }
- if(list.getSize(newteamlist) >= teamsize) {
- msg.prefix(player, gamename, "§eNo space for you in this team.");
- return;
- }
- list.remove(waiters, player_name);
- yetteam = map.get(players, player_name);
- if(yetteam != null) {
- yetteamlist = map.get(team_lists, yetteam);
- list.remove(yetteamlist, player_name);
- }
- list.add(newteamlist, player_name);
- map.add(players, player_name, newteam);
- msg.prefix(player, gamename, concat("§eYou joined the ", map.get(teamcolortext, newteam), " §eteam."));;
- }
- }
- return;
- @finalstart
- player_list = minigame.getPlayers(script_id);
- starttime = time.getMillis();
- event.load("player_toss");
- event.load("entity_click");
- event.load("living_pre_hurt");
- event.load("block_drop");
- while(list.getSize(waiters) != 0) {
- team = getTeamWithLowestPeople(team_lists, numberofteams);
- teamlist = map.get(team_lists, team);
- p_name = list.getIndex(waiters, 0);
- map.add(players, p_name, team);
- list.add(teamlist, p_name);
- list.remove(waiters, p_name);
- }
- minigame.displayAll(1, gamename);
- for(i = 0; i < numberofteams; i++) {
- teamlist = map.get(team_lists, i);
- size = list.getSize(teamlist);
- if(size != 0) {
- list.add(allteams, i);
- map.add(points, i);
- minigame.displayAll(i + 2, concat(map.get(teamcolortext2, i), " Points: ", text.number(points)));
- }
- }
- for(i = 0; i < list.getSize(player_list); i++) {
- p = player.get(list.getIndex(player_list, i));
- p_name = player.getName(p);
- msg.prefix(p, gamename, "The game has started.");
- team = map.get(players, p_name);
- player.setHunger(p, 20);
- player.setSaturation(p, 5);
- player.setGamemode(p, "survival");
- player.setFly(p, false);
- player.action(p, concat(map.get(colorcodes, team), "Team ", map.get(teamcolortext2, team)));
- stacks.clear(p);
- }
- for(team = 0; team < numberofteams; team++) {
- teamsize = map.get(playersinteam, team);
- if(teamsize != 0) {
- list.add(allteams, team);
- map.add(points, team, 0);
- }
- }
- //*Volleyball wäre möglich, Aufschlag ist droppen der rest ist klicken
- block_place/break wird verhindert, block_drop würde einen Punkt geben (Feld ist aus halfslabs
- -> immer blockdrop wenn block den boden berührt) location ist wichtig
- 2 Teams
- bei aufschlag player_move verhindern
- entity_click wird gezählt bei >3 für ein team bekommt das andere einen punkt und Aufschlag
- *//
- sgoto(20, "loop");
- @checkgame
- wait();
- if(player.hasMinigameId(player, script_id)) {
- ignoreGoto(event);
- }
- goto("checkgame");
- @Aufschlag
- teamlist = map.get(team_lists, team);
- p_uuid = list.getIndex(teamlist, math.random(0, list.getSize(teamlist) - 1));
- p = player.get(p_uuid);
- inv = player.getInv(p);
- inv.setItem(inv, 5, read.item("minecraft:bedrock"));
- goto("checkgame");
- @player_toss
- cancel = true;
- player = player;//*?*//
- //*player = living_entity; ist schon player?*//
- item = living.getEquip(player, "hand");
- item_type = item.getType(item);
- //*isblock(item_type) wäre benötigt um nicht einzelne Blöcke zu werfen?*//
- if(item_type == "minecraft:bedrock") {
- location = entity.getLocation(player);
- array = entity.getLook(player);
- array2 = entity.getMotion(player);
- x = array[0] * 1.5 + array2[0];
- y = array[1] * 1.5 + math.abs(array2[1]);
- z = array[2] * 1.5 + array2[2];
- block = entity.spawn(falling_block, location, {BlockState:{Name:"minecraft:bedrock"},Time:1,Motion:[0.0,1.0,0.0],DropItem:0,HurtEntities:1});
- entity.throw(block, x, y, z);
- player.removeItem(player, bedrock)
- }
- goto("checkgame");
- @entity_click
- block = entity.getType(entity);
- player = player;//*?*//
- if(block == falling_block){
- location = entity.getLocation(player);
- array = entity.getLook(player);
- array2 = entity.getMotion(player);
- x = array[0] * 1.5 + array2[0];
- y = array[1] * 1.5 + math.abs(array2[1]);
- z = array[2] * 1.5 + array2[2];
- entity.throw(block, x, y, z);
- }
- goto("checkgame");
- @living_pre_hurt
- block = damage_source;
- player = living_entity;
- cancel = true;
- if(block == falling_block){
- location_player = entity.getLocation(player);
- location_block = entity.getLocation(block);
- motion_player = entity.getMotion(block);
- motion_block = entity.getMotion(block);
- if(location_block[1]-location_player[1] < 1){
- x = motion_block[0] + motion_player[0]*0.5;
- y = math.abs(motion_block[1]) + math.abs(motion_player[1]*0.5);
- z = motion_block[2] + motion_player[2]*0.5;
- entity.throw(block, x, y, z);
- }else{
- x = -motion_block[0] + motion_player[0]*0.5;
- y = math.abs(motion_block[1]) + math.abs(motion_player[1]*0.5);
- z = -motion_block[2] + motion_player[2]*0.5;
- entity.throw(block, x, y, z);
- }
- }
- goto("checkgame");
- @block_drop
- loc = location;
- x = loc[0]
- if(x > middleloc){
- team = 0;
- team2 = 1;
- }else{
- team = 1;
- team2 = 0;
- }
- map.add(points, team, map.get(points, team) + 1);
- updateDisplay();
- minigame.speakAll(gamename,"§eThe ", map.get(teamcolortext2,team), "§eTeam scored a point.");
- if(map.get(points, team) == maxpoints){
- winning_team = team;
- goto("win");
- }
- goto("Aufschlag");
- @block_break
- @block_place
- cancel = true;
- goto("checkgame");
- @loop
- ent_loc = entity.getLocation(block);
- motion = entity.getMotion(block);
- if(ent_loc[0] >= randblock_x1 || ent_loc[0] <= randblock_x2){
- x = -motion[0];
- y = motion[1];
- z = motion[2];
- entity.throw(block, x, y, z);
- }
- if(ent_loc[2] >= randblock_z1 || ent_loc[2] <= randblock_z2){
- x = motion[0];
- y = motion[1];
- z = -motion[2];
- entity.throw(block, x, y, z);
- }
- sgoto(20, "loop");
- goto("checkgame");
- @player_giveup
- @player_logout
- player_name = player.getName(player);
- team = map.get(players, player_name);
- color = map.get(colorcodes, team);
- minigame.speakAll(gamename, concat(color, player_name, " §ehas left the game."));
- teamlist = map.get(team_lists, team);
- list.remove(teamlist, player_name);
- map.remove(players, player_name);
- script = script.getFromId(script_id);
- minigame.kickplayer(script, player);
- if(list.getSize(teamlist) == 0) {
- kickteam(team, true, false);
- winning_team = list.getIndex($allteams, 0);
- goto("win");
- }
- goto("checkgame");
- @win
- tempcolortext = map.get($teamcolortext, winning_team);
- minigame.speakAll($gamename, concat("§cThe ", tempcolortext, " §cTeam has Won."));
- list.remove($allteams, team);
- $endtime = time.getMillis();
- for(i = 0; i < list.getSize(player_list); i++) {
- player_uuid = list.getIndex(player_list, i);
- p = player.get(player_uuid);
- team = map.get(players, player_uuid);
- if(team == winning_team) {
- showstats(p, true, true);
- } else {
- showstats(p, true, false);
- }
- script = script.getFromId(script_id);
- minigame.kickPlayer(script, p);
- }
- minigame.kickAllPlayers(script);
- minigame.term(script, gamesignloc);
- term();
- function showstats(player, show_time, won) { //Player player, Boolean show_time, Boolean won
- player_name = player.getName(player);
- 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);
- kills = map.get($kills_map, player_name);
- record = last_record + kills;
- ranking.setPoints($rankingtable, player_id, record);
- deaths = map.get($deaths_map, player_name);
- wongames = minigame.getWon(player, "snow");
- if(won) {
- wongames++;
- minigame.setWon(player, "snow", wongames);
- }
-
- minigame.statsHeader(player, $gamename, "§e");
- if(show_time) {
- time = ($endtime - $starttime) / 1000;
- minigame.statsLine(player, "§e", "Time", concat(text.number(math.rounddown(time / 60)), " min ", text.number(math.round(time % 60)), " s"));
- }
- minigame.statsLine(player, "§e", "Kills", text.number(kills));
- minigame.statsLine(player, "§e", "Deaths", text.number(deaths));
- if(deaths != 0) {
- kd = kills / deaths;
- minigame.statsLine(player, "§e", "K/D", text.number(math.roundcomma(kd, 2)));
- }
- 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)), "%"));
- }
- }
- function canStartGame() {
- if(list.getSize($waiters) > 0) {
- return true;
- }
- player_list = minigame.getPlayers(script_id);
- all_size = list.getSize(player_list);
- for(i = 0; i < $numberofteams; i++) {
- teamlist = map.get($team_lists, i);
- team_size = list.getSize(teamlist);
- if(team_size == all_size) {
- return false;
- }
- }
- return true;
- }
|