capturetheflag.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. TODO und Ideen
  3. *) //edit
  4. *) sword wird nicht gegeben
  5. *) stats und rangliste einbauen
  6. *) removeitem bei resetflag (damals Bug)
  7. *) multiple teams
  8. *) ein gegneriches team wird ausgelöscht, wenn die eigene flagge UND die flagge des gegners in die eigene base gebracht wurde
  9. */
  10. rankingtable = "ctfranks";
  11. registerRanking(rankingtable);
  12. colorcodes = map.new();
  13. map.add(colorcodes, 0, "§9");
  14. map.add(colorcodes, 1, "§c");
  15. map.add(colorcodes, 2, "§e");
  16. map.add(colorcodes, 3, "§2");
  17. map.add(colorcodes, 4, "§6");
  18. map.add(colorcodes, 5, "§5");
  19. map.add(colorcodes, 6, "§d");
  20. map.add(colorcodes, 7, "§0");
  21. teamcolortext = map.new();
  22. map.add(teamcolortext, 0, "§9blue");
  23. map.add(teamcolortext, 1, "§cred");
  24. map.add(teamcolortext, 2, "§eyellow");
  25. map.add(teamcolortext, 3, "§2green");
  26. map.add(teamcolortext, 4, "§6orange");
  27. map.add(teamcolortext, 5, "§5magenta");
  28. map.add(teamcolortext, 6, "§dpink");
  29. map.add(teamcolortext, 7, "§0black");
  30. teamcolortext2 = map.new();
  31. map.add(teamcolortext2, 0, "§9Blue");
  32. map.add(teamcolortext2, 1, "§cRed");
  33. map.add(teamcolortext2, 2, "§eYellow");
  34. map.add(teamcolortext2, 3, "§2Green");
  35. map.add(teamcolortext2, 4, "§6Orange");
  36. map.add(teamcolortext2, 5, "§5Magenta");
  37. map.add(teamcolortext2, 6, "§dPink");
  38. map.add(teamcolortext2, 7, "§0Black");
  39. banners = map.new(); //Liste der Banner
  40. map.add(banners, 0, "minecraft:blue_banner");
  41. map.add(banners, 1, "minecraft:red_banner");
  42. map.add(banners, 2, "minecraft:yellow_banner");
  43. map.add(banners, 3, "minecraft:green_banner");
  44. map.add(banners, 4, "minecraft:orange_banner");
  45. map.add(banners, 5, "minecraft:purple_banner");
  46. map.add(banners, 6, "minecraft:pink_banner");
  47. map.add(banners, 7, "minecraft:black_banner");
  48. clothescode = map.new(); //Liste der Datenwerte für gefärbte Kleidung
  49. map.add(clothescode, 0, 5592575);
  50. map.add(clothescode, 1, 16733525);
  51. map.add(clothescode, 2, 16777045);
  52. map.add(clothescode, 3, 5635925);
  53. map.add(clothescode, 4, 16755200);
  54. map.add(clothescode, 5, 43690);
  55. map.add(clothescode, 6, 5592405);
  56. map.add(clothescode, 7, 0);
  57. gosub("setstart");
  58. air_item_type = "minecraft:air";
  59. air_item = read.item(air_item_type);
  60. minplayers = teamsize + 1;
  61. maxplayers = teamsize * numberofteams;
  62. compassitem = map.new(); //Map der Kompasse mit Namen
  63. teamlists = map.new(); //Map mit Spielerlisten für jedes Team
  64. for(team = 0; team < numberofteams; team++) {
  65. map.add(teamlists, team, list.new());
  66. map.add(compassitem, team, read.item("minecaft:compass", 1, concat(map.get(teamcolortext2, team), "e Flagge")));
  67. }
  68. all = list.new(); //Alle Spieler in der Quest
  69. waiters = list.new(); //Alle Spieler ohne ausgewähltem Team
  70. players = map.new(); //Alle Spieler mit ausgewähltem Team. Key: player_name / Value: Team
  71. compassmap = map.new(); //Auf welche Flagge zeigt der Kompass eines Spielers
  72. gamename = "§3CTF";
  73. player = script.getLeader();
  74. player_name = player.getName(player);
  75. gosub("lobbycore");
  76. goto("simplelobby");
  77. @lobby
  78. list.add(waiters, player_name);
  79. resetplayer(player);
  80. display.add(player, 0, gamename);
  81. display.add(player, 1, concat("§7Map: §b", mapname));
  82. display.add("all", 2, concat("§7Spieler: §r", text.number(list.getSize(all)), "/", text.number(maxplayers)));
  83. display.add(player, 3, concat("§7", text.number(numberofteams), " Teams"));
  84. if(ggv(player, "ctfwongames") == null) {
  85. sgv(player, "ctfwongames", 0);
  86. }
  87. if(ggv(player, "ctfstolenflags") == null) {
  88. sgv(player, "ctfstolenflags", 0);
  89. }
  90. return;
  91. @leavelobby
  92. list.remove(waiters, player_name);
  93. list.remove(getVar(map.get(players, player_name)), player_name);
  94. map.remove(players, player_name);
  95. return;
  96. @finalstart
  97. minigame.speakAll(gamename, "§rDas Spiel läuft.");
  98. size = list.getSize(all);
  99. block.setSign(gamesignloc, 2, concat(text.number(size), "/", text.number(maxplayers)));
  100. block.setSign(gamesignloc, 3, "§6Läuft");
  101. flagat = map.new(); //Wo befindet sich eine Flagge. Base/Gegnerische Base/Spieler/frei herumliegend
  102. flagatloc = map.new(); //Genaue Koordinaten, wo sich eine Flagge befindet
  103. for(team = 0; team < numberofteams; team++) {
  104. map.add(flagat, team, concat(map.get(colorcodes, team), "Base"));
  105. map.add(flagatloc, team, map.get(flaglocs, team));
  106. }
  107. //Spieler ohne Team einem Team zuweisen
  108. while(list.getSize(waiters) != 0) {
  109. team = getTeamWithLowestPeople();
  110. teamlist = map.get(teamlists, 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. flagcarrier = map.new();
  117. for(i = 0; i < size; i++) {
  118. p = list.getIndex(all, i);
  119. p_name = player.getName(p);
  120. team = map.get(players, p_name);
  121. entity.teleport(p, map.get(spawnlocs, team));
  122. map.add(compassmap, p_name, team);
  123. equipPlayer(p, team);
  124. map.add(flagcarrier, p_name, null);
  125. if(player.isSurvival(p)) {
  126. if(player.isAdventure(p)) {
  127. player.setGamemode(p, "survival");
  128. }
  129. } else {
  130. player.setGamemode(p, "survival");
  131. }
  132. if(player.hasFly(p)) {
  133. player.setFly(p, false);
  134. }
  135. }
  136. display.reset("all");
  137. display.add("all", 0, gamename);
  138. for(team = 0; team < numberofteams; team++) {
  139. templist = getVar(concat("flaglocs", team));
  140. for(h = 0; h < list.getSize(templist); h++) {
  141. tempflagloc = list.getIndex(templist, h);
  142. block.set(tempflagloc, air_item_type);
  143. event.addLoc(tempflagloc);
  144. }
  145. tempflagloc = list.getIndex(templist, 0);
  146. block.set2(tempflagloc, "standing_banner", map.get(flagdirection, tempflagloc), concat("{Base:", map.get(flagcolors, tempflagloc), "}"));
  147. display.add("all", i + 1, concat(map.get(teamcolortext2, team), "e Flagge: ", map.get(flagat, team)));
  148. }
  149. event.load("player_death");
  150. event.load("player_respawn");
  151. event.load("player_move");
  152. event.load("player_toss");
  153. event.load("player_pickup");
  154. event.load("item_air_click");
  155. event.load("player_giveup");
  156. event.load("player_logout");
  157. //sgoto(40, "loop");
  158. @checkgame
  159. wait();
  160. ignoreGoto(event);
  161. goto("wait");
  162. @item_air_click
  163. if(item.getType(living.getEquip(player, "hand")) == "COMPASS") {
  164. tempteamstring = map.get(compassmap, player_name);
  165. newtempteamstring = list.getIndex(allteams, list.getIndexOf(allteams, tempteamstring) + 1);
  166. tempcompass = map.get(compassitem, newtempteamstring);
  167. player.removeItem(player, item);
  168. player.giveItem(player, tempcompass);
  169. map.add(compassmap, player_name, newtempteamstring);
  170. player.setCompass(player, map.get(flagatloc, newtempteamstring));
  171. }
  172. goto("checkgame");
  173. @player_hurt
  174. if(player_involved) {
  175. if(map.get(players, player_name) == map.get(players, sec_player_name)) {
  176. cancel = true;
  177. }
  178. }
  179. goto("checkgame");
  180. @player_death
  181. player.respawn(player);
  182. tempteamstring = map.get(players, player_name);
  183. if(map.get(flagcarrier, player_name) == null) {
  184. goto("checkgame");
  185. }
  186. tempteamstring = map.get(flagcarrier, player_name);
  187. map.add(flagcarrier, player_name, null);
  188. player_loc = entity.getLocation(player);
  189. item.drop(player_loc, map.get(itembanner, tempteamstring));
  190. minigame.speakAll(gamename, concat("§rDie ", map.get(teamcolortext, tempteamstring), " §rFlagge wurde gedroppt."));
  191. map.add(flagat, tempteamstring, "§rGedroppt");
  192. map.add(flagatloc, tempteamstring, player_loc);
  193. display.add("all", list.getIndexOf(allteams, tempteamstring) + 1, concat(map.get(teamcolortext2, tempteamstring), " Flagge: ", map.get(flagat, tempteamstring)));
  194. setCompassNew(tempteamstring);
  195. goto("checkgame");
  196. @player_respawn
  197. tempteamstring = map.get(players, player_name);
  198. respawn_loc = map.get(spawnlocs, tempteamstring);
  199. command("clear ", player_name);
  200. equipPlayer(player, tempteamstring);
  201. goto("checkgame");
  202. @player_toss
  203. cancel = true;
  204. player.giveItem(player, item);
  205. goto("checkgame");
  206. @player_pickup
  207. if(item.getType(item) == "minecraft:banner") {
  208. tempteamstring = map.get(flagdata, item.getData(item));
  209. entity.remove(entity);
  210. goto("pickupflag");
  211. }
  212. goto("checkgame");
  213. @player_move
  214. moveloc = getMoveLocation(entity.getLocation(player));
  215. event.addLoc(moveloc);
  216. moveplayer = player_name;
  217. if(moveloc == oldmoveloc && moveplayer == oldmoveplayer) {
  218. goto("checkgame");
  219. }
  220. oldmoveloc = moveloc;
  221. oldmoveplayer = moveplayer;
  222. tempstack = block.toStack(moveloc);
  223. //Wenn ein Banner vorhanden ist
  224. if(item.getType(tempstack) == "minecraft:banner") {
  225. //Überprüfung, ob das Feld ein Ablagefeld des eigenen Teams ist
  226. tempteamstring = map.get(players, player_name);
  227. if(list.contains(getVar(concat("flaglocs", tempteamstring)), moveloc)) {
  228. goto("checkgame");
  229. }
  230. tempteamstring = map.get(flagdata, item.getData(tempstack));
  231. block.set(moveloc, air_item_type);
  232. goto("pickupflag");
  233. }
  234. //Wenn kein Banner vorhanden ist
  235. if(item.getType(tempstack) == "minecraft:air") {
  236. //Überprüfung, ob der Spieler ein Banner trägt
  237. if(map.get(flagcarrier, player_name) == null) {
  238. goto("checkgame");
  239. }
  240. //Überprüfung, ob das Feld ein Ablagefeld des eigenen Teams ist
  241. tempteamstring = map.get(players, player_name);
  242. if(!list.contains(getVar(concat("flaglocs", tempteamstring)), moveloc)) {
  243. goto("checkgame");
  244. }
  245. tempteamstring2 = map.get(flagcarrier, player_name);
  246. minigame.speakAll(gamename, concat("§rDie ", map.get(teamcolortext, tempteamstring2), " Flagge §rwurde von ", map.get(colorcodes, tempteamstring), "Team ", map.get(teamcolortext2, tempteamstring), " §rerobert"));
  247. block.set2(moveloc, "standing_banner", map.get(flagdirection, moveloc), concat("{Base:", map.get(flagcolors, moveloc), "}"));
  248. living.setEquip(player, "head", air_item);
  249. map.add(flagcarrier, player_name, null);
  250. map.add(flagat, tempteamstring2, concat(map.get(colorcodes, tempteamstring), "Base"));
  251. map.add(flagatloc, tempteamstring2, moveloc);
  252. display.add("all", list.getIndexOf(allteams, tempteamstring2) + 1, concat(map.get(teamcolortext2, tempteamstring2), "e Flagge: ", map.get(flagat, tempteamstring)));
  253. setCompassNew(tempteamstring2);
  254. //edit: wincheck
  255. }
  256. goto("checkgame");
  257. @block_break
  258. @block_place
  259. cancel = true;
  260. goto("checkgame");
  261. //Aktualisiert alle Kompasse, die auf dieses Team eingestellt sind
  262. function setCompassNew(tempteamstring) {
  263. for(i = 0; i < list.getSize($all); i++) {
  264. p = list.getIndex($all, i);
  265. p_name = player.getName(p);
  266. if(map.get($compassmap, p_name) == tempteamstring) {
  267. player.setCompass(p, map.get($flagatloc, tempteamstring));
  268. }
  269. }
  270. return;
  271. }
  272. function equipPlayer(player, tempteamstring) {
  273. clothescolor = map.get($clothescode, map.get(players, player_name));
  274. living.setEquip(player, "chest", read.item(concat("{id:\"minecraft:leather_chestplate\",Count:1b,tag:{display:{color:", clothescolor, "}}}")));
  275. player.giveItem(player, $sword);
  276. player.giveItem(player, $bow);
  277. player.giveItem(player, $food);
  278. player.giveItem(player, $gapple);
  279. player.giveItem(player, map.get($compassitem, tempteamstring));
  280. player.giveItem(player, $arrows);
  281. player.setCompass(player, map.get($flagatloc, map.get($compassmap, player.getName(player))));
  282. return;
  283. }
  284. //edit: Code unten alt
  285. /*@loop
  286. if(list.contains(all, bluecarrier)) {
  287. setVar("blueflagatloc", entity.getLocation(read.player(bluecarrier)));
  288. sgoto(1, "setbluecompassnew");
  289. }
  290. if(list.contains(all, redcarrier)) {
  291. setVar("redflagatloc", entity.getLocation(read.player(redcarrier)));
  292. sgoto(1, "setredcompassnew");
  293. }
  294. setVar("i", 0);
  295. @equip
  296. setVar("pname", list.getIndex(all, i));
  297. setVar("p", read.player(pname));
  298. if(list.contains(redteam, pname)) goto("equipred");
  299. living.setEquip(p, "head", read.item("{id:'minecraft:leather_helmet',Count:1b,tag:{display:{color:3361970}},Damage:0s}"));
  300. living.setEquip(p, "chest", read.item("{id:'minecraft:leather_chestplate',Count:1b,tag:{display:{color:3361970}},Damage:0s}"));
  301. living.setEquip(p, "legs", read.item("{id:'minecraft:leather_leggings',Count:1b,tag:{display:{color:3361970}},Damage:0s}"));
  302. living.setEquip(p, "feet", read.item("{id:'minecraft:leather_boots',Count:1b,tag:{display:{color:3361970}},Damage:0s}"));
  303. player.action(p, "§9Team Blau");
  304. if(less(inc("i"), list.getSize(all))) goto("equip");
  305. sgoto(40, "loop");
  306. goto("checkgame");
  307. @equipred
  308. living.setEquip(p, "head", read.item("{id:'minecraft:leather_helmet',Count:1b,tag:{display:{color:10040115}},Damage:0s}"));
  309. living.setEquip(p, "chest", read.item("{id:'minecraft:leather_chestplate',Count:1b,tag:{display:{color:10040115}},Damage:0s}"));
  310. living.setEquip(p, "legs", read.item("{id:'minecraft:leather_leggings',Count:1b,tag:{display:{color:10040115}},Damage:0s}"));
  311. living.setEquip(p, "feet", read.item("{id:'minecraft:leather_boots',Count:1b,tag:{display:{color:10040115}},Damage:0s}"));
  312. player.action(p, "§cTeam Rot");
  313. if(less(inc("i"), list.getSize(all))) goto("equip");
  314. sgoto(40, "loop");
  315. goto("checkgame");
  316. @blueflagloc
  317. if(and(list.contains(blueteam, player_name), equal(redcarrier, player_name))) goto("bluewin");
  318. if(and(list.contains(redteam, player_name), equal(blueflagat, "§rBase"))) goto("getblueflag");
  319. if(and(list.contains(blueteam, player_name), notequal(blueflagat, "§rBase"), equal(bluecarrier, player_name))) goto("resetblueflag");
  320. goto("checkgame");
  321. @resetblueflag
  322. player.removeItem(player, blueitembanner);
  323. block.clone(bluecopyflagloc, blueflagloc);
  324. event.addLoc(blueflagloc);
  325. setVar("blueflagat", "§rBase");
  326. setVar("blueflagatloc", blueflagloc);
  327. sb.add("all", 97, concat("§9Blaue Flagge: ", blueflagat));
  328. minigame.speakAll("§3CTF", "§rDie §9blaue §rFlagge ist wieder in ihrer Base.");
  329. goto("setbluecompassnew");
  330. @getblueflag
  331. setVar("color", "§c");
  332. block.set(blueflagloc, read.item("AIR"));
  333. player.giveItem(player, blueitembanner);
  334. event.addLoc(blueflagloc);
  335. goto("pickupblue");
  336. @redflagloc
  337. if(and(list.contains(redteam, player_name), equal(bluecarrier, player_name))) goto("redwin");
  338. if(and(list.contains(redteam, player_name), equal(redflagat, "§rBase"))) goto("addredflagloc");
  339. if(and(list.contains(blueteam, player_name), equal(redflagat, "§rBase"))) {
  340. block.set(entity.getLocation(player), air_item_type);
  341. //tempteamstring setzen
  342. living.setEquip(player, "head", map.get(itembanner, tempteamstring));
  343. goto("pickupred");
  344. }
  345. if(and(list.contains(redteam, player_name), notequal(redflagat, "§rBase"), equal(redcarrier, player_name))) goto("resetredflag");
  346. if(notequal(redflagat, "§rBase")) goto("addredflagloc");
  347. goto("checkgame");
  348. @addredflagloc
  349. event.addLoc(redflagloc);
  350. goto("checkgame");
  351. @resetflag
  352. living.setEquip(player, "head", air_item);
  353. block.clone(redcopyflagloc, redflagloc);
  354. setVar("redflagat", "§rBase");
  355. setVar("redflagatloc", redflagloc);
  356. sb.add("all", 96, concat("§cRote Flagge: ", redflagat));
  357. minigame.speakAll("§3CTF", "§rDie §crote §rFlagge ist wieder in der Base.");
  358. setCompassNew(tempteamstring);
  359. goto("checkgame");*/
  360. @pickupflag
  361. if(map.get(flagcarrier, player_name) != null) {
  362. msg.prefix(player, gamename, "§rDu trägst bereits eine Flagge.");
  363. block.set2(moveloc, "standing_banner", map.get(flagdirection, moveloc), concat("{Base:", map.get(flagcolors, moveloc), "}"));
  364. goto("checkgame");
  365. }
  366. tempteamstring2 = map.get(players, player_name);
  367. color = map.get(colorcodes, tempteamstring2);
  368. minigame.speakAll(gamename, concat(color, player_name, "§r trägt die ", map.get(teamcolortext, tempteamstring), " §rFlagge"));
  369. living.setEquip(player, "head", map.get(itembanner, tempteamstring));
  370. map.add(flagcarrier, player_name, tempteamstring);
  371. map.add(flagat, tempteamstring, concat(color, player_name));
  372. map.add(flagatloc, tempteamstring, entity.getLocation(player));
  373. display.add("all", list.getIndexOf(allteams, tempteamstring) + 1, concat(map.get(teamcolortext2, tempteamstring), "e Flagge: ", map.get(flagat, tempteamstring)));
  374. setCompassNew(tempteamstring);
  375. goto("checkgame");
  376. @checkplayability
  377. if(equal(list.getSize(blueteam), 0)) goto("redwin");
  378. if(equal(list.getSize(redteam), 0)) goto("bluewin");
  379. goto("checkgame");
  380. @bluewin
  381. setVar("colortext", "§9blaue");
  382. goto("wincore");
  383. @redwin
  384. setVar("colortext", "§crote");
  385. goto("wincore");
  386. @wincore
  387. minigame.speakAll("§3CTF", concat("§rDas ", colortext, "§r Team hat gewonnen!"));
  388. for(i = 0; i < list.getSize(all); i++) {
  389. p = list.getIndex(all, i);
  390. p_name = player.getName(p);
  391. resetplayer(p);
  392. tptogameslobby(p);
  393. }
  394. entity.removeAll("net.minecraft.entity.item.ItemEntity", middleloc, radius);
  395. block.setSign(gamesignloc, 2, concat("0/", text.number(maxplayers)));
  396. block.setSign(gamesignloc, 3, "§2Bereit");
  397. term();
  398. @player_logout
  399. @player_giveup
  400. kickplayer(player);
  401. list.remove(waiters, player_name);
  402. goto("checkplayability");
  403. function getMoveLocation(location) {
  404. world = loc.getCoord(location, "w");
  405. x = math.roundDown(loc.getX(location));
  406. y = math.roundDown(loc.getY(location));
  407. z = math.roundDown(loc.getZ(location));
  408. moveloc = loc.new(world, x, y, z);
  409. return moveloc;
  410. }