volleyball.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. rankingtable = "Volleyranks";
  2. game_short = "Volley";
  3. specific_lobby_handling = true;
  4. no_core_reset = true;
  5. gamename = "§6Volleyball";
  6. colorcodes = map.new();
  7. map.add(colorcodes, 0, "§1");
  8. map.add(colorcodes, 1, "§4");
  9. teamcolortext = map.new();
  10. map.add(teamcolortext, 0, "§1blue");
  11. map.add(teamcolortext, 1, "§4red");
  12. teamcolortext2 = map.new();
  13. map.add(teamcolortext2, 0, "§1Blue");
  14. map.add(teamcolortext2, 1, "§4Red");
  15. team_lists = map.new(); //Map mit Spielerlisten für jedes Team
  16. map.add(team_lists, 0, list.new());
  17. map.add(team_lists, 1, list.new());
  18. players = map.new(); //Alle Spieler (key) des Spiels und deren Teamzugehörigkeit (value)
  19. playersinteam = map.new(); //Anzahl der Spieler im Team
  20. allteams = list.new(); //Alle Teams, die noch im Spiel sind
  21. waiters = list.new(); //Spieler in der Lobby ohne Teamzugehörigkeit
  22. points = map.new(); //Punktestand der Teams
  23. gosub("setstart");
  24. goto("simplelobby");
  25. randblock_x1 = 5; //vorerst weil noch keine map vorhanden ist
  26. randblock_x2 = -5;
  27. randblock_z1 = 5;
  28. randblock_z2 = -5;
  29. @specificLobbyHandling
  30. player_name = player.getName(player);
  31. if(event == "player_join") {
  32. list.add(waiters, player_name);
  33. living.setHealth(player, 20);
  34. player.setHunger(player, 20);
  35. player.setSaturation(player, 5);
  36. player.clearInventory(player);
  37. display.reset(player);
  38. display.add(player, 1, gamename);
  39. display.add(player, 2, mapname);
  40. display.add(player, 3, "Spieler: 2x6");
  41. return;
  42. }
  43. if(event == "player_logout" || event == "player_giveup") {
  44. list.remove(waiters, player_name);
  45. team = map.get(players, player_name);
  46. if(team != null) {
  47. teamlist = map.get(team_lists, team);
  48. list.remove(teamlist, player_name);
  49. }
  50. map.remove(players, player_name);
  51. return;
  52. }
  53. if(event == "block_click") {
  54. if(hand == "OFF_HAND" || action == "left") {
  55. return;
  56. }
  57. if(list.contains(joinblocks, block_loc)) {
  58. newteam = list.getIndexOf(joinblocks, block_loc);
  59. newteamlist = map.get(team_lists, newteam);
  60. if(list.contains(newteamlist, player_name)) {
  61. msg.prefix(player, gamename, "§eYou are already in this team.");
  62. return;
  63. }
  64. if(list.getSize(newteamlist) >= teamsize) {
  65. msg.prefix(player, gamename, "§eNo space for you in this team.");
  66. return;
  67. }
  68. list.remove(waiters, player_name);
  69. yetteam = map.get(players, player_name);
  70. if(yetteam != null) {
  71. yetteamlist = map.get(team_lists, yetteam);
  72. list.remove(yetteamlist, player_name);
  73. }
  74. list.add(newteamlist, player_name);
  75. map.add(players, player_name, newteam);
  76. msg.prefix(player, gamename, concat("§eYou joined the ", map.get(teamcolortext, newteam), " §eteam."));;
  77. }
  78. }
  79. return;
  80. @finalstart
  81. player_list = minigame.getPlayers(script_id);
  82. starttime = time.getMillis();
  83. event.load("player_toss");
  84. event.load("entity_click");
  85. event.load("living_pre_hurt");
  86. event.load("block_drop");
  87. while(list.getSize(waiters) != 0) {
  88. team = getTeamWithLowestPeople(team_lists, numberofteams);
  89. teamlist = map.get(team_lists, team);
  90. p_name = list.getIndex(waiters, 0);
  91. map.add(players, p_name, team);
  92. list.add(teamlist, p_name);
  93. list.remove(waiters, p_name);
  94. }
  95. minigame.displayAll(1, gamename);
  96. for(i = 0; i < numberofteams; i++) {
  97. teamlist = map.get(team_lists, i);
  98. size = list.getSize(teamlist);
  99. if(size != 0) {
  100. list.add(allteams, i);
  101. map.add(points, i);
  102. minigame.displayAll(i + 2, concat(map.get(teamcolortext2, i), " Points: ", text.number(points)));
  103. }
  104. }
  105. for(i = 0; i < list.getSize(player_list); i++) {
  106. p = player.get(list.getIndex(player_list, i));
  107. p_name = player.getName(p);
  108. msg.prefix(p, gamename, "The game has started.");
  109. team = map.get(players, p_name);
  110. player.setHunger(p, 20);
  111. player.setSaturation(p, 5);
  112. player.setGamemode(p, "survival");
  113. player.setFly(p, false);
  114. player.action(p, concat(map.get(colorcodes, team), "Team ", map.get(teamcolortext2, team)));
  115. stacks.clear(p);
  116. }
  117. for(team = 0; team < numberofteams; team++) {
  118. teamsize = map.get(playersinteam, team);
  119. if(teamsize != 0) {
  120. list.add(allteams, team);
  121. map.add(points, team, 0);
  122. }
  123. }
  124. //*Volleyball wäre möglich, Aufschlag ist droppen der rest ist klicken
  125. block_place/break wird verhindert, block_drop würde einen Punkt geben (Feld ist aus halfslabs
  126. -> immer blockdrop wenn block den boden berührt) location ist wichtig
  127. 2 Teams
  128. bei aufschlag player_move verhindern
  129. entity_click wird gezählt bei >3 für ein team bekommt das andere einen punkt und Aufschlag
  130. *//
  131. sgoto(20, "loop");
  132. @checkgame
  133. wait();
  134. if(player.hasMinigameId(player, script_id)) {
  135. ignoreGoto(event);
  136. }
  137. goto("checkgame");
  138. @Aufschlag
  139. teamlist = map.get(team_lists, team);
  140. p_uuid = list.getIndex(teamlist, math.random(0, list.getSize(teamlist) - 1));
  141. p = player.get(p_uuid);
  142. inv = player.getInv(p);
  143. inv.setItem(inv, 5, read.item("minecraft:bedrock"));
  144. goto("checkgame");
  145. @player_toss
  146. cancel = true;
  147. player = player;//*?*//
  148. //*player = living_entity; ist schon player?*//
  149. item = living.getEquip(player, "hand");
  150. item_type = item.getType(item);
  151. //*isblock(item_type) wäre benötigt um nicht einzelne Blöcke zu werfen?*//
  152. if(item_type == "minecraft:bedrock") {
  153. location = entity.getLocation(player);
  154. array = entity.getLook(player);
  155. array2 = entity.getMotion(player);
  156. x = array[0] * 1.5 + array2[0];
  157. y = array[1] * 1.5 + math.abs(array2[1]);
  158. z = array[2] * 1.5 + array2[2];
  159. block = entity.spawn(falling_block, location, {BlockState:{Name:"minecraft:bedrock"},Time:1,Motion:[0.0,1.0,0.0],DropItem:0,HurtEntities:1});
  160. entity.throw(block, x, y, z);
  161. player.removeItem(player, bedrock)
  162. }
  163. goto("checkgame");
  164. @entity_click
  165. block = entity.getType(entity);
  166. player = player;//*?*//
  167. if(block == falling_block){
  168. location = entity.getLocation(player);
  169. array = entity.getLook(player);
  170. array2 = entity.getMotion(player);
  171. x = array[0] * 1.5 + array2[0];
  172. y = array[1] * 1.5 + math.abs(array2[1]);
  173. z = array[2] * 1.5 + array2[2];
  174. entity.throw(block, x, y, z);
  175. }
  176. goto("checkgame");
  177. @living_pre_hurt
  178. block = damage_source;
  179. player = living_entity;
  180. cancel = true;
  181. if(block == falling_block){
  182. location_player = entity.getLocation(player);
  183. location_block = entity.getLocation(block);
  184. motion_player = entity.getMotion(block);
  185. motion_block = entity.getMotion(block);
  186. if(location_block[1]-location_player[1] < 1){
  187. x = motion_block[0] + motion_player[0]*0.5;
  188. y = math.abs(motion_block[1]) + math.abs(motion_player[1]*0.5);
  189. z = motion_block[2] + motion_player[2]*0.5;
  190. entity.throw(block, x, y, z);
  191. }else{
  192. x = -motion_block[0] + motion_player[0]*0.5;
  193. y = math.abs(motion_block[1]) + math.abs(motion_player[1]*0.5);
  194. z = -motion_block[2] + motion_player[2]*0.5;
  195. entity.throw(block, x, y, z);
  196. }
  197. }
  198. goto("checkgame");
  199. @block_drop
  200. loc = location;
  201. x = loc[0]
  202. if(x > middleloc){
  203. team = 0;
  204. team2 = 1;
  205. }else{
  206. team = 1;
  207. team2 = 0;
  208. }
  209. map.add(points, team, map.get(points, team) + 1);
  210. updateDisplay();
  211. minigame.speakAll(gamename,"§eThe ", map.get(teamcolortext2,team), "§eTeam scored a point.");
  212. if(map.get(points, team) == maxpoints){
  213. winning_team = team;
  214. goto("win");
  215. }
  216. goto("Aufschlag");
  217. @block_break
  218. @block_place
  219. cancel = true;
  220. goto("checkgame");
  221. @loop
  222. ent_loc = entity.getLocation(block);
  223. motion = entity.getMotion(block);
  224. if(ent_loc[0] >= randblock_x1 || ent_loc[0] <= randblock_x2){
  225. x = -motion[0];
  226. y = motion[1];
  227. z = motion[2];
  228. entity.throw(block, x, y, z);
  229. }
  230. if(ent_loc[2] >= randblock_z1 || ent_loc[2] <= randblock_z2){
  231. x = motion[0];
  232. y = motion[1];
  233. z = -motion[2];
  234. entity.throw(block, x, y, z);
  235. }
  236. sgoto(20, "loop");
  237. goto("checkgame");
  238. @player_giveup
  239. @player_logout
  240. player_name = player.getName(player);
  241. team = map.get(players, player_name);
  242. color = map.get(colorcodes, team);
  243. minigame.speakAll(gamename, concat(color, player_name, " §ehas left the game."));
  244. teamlist = map.get(team_lists, team);
  245. list.remove(teamlist, player_name);
  246. map.remove(players, player_name);
  247. script = script.getFromId(script_id);
  248. minigame.kickplayer(script, player);
  249. if(list.getSize(teamlist) == 0) {
  250. kickteam(team, true, false);
  251. winning_team = list.getIndex($allteams, 0);
  252. goto("win");
  253. }
  254. goto("checkgame");
  255. @win
  256. tempcolortext = map.get($teamcolortext, winning_team);
  257. minigame.speakAll($gamename, concat("§cThe ", tempcolortext, " §cTeam has Won."));
  258. list.remove($allteams, team);
  259. $endtime = time.getMillis();
  260. for(i = 0; i < list.getSize(player_list); i++) {
  261. player_uuid = list.getIndex(player_list, i);
  262. p = player.get(player_uuid);
  263. team = map.get(players, player_uuid);
  264. if(team == winning_team) {
  265. showstats(p, true, true);
  266. } else {
  267. showstats(p, true, false);
  268. }
  269. script = script.getFromId(script_id);
  270. minigame.kickPlayer(script, p);
  271. }
  272. minigame.kickAllPlayers(script);
  273. minigame.term(script, gamesignloc);
  274. term();
  275. function showstats(player, show_time, won) { //Player player, Boolean show_time, Boolean won
  276. player_name = player.getName(player);
  277. player_id = player.getId(player);
  278. last_record = ranking.getPoints($rankingtable, player_id);
  279. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  280. minigame.setPlayed(player_id, $game_short, playedgames);
  281. kills = map.get($kills_map, player_name);
  282. record = last_record + kills;
  283. ranking.setPoints($rankingtable, player_id, record);
  284. deaths = map.get($deaths_map, player_name);
  285. wongames = minigame.getWon(player, "snow");
  286. if(won) {
  287. wongames++;
  288. minigame.setWon(player, "snow", wongames);
  289. }
  290. minigame.statsHeader(player, $gamename, "§e");
  291. if(show_time) {
  292. time = ($endtime - $starttime) / 1000;
  293. minigame.statsLine(player, "§e", "Time", concat(text.number(math.rounddown(time / 60)), " min ", text.number(math.round(time % 60)), " s"));
  294. }
  295. minigame.statsLine(player, "§e", "Kills", text.number(kills));
  296. minigame.statsLine(player, "§e", "Deaths", text.number(deaths));
  297. if(deaths != 0) {
  298. kd = kills / deaths;
  299. minigame.statsLine(player, "§e", "K/D", text.number(math.roundcomma(kd, 2)));
  300. }
  301. minigame.statsLine(player, "§e", "Won games", text.number(wongames));
  302. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  303. if(playedgames != 0) {
  304. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
  305. }
  306. }
  307. function canStartGame() {
  308. if(list.getSize($waiters) > 0) {
  309. return true;
  310. }
  311. player_list = minigame.getPlayers(script_id);
  312. all_size = list.getSize(player_list);
  313. for(i = 0; i < $numberofteams; i++) {
  314. teamlist = map.get($team_lists, i);
  315. team_size = list.getSize(teamlist);
  316. if(team_size == all_size) {
  317. return false;
  318. }
  319. }
  320. return true;
  321. }