volleyball.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. entity.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. player.setInvSlot(p, 5, "minecraft:bedrock");
  143. goto("checkgame");
  144. @player_toss
  145. cancel = true;
  146. player = player;//*?*//
  147. //*player = living_entity; ist schon player?*//
  148. item = entity.getEquip(player, "hand");
  149. item_type = item.getType(item);
  150. //*isblock(item_type) wäre benötigt um nicht einzelne Blöcke zu werfen?*//
  151. if(item_type == "minecraft:bedrock") {
  152. location = entity.getLocation(player);
  153. array = entity.getLook(player);
  154. array2 = entity.getMotion(player);
  155. x = array[0] * 1.5 + array2[0];
  156. y = array[1] * 1.5 + math.abs(array2[1]);
  157. z = array[2] * 1.5 + array2[2];
  158. block = entity.spawn(falling_block, location, {BlockState:{Name:"minecraft:bedrock"},Time:1,Motion:[0.0,1.0,0.0],DropItem:0,HurtEntities:1});
  159. entity.throw(block, x, y, z);
  160. player.removeItem(player, bedrock)
  161. }
  162. goto("checkgame");
  163. @entity_click
  164. block = entity.getType(entity);
  165. player = player;//*?*//
  166. if(block == falling_block){
  167. location = entity.getLocation(player);
  168. array = entity.getLook(player);
  169. array2 = entity.getMotion(player);
  170. x = array[0] * 1.5 + array2[0];
  171. y = array[1] * 1.5 + math.abs(array2[1]);
  172. z = array[2] * 1.5 + array2[2];
  173. entity.throw(block, x, y, z);
  174. }
  175. goto("checkgame");
  176. @living_pre_hurt
  177. block = damage_source;
  178. player = living_entity;
  179. cancel = true;
  180. if(block == falling_block){
  181. location_player = entity.getLocation(player);
  182. location_block = entity.getLocation(block);
  183. motion_player = entity.getMotion(block);
  184. motion_block = entity.getMotion(block);
  185. if(location_block[1]-location_player[1] < 1){
  186. x = motion_block[0] + motion_player[0]*0.5;
  187. y = math.abs(motion_block[1]) + math.abs(motion_player[1]*0.5);
  188. z = motion_block[2] + motion_player[2]*0.5;
  189. entity.throw(block, x, y, z);
  190. }else{
  191. x = -motion_block[0] + motion_player[0]*0.5;
  192. y = math.abs(motion_block[1]) + math.abs(motion_player[1]*0.5);
  193. z = -motion_block[2] + motion_player[2]*0.5;
  194. entity.throw(block, x, y, z);
  195. }
  196. }
  197. goto("checkgame");
  198. @block_drop
  199. loc = location;
  200. x = loc[0]
  201. if(x > middleloc){
  202. team = 0;
  203. team2 = 1;
  204. }else{
  205. team = 1;
  206. team2 = 0;
  207. }
  208. map.add(points, team, map.get(points, team) + 1);
  209. updateDisplay();
  210. minigame.speakAll(gamename,"§eThe ", map.get(teamcolortext2,team), "§eTeam scored a point.");
  211. if(map.get(points, team) == maxpoints){
  212. winning_team = team;
  213. goto("win");
  214. }
  215. goto("Aufschlag");
  216. @block_break
  217. @block_place
  218. cancel = true;
  219. goto("checkgame");
  220. @loop
  221. ent_loc = entity.getLocation(block);
  222. motion = entity.getMotion(block);
  223. if(ent_loc[0] >= randblock_x1 || ent_loc[0] <= randblock_x2){
  224. x = -motion[0];
  225. y = motion[1];
  226. z = motion[2];
  227. entity.throw(block, x, y, z);
  228. }
  229. if(ent_loc[2] >= randblock_z1 || ent_loc[2] <= randblock_z2){
  230. x = motion[0];
  231. y = motion[1];
  232. z = -motion[2];
  233. entity.throw(block, x, y, z);
  234. }
  235. sgoto(20, "loop");
  236. goto("checkgame");
  237. @player_giveup
  238. @player_logout
  239. player_name = player.getName(player);
  240. team = map.get(players, player_name);
  241. color = map.get(colorcodes, team);
  242. minigame.speakAll(gamename, concat(color, player_name, " §ehas left the game."));
  243. teamlist = map.get(team_lists, team);
  244. list.remove(teamlist, player_name);
  245. map.remove(players, player_name);
  246. script = script.getFromId(script_id);
  247. minigame.kickplayer(script, player);
  248. if(list.getSize(teamlist) == 0) {
  249. kickteam(team, true, false);
  250. winning_team = list.getIndex($allteams, 0);
  251. goto("win");
  252. }
  253. goto("checkgame");
  254. @win
  255. tempcolortext = map.get($teamcolortext, winning_team);
  256. minigame.speakAll($gamename, concat("§cThe ", tempcolortext, " §cTeam has Won."));
  257. list.remove($allteams, team);
  258. $endtime = time.getMillis();
  259. for(i = 0; i < list.getSize(player_list); i++) {
  260. player_uuid = list.getIndex(player_list, i);
  261. p = player.get(player_uuid);
  262. team = map.get(players, player_uuid);
  263. if(team == winning_team) {
  264. showstats(p, true, true);
  265. } else {
  266. showstats(p, true, false);
  267. }
  268. script = script.getFromId(script_id);
  269. minigame.kickPlayer(script, p);
  270. }
  271. minigame.kickAllPlayers(script);
  272. minigame.term(script, gamesignloc);
  273. term();
  274. function showstats(player, show_time, won) { //Player player, Boolean show_time, Boolean won
  275. player_name = player.getName(player);
  276. player_id = player.getId(player);
  277. last_record = ranking.getPoints($rankingtable, player_id);
  278. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  279. minigame.setPlayed(player_id, $game_short, playedgames);
  280. kills = map.get($kills_map, player_name);
  281. record = last_record + kills;
  282. ranking.setPoints($rankingtable, player_id, record);
  283. deaths = map.get($deaths_map, player_name);
  284. wongames = minigame.getWon(player, "snow");
  285. if(won) {
  286. wongames++;
  287. minigame.setWon(player, "snow", wongames);
  288. }
  289. minigame.statsHeader(player, $gamename, "§e");
  290. if(show_time) {
  291. time = ($endtime - $starttime) / 1000;
  292. minigame.statsLine(player, "§e", "Time", concat(text.number(math.rounddown(time / 60)), " min ", text.number(math.round(time % 60)), " s"));
  293. }
  294. minigame.statsLine(player, "§e", "Kills", text.number(kills));
  295. minigame.statsLine(player, "§e", "Deaths", text.number(deaths));
  296. if(deaths != 0) {
  297. kd = kills / deaths;
  298. minigame.statsLine(player, "§e", "K/D", text.number(math.roundcomma(kd, 2)));
  299. }
  300. minigame.statsLine(player, "§e", "Won games", text.number(wongames));
  301. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  302. if(playedgames != 0) {
  303. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
  304. }
  305. }
  306. function canStartGame() {
  307. if(list.getSize($waiters) > 0) {
  308. return true;
  309. }
  310. player_list = minigame.getPlayers(script_id);
  311. all_size = list.getSize(player_list);
  312. for(i = 0; i < $numberofteams; i++) {
  313. teamlist = map.get($team_lists, i);
  314. team_size = list.getSize(teamlist);
  315. if(team_size == all_size) {
  316. return false;
  317. }
  318. }
  319. return true;
  320. }