hideandseek.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. rankingtable = "fncranks";
  2. game_short = "hs";
  3. cooldown_map = map.new();
  4. brokenblocks = map.new();
  5. placedblocks = list.new();
  6. points = map.new();
  7. times = map.new();
  8. seekerlist = list.new();
  9. escaperlist = list.new();
  10. winpoints = 30; //Punkte für Win
  11. gamename = "§9Hide and Seek";
  12. seeker_skills = list.new();
  13. hider_skills = list.new();
  14. addSeekerSkill("Speed", 20, "km:skill54", 5, 2, false, "speed");
  15. addSeekerSkill("JumpBoost", 12, "km:skill15", 3, 5, false, "jump_boost");
  16. addSeekerSkill("Haste", 25, "km:skill50", 7, 3, false, "haste");
  17. addSeekerSkill("Slowness", 25, "km:skill53", 3, 1, true, "slowness");
  18. addSeekerSkill("Glowing", 50, "km:skill3", 2, 1, true, "glowing");
  19. addHiderSkill("Invisibility", 45, "km:skill47", 10, 1, false, "invisibility");
  20. addHiderSkill("Haste", 25, "km:skill50", 7, 3, false, "haste");
  21. addHiderSkill("Slowness", 25, "km:skill53", 3, 1, true, "slowness");
  22. addHiderSkill("Blindness", 25, "km:skill55", 3, 1, true, "blindness");
  23. addHiderSkill("Nausea", 25, "km:skill36", 10, 10, true, "nausea");
  24. specific_lobby_handling = true;
  25. no_core_reset = true;
  26. gosub("setstart");
  27. spawnprotect = list.new();
  28. list.add(spawnprotect, middleloc);
  29. list.add(spawnprotect, loc.mod(middleloc, 0, 1, 0));
  30. list.add(spawnprotect, loc.mod(middleloc, -1, 0, 0));
  31. list.add(spawnprotect, loc.mod(middleloc, -1, 1, 0));
  32. list.add(spawnprotect, loc.mod(middleloc, 1, 0, 0));
  33. list.add(spawnprotect, loc.mod(middleloc, 1, 1, 0));
  34. list.add(spawnprotect, loc.mod(middleloc, 0, 0, 1));
  35. list.add(spawnprotect, loc.mod(middleloc, 0, 1, 1));
  36. list.add(spawnprotect, loc.mod(middleloc, 0, 0, -1));
  37. list.add(spawnprotect, loc.mod(middleloc, 0, 1, -1));
  38. list.add(spawnprotect, escaper_spawn_loc);
  39. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 0, 1, 0));
  40. list.add(spawnprotect, loc.mod(escaper_spawn_loc, -1, 0, 0));
  41. list.add(spawnprotect, loc.mod(escaper_spawn_loc, -1, 1, 0));
  42. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 1, 0, 0));
  43. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 1, 1, 0));
  44. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 0, 0, 1));
  45. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 0, 1, 1));
  46. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 0, 0, -1));
  47. list.add(spawnprotect, loc.mod(escaper_spawn_loc, 0, 1, -1));
  48. list.add(spawnprotect, seeker_spawn_loc);
  49. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 0, 1, 0));
  50. list.add(spawnprotect, loc.mod(seeker_spawn_loc, -1, 0, 0));
  51. list.add(spawnprotect, loc.mod(seeker_spawn_loc, -1, 1, 0));
  52. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 1, 0, 0));
  53. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 1, 1, 0));
  54. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 0, 0, 1));
  55. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 0, 1, 1));
  56. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 0, 0, -1));
  57. list.add(spawnprotect, loc.mod(seeker_spawn_loc, 0, 1, -1));
  58. escaper_spawn_loc = loc.mod(escaper_spawn_loc, 0.5, 0, 0.5);
  59. seeker_spawn_loc = loc.mod(seeker_spawn_loc, 0.5, 0, 0.5);
  60. goto("simplelobby");
  61. @specificLobbyHandling
  62. if(event == "player_join") {
  63. entity.cleareffects(player);
  64. living.setHealth(player, 20);
  65. player.setHunger(player, 20);
  66. player.setSaturation(player, 5);
  67. player.clearInventory(player);
  68. display.reset(player);
  69. }
  70. return;
  71. @finalstart
  72. player_list = minigame.getPlayers(script_id);
  73. event.load("player_post_respawn");
  74. event.load("function_key");
  75. //Temp-Kopie von player_list erstellen
  76. templist = list.new();
  77. for(i = 0; i < list.getSize(player_list); i++) {
  78. p_uuid = list.getIndex(player_list, i);
  79. p = player.get(p_uuid);
  80. msg.prefix(p, gamename, "The game has started.");
  81. list.add(templist, p_uuid);
  82. map.add(points, p_uuid, 0);
  83. player.setGamemode(p, "survival");
  84. player.setFly(p, false);
  85. }
  86. diapickaxe = read.item("{id:\"minecraft:diamond_pickaxe\",Count:1b,tag:{Enchantments:[{lvl:1s,id:\"minecraft:efficiency\"}]}}");
  87. blocks512 = read.item("minecraft:cut_sandstone", 512);
  88. stick = read.item("{id:\"minecraft:stick\",Count:1b,tag:{HideFlags:2,Enchantments:[{lvl:1s,id:\"minecraft:knockback\"}],display:{Name:'{\"text\":\"§bKnüppel\"}'},AttributeModifiers:[{UUIDMost:1,UUIDLeast:1,Amount:100.0d,Slot:\"mainhand\",AttributeName:\"generic.attackSpeed\",Operation:0,Name:\"modifier\"}]}}");
  89. ironpickaxe = read.item("minecraft:iron_pickaxe");
  90. blocks64 = read.item("minecraft:cut_sandstone", 64);
  91. for(i = 0; i < seeker_amount; i++) {
  92. p_uuid = list.getIndex(templist, math.random(0, list.getSize(templist) - 1));
  93. p = player.get(p_uuid);
  94. list.remove(templist, p_uuid);
  95. setSeeker(p);
  96. msg.prefix(p, gamename, "Catch other players!");
  97. }
  98. for(i = 0; i < list.getSize(templist); i++) {
  99. p_uuid = list.getIndex(templist, i);
  100. p = player.get(p_uuid);
  101. setEscaper(p);
  102. msg.prefix(p, gamename, "Run away!!!");
  103. }
  104. sgoto(20, "loop");
  105. gosub("updatedisplay");
  106. @checkgame
  107. wait();
  108. if(event == "living_pre_hurt") {
  109. if(!isPlayer(living_entity)) {
  110. goto("checkgame");
  111. }
  112. player = living_entity;
  113. }
  114. if(player.hasMinigameId(player, script_id)) {
  115. ignoreGoto(event);
  116. }
  117. goto("checkgame");
  118. @function_key
  119. if(list.contains(seekerlist, player.getUuid(player))) {
  120. skills_list = seeker_skills;
  121. type = "seeker";
  122. } else {
  123. skills_list = hider_skills;
  124. type = "hider";
  125. }
  126. if(key > list.getSize(skills_list)) {
  127. goto("checkgame");
  128. }
  129. skill = list.getIndex(skills_list, key - 1);
  130. skill_name = skill[0];
  131. needed_cooldown = skill[1];
  132. effecttime = skill[3] * 20;
  133. amplifier = skill[4];
  134. offensive = skill[5];
  135. tech_name = skill[6];
  136. last_exe_time = getCatchLastExeTime(player, skill_name);
  137. diff_time = math.roundUp((time.getMillis() - last_exe_time) / 1000);
  138. if(diff_time < needed_cooldown) {
  139. player.action(player, concat("§a", text.number(needed_cooldown - diff_time), "s cooldown left"));
  140. goto("checkgame");
  141. }
  142. if(offensive) {
  143. if(type == "seeker") {
  144. iter = list.iterator(escaperlist);
  145. while(hasNext(iter)) {
  146. p = player.get(next(iter));
  147. entity.addEffect(p, tech_name, effecttime, amplifier, false);
  148. }
  149. } else {
  150. iter = list.iterator(seekerlist);
  151. while(hasNext(iter)) {
  152. p = player.get(next(iter));
  153. entity.addEffect(p, tech_name, effecttime, amplifier, false);
  154. }
  155. }
  156. } else {
  157. entity.addEffect(player, tech_name, effecttime, amplifier, false);
  158. }
  159. setCatchLastExeTime(player, skill_name);
  160. status.addTimed(player, key, needed_cooldown * 20, concat("CD ", skill_name));
  161. minigame.speakAll(gamename, concat("§6", player.getName(player), "§r used §2", skill_name, "."));
  162. goto("checkgame");
  163. @living_pre_hurt
  164. defender = player;
  165. attacker = player.getFromDamageSource(damage_source);
  166. if(attacker == null) {
  167. goto("checkgame");
  168. }
  169. defender_uuid = player.getUuid(defender);
  170. if(!list.contains(player_list, defender_uuid)) {
  171. cancel = true;
  172. msg.prefix(attacker, gamename, "§eIllegal player in game.");
  173. goto("checkgame");
  174. }
  175. if(!player.hasMinigameId(attacker, script_id)) {
  176. goto("checkgame");
  177. }
  178. attacker_uuid = player.getUuid(attacker);
  179. if(defender_uuid == attacker_uuid) {
  180. goto("checkgame");
  181. }
  182. if(!list.contains(player_list, attacker_uuid)) {
  183. msg.prefix(defender, gamename, "§eIllegal player in game.");
  184. goto("checkgame");
  185. }
  186. if(list.contains(seekerlist, attacker_uuid) && list.contains(escaperlist, defender_uuid)) {
  187. setSeeker(defender);
  188. msg.prefix(defender, gamename, "Catch other players!");
  189. setEscaper(attacker);
  190. msg.prefix(attacker, gamename, "Run away!!!");
  191. gosub("updatedisplay");
  192. }
  193. goto("checkgame");
  194. @player_post_respawn
  195. if(list.contains(escaperlist, player.getUuid(player))) {
  196. //Random-Seeker zum Escaper machen
  197. p_uuid = list.getIndex(seekerlist, math.random(0, list.getSize(seekerlist) - 1));
  198. p = player.get(p_uuid);
  199. setEscaper(p);
  200. msg.prefix(p, gamename, "Run away!!!");
  201. //Escaper wird zum Seeker
  202. setSeeker(player);
  203. msg.prefix(player, gamename, "Catch other players!");
  204. gosub("updatedisplay");
  205. } else {
  206. player.clearInventory(player);
  207. giveSeekerItems(player);
  208. entity.teleport(player, seeker_spawn_loc);
  209. }
  210. goto("checkgame");
  211. @block_break
  212. cancel = true;
  213. if(list.contains(spawnprotect, block_loc)) {
  214. inv.update(player);
  215. goto("checkgame");
  216. }
  217. if(list.contains(placedblocks, block_loc)) {
  218. cancel = false;
  219. list.remove(placedblocks, block_loc);
  220. goto("checkgame");
  221. }
  222. if(set.contains(allowed_breaks, block_type)) {
  223. cancel = false;
  224. map.add(brokenblocks, block_loc, block_type);
  225. goto("checkgame");
  226. }
  227. if(block_type == "minecraft:diamond_block") {
  228. player_uuid = player.getUuid(player);
  229. if(list.contains(escaperlist, player_uuid)) {
  230. cancel = false;
  231. temp = map.get(points, player_uuid) + 1;
  232. map.add(points, player_uuid, temp);
  233. if(temp >= winpoints) {
  234. winner_uuid = player_uuid;
  235. goto("win");
  236. }
  237. sgoto(60, "replacedia");
  238. goto("checkgame");
  239. }
  240. }
  241. goto("checkgame");
  242. @block_place
  243. if(list.contains(spawnprotect, block_loc)) {
  244. cancel = true;
  245. inv.update(player);
  246. goto("checkgame");
  247. }
  248. if(block_type == "minecraft:diamond_block") {
  249. cancel = true;
  250. inv.update(player);
  251. goto("checkgame");
  252. }
  253. cancel = false;
  254. list.add(placedblocks, block_loc);
  255. goto("checkgame");
  256. @replacedia
  257. block.set(dia_loc, "minecraft:diamond_block");
  258. goto("checkgame");
  259. @loop
  260. //Zeit wird nur Escapern angezeigt
  261. for(i = 0; i < list.getSize(escaperlist); i++) {
  262. p_uuid = list.getIndex(escaperlist, i);
  263. seconds = map.get(times, p_uuid) - 1;
  264. if(seconds <= 0) {
  265. seconds = 30;
  266. temp = map.get(points, p_uuid) + 2;
  267. map.add(points, p_uuid, temp);
  268. if(temp >= winpoints) {
  269. winner_uuid = p_uuid;
  270. goto("win");
  271. }
  272. }
  273. map.add(times, p_uuid, seconds);
  274. }
  275. sgoto(20, "loop");
  276. gosub("updatedisplay");
  277. goto("checkgame");
  278. @updatedisplay
  279. minigame.displayResetAll();
  280. displayindex = 0;
  281. minigame.displayAll(displayindex++, "§6Catcher");
  282. for(i = 0; i < list.getSize(seekerlist); i++) {
  283. minigame.displayAll(displayindex++, player.getName(list.getIndex(seekerlist, i)));
  284. }
  285. minigame.displayAll(displayindex++, "");
  286. minigame.displayAll(displayindex++, concat("§6Points §r(Goal: ", text.number(winpoints), ")"));
  287. for(i = 0; i < list.getSize(player_list); i++) {
  288. p_uuid = list.getIndex(player_list, i);
  289. minigame.displayAll(displayindex++, concat(text.number(map.get(points, p_uuid)), " ", player.getName(p_uuid)));
  290. }
  291. for(i = 0; i < list.getSize(escaperlist); i++) {
  292. p_uuid = list.getIndex(escaperlist, i);
  293. p = player.get(p_uuid);
  294. display.add(p, displayindex++, "");
  295. display.add(p, displayindex++, "§6Counter");
  296. display.add(p, displayindex++, concat(text.number(map.get(times, p_uuid))));
  297. }
  298. return;
  299. function setSeeker(player) {
  300. setStackIcons(player, $seeker_skills);
  301. player_uuid = player.getUuid(player);
  302. living.setHealth(player, 20);
  303. player.setHunger(player, 20);
  304. player.setSaturation(player, 5);
  305. entity.clearEffects(player);
  306. player.clearInventory(player);
  307. list.add($seekerlist, player_uuid);
  308. list.remove($escaperlist, player_uuid);
  309. giveSeekerItems(player);
  310. entity.teleport(player, $seeker_spawn_loc);
  311. entity.addEffect(player, "slowness", $slowtime, 6);
  312. entity.addEffect(player, "jump_boost", $slowtime, 128);
  313. }
  314. function setEscaper(player) {
  315. setStackIcons(player, $hider_skills);
  316. player_uuid = player.getUuid(player);
  317. living.setHealth(player, 20);
  318. player.setHunger(player, 20);
  319. player.setSaturation(player, 5);
  320. entity.clearEffects(player);
  321. player.clearInventory(player);
  322. list.add($escaperlist, player_uuid);
  323. list.remove($seekerlist, player_uuid);
  324. player.giveItem(player, $diapickaxe);
  325. player.giveItem(player, $stick);
  326. player.giveItem(player, $blocks512);
  327. map.add($times, player_uuid, 30);
  328. entity.teleport(player, $escaper_spawn_loc);
  329. }
  330. function giveSeekerItems(player) {
  331. player.giveItem(player, $ironpickaxe);
  332. player.giveItem(player, $blocks64);
  333. }
  334. function setCatchLastExeTime(player, skill_name) {
  335. player_uuid = player.getUuid(player);
  336. player_map = map.getOrDefault($cooldown_map, player_uuid, map.new());
  337. map.add(player_map, skill_name, time.getMillis());
  338. map.add($cooldown_map, player_uuid, player_map);
  339. }
  340. function getCatchLastExeTime(player, skill_name) {
  341. player_map = map.get($cooldown_map, player.getUuid(player));
  342. if(player_map == null) {
  343. return 0;
  344. }
  345. return map.getOrDefault(player_map, skill_name, 0);
  346. }
  347. function setStackIcons(player, skills_list) {
  348. stacks.clear(player);
  349. for(h = 0; h < list.getSize(skills_list); h++) {
  350. skill = list.getIndex(skills_list, h);
  351. icon = skill[2];
  352. stacks.set(player, h, icon);
  353. }
  354. stacks.setActive(player, true);
  355. }
  356. function addSeekerSkill(skill_name, cooldown, icon, effecttime, amplifier, offensive, tech_name) {
  357. skill = array.new(7);
  358. skill[0] = skill_name;
  359. skill[1] = cooldown; //s
  360. skill[2] = icon;
  361. skill[3] = effecttime; //s
  362. skill[4] = amplifier;
  363. skill[5] = offensive;
  364. skill[6] = tech_name;
  365. list.add($seeker_skills, skill);
  366. }
  367. function addHiderSkill(skill_name, cooldown, icon, effecttime, amplifier, offensive, tech_name) {
  368. skill = array.new(7);
  369. skill[0] = skill_name;
  370. skill[1] = cooldown; //s
  371. skill[2] = icon;
  372. skill[3] = effecttime; //s
  373. skill[4] = amplifier;
  374. skill[5] = offensive;
  375. skill[6] = tech_name;
  376. list.add($hider_skills, skill);
  377. }
  378. @player_logout
  379. @player_giveup
  380. minigame.speakAll(gamename, concat("§6", player.getName(player), " §rhas left the game."));
  381. script = script.getFromId(script_id);
  382. minigame.kickPlayer(script, player);
  383. player_uuid = player.getUuid(player);
  384. map.remove(points, player_uuid);
  385. list.remove(seekerlist, player_uuid);
  386. list.remove(escaperlist, player_uuid);
  387. if(list.getSize(player_list) < minplayers) {
  388. minplayers--;
  389. if(--seeker_amount == 0) {
  390. winner_uuid = list.getIndex(player_list, 0);
  391. goto("win");
  392. }
  393. }
  394. if(list.contains(seekerlist, player_uuid)) {
  395. //Ersatz-Sucher erstellen
  396. p = player.get(list.getIndex(escaperlist, math.random(0, list.getSize(escaperlist) - 1)));
  397. setSeeker(p);
  398. msg.prefix(p, gamename, "A catcher has left. You are a catcher now.");
  399. gosub("updatedisplay");
  400. }
  401. goto("checkgame");
  402. @win
  403. winnername = player.getName(winner_uuid);
  404. for(i = 0; i < list.getSize(player_list); i++) {
  405. p_uuid = list.getIndex(player_list, i);
  406. p = player.get(p_uuid);
  407. msg.prefix(p, gamename, concat("§6", winnername, "§r has won."));
  408. player.tpGamesLobby(p);
  409. resetplayer(p);
  410. money.addBoost(p, math.round(map.get(points, p_uuid)));
  411. p_id = player.getId(p);
  412. last_record = ranking.getPoints(rankingtable, p_id);
  413. if(p_uuid == winner_uuid) {
  414. last_record++;
  415. }
  416. playedgames = minigame.getPlayed(p_id, game_short) + 1;
  417. minigame.setPlayed(p_id, game_short, playedgames);
  418. ranking.setPoints(rankingtable, p_id, last_record);
  419. minigame.statsHeader(p, gamename, "§e");
  420. minigame.statsLine(p, "§e", "Played games", text.number(playedgames));
  421. minigame.statsLine(p, "§e", "Won games", text.number(last_record));
  422. if(playedgames != 0) {
  423. minigame.statsLine(p, "§e", "Win ratio", concat(text.number(math.roundComma((last_record / playedgames) * 100, 2)), "%"));
  424. }
  425. iter = list.iterator(placedblocks);
  426. while(hasNext(iter)) {
  427. block.set(next(iter), "minecraft:air");
  428. }
  429. iter = map.iterator(brokenblocks);
  430. while(hasNext(iter)) {
  431. element = next(iter);
  432. loc = map.getKey(element);
  433. type = map.getValue(element);
  434. block.set(loc, type);
  435. }
  436. block.set(dia_loc, "minecraft:diamond_block");
  437. entity.removeAll("net.minecraft.entity.item.ItemEntity", middleloc, radius);
  438. }
  439. script = script.getFromId(script_id);
  440. minigame.kickAllPlayers(script);
  441. minigame.term(script, gamesignloc);
  442. term();