snowfight.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. rankingtable = "snowranks";
  2. game_short = "snow";
  3. game_tab = "§6SNOW";
  4. specific_lobby_handling = true;
  5. no_core_reset = true;
  6. gamename = "§6Snowfight";
  7. snow_stack = read.item("minecraft:snowball", 16);
  8. colorcodes = map.new();
  9. map.add(colorcodes, 0, "§1");
  10. map.add(colorcodes, 1, "§4");
  11. map.add(colorcodes, 2, "§e");
  12. map.add(colorcodes, 3, "§2");
  13. teamcolortext = map.new();
  14. map.add(teamcolortext, 0, "§1blue");
  15. map.add(teamcolortext, 1, "§4red");
  16. map.add(teamcolortext, 2, "§eyellow");
  17. map.add(teamcolortext, 3, "§2green");
  18. teamcolortext2 = map.new();
  19. map.add(teamcolortext2, 0, "§1Blue");
  20. map.add(teamcolortext2, 1, "§4Red");
  21. map.add(teamcolortext2, 2, "§eYellow");
  22. map.add(teamcolortext2, 3, "§2Green");
  23. cloth_color = map.new();
  24. map.add(cloth_color, 0, 3361970);
  25. map.add(cloth_color, 1, 10040115);
  26. map.add(cloth_color, 2, 16701501);
  27. map.add(cloth_color, 3, 84395831);
  28. team_lists = map.new(); //Map mit Spielerlisten für jedes Team
  29. map.add(team_lists, 0, list.new());
  30. map.add(team_lists, 1, list.new());
  31. map.add(team_lists, 2, list.new());
  32. map.add(team_lists, 3, list.new());
  33. players = map.new(); //Alle Spieler (key) des Spiels und deren Teamzugehörigkeit (value)
  34. allteams = list.new(); //Alle Teams, die noch im Spiel sind
  35. waiters = list.new(); //Spieler in der Lobby ohne Teamzugehörigkeit
  36. lifes = map.new();
  37. nerf_map = map.new();
  38. kills_map = map.new();
  39. deaths_map = map.new();
  40. cooldown_map = map.new();
  41. gosub("setstart");
  42. goto("simplelobby");
  43. @specificLobbyHandling
  44. player_name = player.getName(player);
  45. if(event == "player_join") {
  46. list.add(waiters, player_name);
  47. map.add(nerf_map, player_name, 0);
  48. map.add(kills_map, player_name, 0);
  49. map.add(deaths_map, player_name, 0);
  50. living.setHealth(player, 20);
  51. player.setHunger(player, 20);
  52. player.setSaturation(player, 5);
  53. player.clearInventory(player);
  54. display.reset(player);
  55. display.add(player, 1, gamename);
  56. display.add(player, 2, mapname);
  57. display.add(player, 3, "Spieler: 2x10");
  58. return;
  59. }
  60. if(event == "player_logout" || event == "player_giveup") {
  61. list.remove(waiters, player_name);
  62. team = map.get(players, player_name);
  63. if(team != null) {
  64. teamlist = map.get(team_lists, team);
  65. list.remove(teamlist, player_name);
  66. }
  67. map.remove(players, player_name);
  68. return;
  69. }
  70. if(event == "block_click") {
  71. if(hand == "OFF_HAND" || action == "left") {
  72. return;
  73. }
  74. if(list.contains(joinblocks, block_loc)) {
  75. newteam = list.getIndexOf(joinblocks, block_loc);
  76. newteamlist = map.get(team_lists, newteam);
  77. if(list.contains(newteamlist, player_name)) {
  78. msg.prefix(player, gamename, "§eYou are already in this team.");
  79. return;
  80. }
  81. if(list.getSize(newteamlist) >= teamsize) {
  82. msg.prefix(player, gamename, "§eNo space for you in this team.");
  83. return;
  84. }
  85. list.remove(waiters, player_name);
  86. yetteam = map.get(players, player_name);
  87. if(yetteam != null) {
  88. yetteamlist = map.get(team_lists, yetteam);
  89. list.remove(yetteamlist, player_name);
  90. }
  91. list.add(newteamlist, player_name);
  92. map.add(players, player_name, newteam);
  93. msg.prefix(player, gamename, concat("§eYou joined the ", map.get(teamcolortext, newteam), " §eteam."));;
  94. }
  95. }
  96. return;
  97. @finalstart
  98. player_list = minigame.getPlayers(script_id);
  99. starttime = time.getMillis();
  100. event.load("projectile_hit");
  101. event.load("player_toss");
  102. event.load("item_air_click");
  103. event.load("living_drop");
  104. event.load("player_post_respawn");
  105. event.load("function_key");
  106. snow_skills = list.new();
  107. addSnowSkill("Snowball", "minecraft:snowball", 45);
  108. while(list.getSize(waiters) != 0) {
  109. team = getTeamWithLowestPeople(team_lists, numberofteams);
  110. teamlist = map.get(team_lists, team);
  111. p_name = list.getIndex(waiters, 0);
  112. map.add(players, p_name, team);
  113. list.add(teamlist, p_name);
  114. list.remove(waiters, p_name);
  115. }
  116. max = 1;
  117. for(i = 0; i < numberofteams; i++) {
  118. teamlist = map.get(team_lists, i);
  119. size = list.getSize(teamlist);
  120. if(size > max) {
  121. max = size;
  122. }
  123. }
  124. team_lifes = max * 10;
  125. minigame.displayAll(1, gamename);
  126. for(i = 0; i < numberofteams; i++) {
  127. teamlist = map.get(team_lists, i);
  128. size = list.getSize(teamlist);
  129. if(size != 0) {
  130. list.add(allteams, i);
  131. map.add(lifes, i, team_lifes);
  132. minigame.displayAll(i + 2, concat(map.get(teamcolortext2, i), " Lifes: ", text.number(team_lifes)));
  133. }
  134. }
  135. for(i = 0; i < list.getSize(player_list); i++) {
  136. p = player.get(list.getIndex(player_list, i));
  137. p_name = player.getName(p);
  138. msg.prefix(p, gamename, "The game has started.");
  139. team = map.get(players, p_name);
  140. giveSnowballs(p);
  141. player.setHunger(p, 20);
  142. player.setSaturation(p, 5);
  143. player.setGamemode(p, "survival");
  144. player.setFly(p, false);
  145. entity.teleport(p, map.get(spawnlocs, team));
  146. color = map.get(colorcodes, team);
  147. player.action(p, concat(color, "Team ", map.get(teamcolortext2, team)));
  148. stacks.clear(p);
  149. setStackIcons(p);
  150. equipPlayer(p, team);
  151. minigame.setTabName(p, game_tab, color);
  152. }
  153. sgoto(40, "loop");
  154. @checkgame
  155. wait();
  156. if(event == "living_pre_hurt" || event == "living_drop") {
  157. if(!isPlayer(living_entity)) {
  158. goto("checkgame");
  159. }
  160. player = living_entity;
  161. }
  162. if(event == "projectile_hit") {
  163. if(!isPlayer(shooter)) {
  164. goto("checkgame");
  165. }
  166. player = shooter;
  167. }
  168. if(player.hasMinigameId(player, script_id)) {
  169. player_name = player.getName(player);
  170. ignoreGoto(event);
  171. }
  172. goto("checkgame");
  173. @item_air_click
  174. player_item_type = item.getType(living.getEquip(player, "hand"));
  175. if(player_item_type == "minecraft:snowball") {
  176. for(i = 0; i < list.getSize(allteams); i++) {
  177. temp_team = list.getIndex(allteams, i);
  178. teamlist = map.get(team_lists, temp_team);
  179. if(!list.contains(teamlist, player_name)) {
  180. loc = map.get(spawnlocs, i);
  181. if(loc.distance(loc, entity.getLocation(player)) < nerfradius) {
  182. team = map.get(players, player_name);
  183. entity.addEffect(player, "wither", 200, 8);
  184. entity.addEffect(player, "slowness", 100, 3);
  185. nerf_counter = map.get(nerf_map, player_name);
  186. map.add(nerf_map, player_name, nerf_counter + 1);
  187. if(nerf_counter == 10) {
  188. map.add(nerf_map, player_name, 0);
  189. player.clearInventory(player);
  190. entity.cleareffects(player);
  191. giveSnowballs(player);
  192. entity.teleport(player, map.get(spawnlocs, team));
  193. map.add(deaths_map, player_name, map.get(deaths_map, player_name) + 1);
  194. new_lifes = map.get(lifes, team) - 1;
  195. map.add(lifes, team, new_lifes);
  196. minigame.displayAll(team + 2, concat(map.get(teamcolortext2, team), " Lifes: ", text.number(new_lifes)));
  197. }
  198. }
  199. }
  200. }
  201. }
  202. goto("checkgame");
  203. @projectile_hit
  204. if(entity_hit != null) {
  205. if(!isPlayer(entity_hit)) {
  206. goto("checkgame");
  207. }
  208. entity_hit_name = player.getName(entity_hit);
  209. if(!list.contains(player_list, player.getUuid(entity_hit))) {
  210. minigame.msgAll(concat("Illegal Player ", entity_hit_name));
  211. goto("checkgame");
  212. }
  213. if(!list.contains(player_list, player.getUuid(player))) {
  214. minigame.msgAll(concat("Illegal Player ", entity_hit_name));
  215. goto("checkgame");
  216. }
  217. team = map.get(players, player_name);
  218. hit_team = map.get(players, entity_hit_name);
  219. if(team == hit_team) {
  220. goto("checkgame"); //Friendly-Firedly-Fire
  221. }
  222. player.clearInventory(entity_hit);
  223. giveSnowballs(entity_hit);
  224. map.add(kills_map, player_name, map.get(kills_map, player_name) + 1);
  225. map.add(deaths_map, entity_hit_name, map.get(deaths_map, entity_hit_name) + 1);
  226. new_lifes = map.get(lifes, hit_team) - 1;
  227. map.add(lifes, hit_team, new_lifes);
  228. minigame.displayAll(hit_team + 2, concat(map.get(teamcolortext2, hit_team), " Lifes: ", text.number(new_lifes)));
  229. loc = map.get(spawnlocs, hit_team);
  230. entity.teleport(entity_hit, loc);
  231. if(new_lifes == 0) {
  232. colorgameover(hit_team);
  233. }
  234. }
  235. goto("checkgame");
  236. @function_key
  237. if(key > list.getSize(snow_skills)) {
  238. goto("checkgame");
  239. }
  240. skill = list.getIndex(snow_skills, key - 1);
  241. skill_name = skill[0];
  242. last_exe_time = getSnowLastExeTime(player, skill_name);
  243. needed_cooldown = skill[2];
  244. now_time = time.getMillis();
  245. diff_time = math.roundUp((now_time - last_exe_time) / 1000);
  246. if(diff_time < needed_cooldown) {
  247. player.action(player, concat("§a", text.number(needed_cooldown - diff_time), "s cooldown left"));
  248. goto("checkgame");
  249. }
  250. if(key == 1) {
  251. giveSnowballs(player);
  252. }
  253. setSnowLastExeTime(player, skill_name);
  254. status.addTimed(player, key, needed_cooldown * 20, concat("Cooldown ", skill_name));
  255. minigame.speakAll(gamename, concat("§6", player_name, "§r used §2", skill_name, "."));
  256. goto("checkgame");
  257. @player_post_respawn
  258. team = map.get(players, player_name);
  259. loc = map.get(spawnlocs, team);
  260. entity.teleports(player, loc);
  261. giveSnowballs(player);
  262. goto("checkgame");
  263. @living_drop
  264. list.clear(drops);
  265. goto("checkgame");
  266. @living_pre_hurt
  267. damage_type = damage.getType(damage_source);
  268. if(damage_type == "wither") {
  269. goto("checkgame");
  270. }
  271. cancel = true;
  272. goto("checkgame");
  273. @player_toss
  274. cancel = true;
  275. //inv.update(player);
  276. player.giveItem(player, item);
  277. goto("checkgame");
  278. @block_break
  279. @block_place
  280. cancel = true;
  281. goto("checkgame");
  282. @loop
  283. for(i = 0; i < list.getSize(player_list); i++) {
  284. p = player.get(list.getIndex(player_list, i));
  285. p_name = player.getName(p);
  286. team = map.get(players, p_name);
  287. player.setHunger(p, 20);
  288. player.setSaturation(p, 5);
  289. player.action(p, concat(map.get(colorcodes, team), "Team ", map.get(teamcolortext2, team)));
  290. equipPlayer(p, team);
  291. }
  292. sgoto(40, "loop");
  293. goto("checkgame");
  294. @player_giveup
  295. @player_logout
  296. team = map.get(players, player_name);
  297. color = map.get(colorcodes, team);
  298. minigame.speakAll(gamename, concat(color, player_name, " §ehas left the game."));
  299. teamlist = map.get(team_lists, team);
  300. list.remove(teamlist, player_name);
  301. map.remove(players, player_name);
  302. script = script.getFromId(script_id);
  303. minigame.kickplayer(script, player);
  304. if(list.getSize(teamlist) == 0) {
  305. colorgameover(team);
  306. }
  307. goto("checkgame");
  308. function colorgameover(team) {
  309. tempcolortext = map.get($teamcolortext, team);
  310. minigame.speakAll($gamename, concat("§cThe ", tempcolortext, " §cTeam has been eliminated."));
  311. list.remove($allteams, team);
  312. if(list.getSize($allteams) == 1) {
  313. $endtime = time.getMillis();
  314. kickteam(team, true, false);
  315. win_team = list.getIndex($allteams, 0);
  316. kickteam(win_team, true, true);
  317. entity.removeAll("net.minecraft.entity.item.ItemEntity", $middleloc, $radius);
  318. script = script.getFromId($script_id);
  319. minigame.term(script, $gamesignloc);
  320. term();
  321. }
  322. kickteam(team, false, false);
  323. }
  324. function kickteam(team, show_time, won) {
  325. teamlist = map.get($team_lists, team);
  326. for(i = 0; i < list.getSize(teamlist); i++) {
  327. p_name = list.getIndex(teamlist, i);
  328. p = read.player(p_name);
  329. showstats(p, show_time, won);
  330. script = script.getFromId($script_id);
  331. minigame.kickplayer(script, p);
  332. if(won) {
  333. money.addBoost(p, 128);
  334. } else {
  335. money.addBoost(p, 32);
  336. }
  337. }
  338. }
  339. function showstats(player, show_time, won) { //Player player, Boolean show_time, Boolean won
  340. player_name = player.getName(player);
  341. player_id = player.getId(player);
  342. last_record = ranking.getPoints($rankingtable, player_id);
  343. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  344. minigame.setPlayed(player_id, $game_short, playedgames);
  345. kills = map.get($kills_map, player_name);
  346. record = last_record + kills;
  347. ranking.setPoints($rankingtable, player_id, record);
  348. deaths = map.get($deaths_map, player_name);
  349. wongames = minigame.getWon(player, "snow");
  350. if(won) {
  351. wongames++;
  352. minigame.setWon(player, "snow", wongames);
  353. }
  354. minigame.statsHeader(player, $gamename, "§e");
  355. if(show_time) {
  356. time = ($endtime - $starttime) / 1000;
  357. minigame.statsLine(player, "§e", "Time", concat(text.number(math.rounddown(time / 60)), " min ", text.number(math.round(time % 60)), " s"));
  358. }
  359. minigame.statsLine(player, "§e", "Kills", text.number(kills));
  360. minigame.statsLine(player, "§e", "Deaths", text.number(deaths));
  361. if(deaths != 0) {
  362. kd = kills / deaths;
  363. minigame.statsLine(player, "§e", "K/D", text.number(math.roundcomma(kd, 2)));
  364. }
  365. minigame.statsLine(player, "§e", "Won games", text.number(wongames));
  366. minigame.statsLine(player, "§e", "Played games", text.number(playedgames));
  367. if(playedgames != 0) {
  368. minigame.statsLine(player, "§e", "Win ratio", concat(text.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
  369. }
  370. }
  371. function giveSnowballs(player) {
  372. player.giveItem(player, $snow_stack);
  373. player.giveItem(player, $snow_stack);
  374. player.giveItem(player, $snow_stack);
  375. player.giveItem(player, $snow_stack);
  376. }
  377. function equipPlayer(player, team) {
  378. if(item.getType(living.getEquip(player, "head")) == "minecraft:air") {
  379. color = map.get($cloth_color, team);
  380. living.setEquip(player, "head", read.item(concat("{id:'minecraft:leather_helmet',Count:1b,tag:{display:{color:", color, "}}}")));
  381. living.setEquip(player, "chest", read.item(concat("{id:'minecraft:leather_chestplate',Count:1b,tag:{display:{color:", color, "}}}")));
  382. living.setEquip(player, "legs", read.item(concat("{id:'minecraft:leather_leggings',Count:1b,tag:{display:{color:", color, "}}}")));
  383. living.setEquip(player, "feet", read.item(concat("{id:'minecraft:leather_boots',Count:1b,tag:{display:{color:", color, "}}}")));
  384. }
  385. }
  386. function setSnowLastExeTime(player, skill_name) {
  387. player_uuid = player.getUuid(player);
  388. player_map = map.getOrDefault($cooldown_map, player_uuid, map.new());
  389. map.add(player_map, skill_name, time.getMillis());
  390. map.add($cooldown_map, player_uuid, player_map);
  391. }
  392. function getSnowLastExeTime(player, skill_name) {
  393. player_map = map.get($cooldown_map, player.getUuid(player));
  394. if(player_map == null) {
  395. return 0;
  396. }
  397. return map.getOrDefault(player_map, skill_name, 0);
  398. }
  399. function setStackIcons(player) {
  400. for(h = 0; h < list.getSize($snow_skills); h++) {
  401. skill = list.getIndex($snow_skills, h);
  402. icon = skill[1];
  403. stacks.set(player, h, icon);
  404. }
  405. stacks.setActive(player, true);
  406. }
  407. function addSnowSkill(skill_name, icon, cooldown) {
  408. skill = array.new(3);
  409. skill[0] = skill_name;
  410. skill[1] = icon;
  411. skill[2] = cooldown; //s
  412. list.add($snow_skills, skill);
  413. }
  414. function canStartGame() {
  415. if(list.getSize($waiters) > 0) {
  416. return true;
  417. }
  418. player_list = minigame.getPlayers(script_id);
  419. all_size = list.getSize(player_list);
  420. for(i = 0; i < $numberofteams; i++) {
  421. teamlist = map.get($team_lists, i);
  422. team_size = list.getSize(teamlist);
  423. if(team_size == all_size) {
  424. return false;
  425. }
  426. }
  427. return true;
  428. }