snowfight.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. rankingtable = "snowranks";
  2. game_short = "snow";
  3. game_tab = "§6SNOW";
  4. minigame.setSpecificLobbyHandling(true);
  5. minigame.setPlayerResetInCore(false);
  6. minigame.setIndivStartCheck(true);
  7. gamename = "§6Snowfight";
  8. snow_stack = item.create("minecraft:snowball", 16, null, null);
  9. Air = material.get("AIR");
  10. B_Candle = material.get("BLACK_CANDLE");
  11. B_Concrete = material.get("BLACK_CONCRETE"); //for black hole
  12. W_Concrete = material.get("WHITE_CONCRETE"); //for white hole
  13. pling_sound = sound.get("minecraft:block.note_block.chime"); //snowball hits candle
  14. Nom_sound = sound.get("minecraft:entity.generic.eat"); //snowball hits hole
  15. sound_Category = sound.getCategory("MASTER");
  16. snow_particle = particle.get("SNOWFLAKE");
  17. smokeparticle = particle.get("SMOKE_LARGE");
  18. fire_particle = particle.get("FLAME");
  19. gravitors = list.new();
  20. toggled_black_holes = list.new();
  21. toggled_white_holes = list.new();
  22. relit_candles = list.new();
  23. grav_locs = list.new();
  24. colorcodes = map.new();
  25. map.add(colorcodes, 0, "§1");
  26. map.add(colorcodes, 1, "§4");
  27. map.add(colorcodes, 2, "§e");
  28. map.add(colorcodes, 3, "§2");
  29. teamcolortext = map.new();
  30. map.add(teamcolortext, 0, "§1blue");
  31. map.add(teamcolortext, 1, "§4red");
  32. map.add(teamcolortext, 2, "§eyellow");
  33. map.add(teamcolortext, 3, "§2green");
  34. teamcolortext2 = map.new();
  35. map.add(teamcolortext2, 0, "§1Blue");
  36. map.add(teamcolortext2, 1, "§4Red");
  37. map.add(teamcolortext2, 2, "§eYellow");
  38. map.add(teamcolortext2, 3, "§2Green");
  39. cloth_color = map.new();
  40. map.add(cloth_color, 0, 3361970);
  41. map.add(cloth_color, 1, 10040115);
  42. map.add(cloth_color, 2, 16701501);
  43. map.add(cloth_color, 3, 84395831);
  44. team_lists = map.new(); //Map mit Spielerlisten für jedes Team
  45. map.add(team_lists, 0, list.new());
  46. map.add(team_lists, 1, list.new());
  47. map.add(team_lists, 2, list.new());
  48. map.add(team_lists, 3, list.new());
  49. players = map.new(); //Alle Spieler (key) des Spiels und deren Teamzugehörigkeit (value)
  50. allteams = list.new(); //Alle Teams, die noch im Spiel sind
  51. waiters = list.new(); //Spieler in der Lobby ohne Teamzugehörigkeit
  52. spawn_prot = list.new();
  53. lifes = map.new();
  54. kills_map = map.new();
  55. deaths_map = map.new();
  56. cooldown_map = map.new();
  57. snowball = material.get("snowball");
  58. minigame.initStart();
  59. goto("simplelobby");
  60. @specificLobbyHandling
  61. player_name = player.getName(player);
  62. if(event == "minigame_join") {
  63. list.add(waiters, player_name);
  64. map.add(kills_map, player_name, 0);
  65. map.add(deaths_map, player_name, 0);
  66. living.setHealth(player, 20);
  67. player.setHunger(player, 20);
  68. player.setSaturation(player, 5);
  69. player.clearInventory(player);
  70. sb.add(player, 99, gamename);
  71. sb.add(player, 98, string.concat("Map: ", mapname));
  72. sb.add(player, 97, "2x10");
  73. sb.add(player, 96, sb.getSpacer());
  74. return;
  75. }
  76. if(event == "player_quit" || event == "player_giveup") {
  77. list.remove(waiters, player_name);
  78. team = map.get(players, player_name);
  79. if(team != null) {
  80. teamlist = map.get(team_lists, team);
  81. list.remove(teamlist, player_name);
  82. }
  83. map.remove(players, player_name);
  84. return;
  85. }
  86. if(event == "block_click") {
  87. if(slot.isOffHand(hand)) {
  88. return;
  89. }
  90. if(action != "RIGHT_CLICK_BLOCK") {
  91. return;
  92. }
  93. block_loc = block.getLocation(block);
  94. if(list.contains(joinblocks, block_loc)) {
  95. newteam = list.getIndexOf(joinblocks, block_loc);
  96. newteamlist = map.get(team_lists, newteam);
  97. if(list.contains(newteamlist, player_name)) {
  98. msg.prefix(player, gamename, "§eYou are already in this team.");
  99. return;
  100. }
  101. if(list.getSize(newteamlist) >= teamsize) {
  102. msg.prefix(player, gamename, "§eNo space for you in this team.");
  103. return;
  104. }
  105. list.remove(waiters, player_name);
  106. yetteam = map.get(players, player_name);
  107. if(yetteam != null) {
  108. yetteamlist = map.get(team_lists, yetteam);
  109. list.remove(yetteamlist, player_name);
  110. }
  111. list.add(newteamlist, player_name);
  112. map.add(players, player_name, newteam);
  113. msg.prefix(player, gamename, string.concat("§eYou joined the ", map.get(teamcolortext, newteam), " §eteam."));;
  114. if(!minigame.isStarting()) {
  115. goto("startcountdown");
  116. }
  117. }
  118. }
  119. return;
  120. @finalstart
  121. player_list = minigame.getPlayers(script_id);
  122. starttime = time.getMillis();
  123. event.load("projectile_hit");
  124. event.load("player_drop");
  125. event.load("living_death");
  126. event.load("player_post_respawn");
  127. event.load("entity_spawn");
  128. event.load("entity_remove");
  129. event.load("arm_swing");
  130. //event.load("block_click"); //for polarity change, currently not active
  131. event.load("player_move");
  132. while(list.getSize(waiters) != 0) {
  133. team = getTeamWithLowestPeople(team_lists, numberofteams);
  134. teamlist = map.get(team_lists, team);
  135. p_name = list.getIndex(waiters, 0);
  136. map.add(players, p_name, team);
  137. list.add(teamlist, p_name);
  138. list.remove(waiters, p_name);
  139. }
  140. max = 1;
  141. for(i = 0; i < numberofteams; i++) {
  142. teamlist = map.get(team_lists, i);
  143. size = list.getSize(teamlist);
  144. if(size > max) {
  145. max = size;
  146. }
  147. }
  148. team_lifes = max * 10;
  149. sb.clearGameAll();
  150. minigame.displayAll(99, gamename);
  151. for(i = 0; i < numberofteams; i++) {
  152. teamlist = map.get(team_lists, i);
  153. size = list.getSize(teamlist);
  154. if(size != 0) {
  155. list.add(allteams, i);
  156. map.add(lifes, i, team_lifes);
  157. minigame.displayAll(98 - i, string.concat(map.get(teamcolortext2, i), " Lifes: ", string.number(team_lifes)));
  158. }
  159. }
  160. minigame.displayAll(98 - i, sb.getSpacer());
  161. for(i = 0; i < list.getSize(player_list); i++) {
  162. p = player.get(list.getIndex(player_list, i));
  163. p_name = player.getName(p);
  164. msg.prefix(p, gamename, "The game has started.");
  165. team = map.get(players, p_name);
  166. giveSnowballs(p);
  167. player.setHunger(p, 20);
  168. player.setSaturation(p, 5);
  169. player.setGamemode(p, "SURVIVAL");
  170. player.setFly(p, false);
  171. entity.teleport(p, map.get(spawnlocs, team));
  172. color = map.get(colorcodes, team);
  173. player.action(p, text.new(string.concat(color, "Team ", map.get(teamcolortext2, team))));
  174. equipPlayer(p, team);
  175. minigame.setTabName(p, game_tab, color);
  176. }
  177. sgoto(40, "loop");
  178. @checkgame
  179. wait();
  180. if(event == entity_spawn){
  181. goto("entity_spawn");
  182. }
  183. elseif (event == "entity_remove"){
  184. goto("entity_remove");
  185. }
  186. if(event == "living_death") {
  187. if(!isPlayer(living_entity)) {
  188. goto("checkgame");
  189. }
  190. player = living_entity;
  191. }
  192. if(event == "entity_damage") {
  193. if(!isPlayer(entity)) {
  194. goto("checkgame");
  195. }
  196. player = entity;
  197. }
  198. if(event == "projectile_hit") {
  199. if(shooter == null || !isPlayer(shooter)) {
  200. goto("checkgame");
  201. }
  202. player = shooter;
  203. }
  204. if(player.hasMinigameId(player, script_id)) {
  205. player_name = player.getName(player);
  206. ignoreGoto(event);
  207. }
  208. goto("checkgame");
  209. @entity_spawn
  210. //if there is a new snowball in game, add it to gravitation
  211. if (entity.getType(entity) != "snowball"){
  212. goto("checkgame");
  213. }
  214. if (get_distance(entity) > 100){
  215. goto("checkgame");
  216. }
  217. entity.setGravity(entity, false);
  218. list.add(gravitors, entity);
  219. Snow.gravitate(entity);
  220. if (list.getSize(gravitors) == 1){
  221. sgoto(1, "gravitation");
  222. }
  223. goto("checkgame");
  224. @entity_remove
  225. //if snowball hits smth, remove it
  226. //if it hits a black hole or candles doshit
  227. if (Snow.check(entity)){
  228. goto("checkgame");
  229. }
  230. list.remove(gravitors, entity);
  231. ent_loc = entity.getLocation(entity);
  232. motion = entity.getMotion(entity);
  233. for (i = 0; i<5; i++){
  234. hit_block = block.get(ent_loc);
  235. Material = block.getType(hit_block);
  236. if (Material != Air){
  237. break;
  238. }
  239. loc.add(ent_loc, motion[0]/5, motion[1]/5, motion[2]/5);
  240. }
  241. if (Material == B_Candle){
  242. sound.spawn(ent_loc, pling_sound, sound_Category, 1, 1);
  243. if (list.contains(relit_candles, hit_block)){
  244. goto("checkgame");
  245. }
  246. loc = block.getLocation(hit_block);
  247. loc.add(loc,0.5, 0.8, 0.5);
  248. particle.spawn(loc, smokeparticle, 5, 0.1);
  249. list.add(relit_candles, hit_block);
  250. Candle.change_lit(hit_block);
  251. sgoto(100, "candle");
  252. }
  253. elseif (Material == B_Concrete){
  254. if (!(list.contains(black_holes, ent_loc) || list.contains(white_holes, ent_loc))){
  255. goto("checkgame");
  256. }
  257. sound.spawn(ent_loc, Nom_sound, sound_Category, 1, 1);
  258. }
  259. goto("checkgame");
  260. @arm_swing
  261. if (get_distance(player) > 100){
  262. goto("checkgame");
  263. }
  264. if (!player.isSneaking(player)){
  265. goto("checkgame");
  266. }
  267. if (item.getType(living.getEquip(player, hand)) != snowball){
  268. goto("checkgame");
  269. }
  270. Snow.aimassist(player);
  271. goto("checkgame");
  272. @block_click
  273. goto("checkgame");//currently not on
  274. //change polarity of holes if they are clicked
  275. if (get_distance(player) > 100){
  276. goto("checkgame");
  277. }
  278. if (action != "RIGHT_CLICK_BLOCK"){
  279. goto("checkgame");
  280. }
  281. bool = !bool;
  282. if (bool){
  283. goto("checkgame");
  284. }
  285. Material = block.getType(block);
  286. loc = block.getLocation(block);
  287. loc.add(loc,0.5,0.5,0.5);
  288. if (Material == B_Concrete){
  289. if (list.contains(black_holes, loc)){
  290. list.remove(black_holes, loc);
  291. list.add(white_holes, loc);
  292. block.setMaterial(block, W_Concrete);
  293. }
  294. }
  295. elseif (Material == W_Concrete){
  296. if (list.contains(white_holes, loc)){
  297. list.remove(white_holes, loc);
  298. list.add(black_holes, loc);
  299. block.setMaterial(block, B_Concrete);
  300. }
  301. }
  302. //entity_click doesn't work on snowballs so this is currently useless, but would work in theory
  303. /*elseif (event == "entity_click"){
  304. if (Snow.check(entity)){
  305. goto("wait");
  306. }
  307. motion_ball = entity.getMotion(entity);
  308. motion_player = entity.getMotion(player);
  309. speed = math.sqrt(math.pow(motion_ball[0]-motion_player[0],2), math.pow(motion_ball[1]-motion_player[1],2), math.pow(motion_ball[2]-motion_player[2],2));
  310. if (speed > 5.5){
  311. goto("wait");
  312. }
  313. itemstack = item.new(snowball, 1);
  314. entity.remove(entity);
  315. player.giveItem(player, itemstack);
  316. }*/
  317. goto("checkgame");
  318. @player_move
  319. //player off map
  320. if (id == edge){
  321. //Snow.launchback(player);
  322. if (list.getSize(gravitors) == 0){
  323. sgoto(1, "gravitation");
  324. }
  325. entity.setGravity(player, false);
  326. entity.setMotion(player, 0, 0.2, 0);
  327. list.add(gravitors, player);
  328. Snow.gravitate(player);
  329. }
  330. elseif (id == fall){
  331. if (!list.contains(gravitors, player)){
  332. goto("checkgame");
  333. }
  334. list.remove(gravitors, player);
  335. @fall
  336. entity.setGravity(player, true);
  337. //Snow.setback(player); deprecated
  338. player_name = player.getName(player);
  339. hit_team = map.get(players, player_name);
  340. player.clearInventory(player);
  341. giveSnowballs(player);
  342. map.add(deaths_map, player_name, map.get(deaths_map, player_name) + 1);
  343. new_lifes = map.get(lifes, hit_team) - 1;
  344. map.add(lifes, hit_team, new_lifes);
  345. minigame.displayAll(98 - hit_team, string.concat(map.get(teamcolortext2, hit_team), " Lifes: ", string.number(new_lifes)));
  346. loc = map.get(spawnlocs, hit_team);
  347. entity.teleport(player, loc);
  348. if(new_lifes == 0) {
  349. colorgameover(hit_team);
  350. }
  351. }
  352. goto("checkgame");
  353. @projectile_hit
  354. if(entity_hit != null) {
  355. if(!isPlayer(entity_hit)) {
  356. goto("checkgame");
  357. }
  358. entity_hit_name = player.getName(entity_hit);
  359. if(!list.contains(player_list, player.getUuid(entity_hit))) {
  360. minigame.msgAll(string.concat("Illegal Player ", entity_hit_name));
  361. goto("checkgame");
  362. }
  363. if(!list.contains(player_list, player.getUuid(player))) {
  364. minigame.msgAll(string.concat("Illegal Player ", entity_hit_name));
  365. goto("checkgame");
  366. }
  367. player_id = player.getId(entity_hit);
  368. if(list.contains(spawn_prot, player_id)) {
  369. goto("checkgame");
  370. }
  371. team = map.get(players, player_name);
  372. hit_team = map.get(players, entity_hit_name);
  373. if(team == hit_team) {
  374. goto("checkgame"); //Friendly-Firedly-Fire
  375. }
  376. player.clearInventory(entity_hit);
  377. giveSnowballs(entity_hit);
  378. map.add(kills_map, player_name, map.get(kills_map, player_name) + 1);
  379. map.add(deaths_map, entity_hit_name, map.get(deaths_map, entity_hit_name) + 1);
  380. new_lifes = map.get(lifes, hit_team) - 1;
  381. map.add(lifes, hit_team, new_lifes);
  382. minigame.displayAll(98 - hit_team, string.concat(map.get(teamcolortext2, hit_team), " Lifes: ", string.number(new_lifes)));
  383. loc = map.get(spawnlocs, hit_team);
  384. entity.teleport(entity_hit, loc);
  385. if(new_lifes == 0) {
  386. colorgameover(hit_team);
  387. }
  388. list.add(spawn_prot, player_id);
  389. sgoto(80, "remove_prot");
  390. }
  391. goto("checkgame");
  392. @remove_prot
  393. list.removeIndex(spawn_prot, 0);
  394. goto("checkgame");
  395. @player_post_respawn
  396. team = map.get(players, player_name);
  397. loc = map.get(spawnlocs, team);
  398. entity.teleport(player, loc);
  399. giveSnowballs(player);
  400. goto("checkgame");
  401. @living_death
  402. list.clear(drops);
  403. goto("checkgame");
  404. @entity_damage
  405. damage_type = damage.getType(damage_source);
  406. if(damage_type == "wither") {
  407. goto("checkgame");
  408. }
  409. if(cause == "FALL"){
  410. if (loc.getY(entity.getLocation(player)) <= loc.getY(edge_2)){
  411. cancel = true;
  412. goto("fall");
  413. }
  414. }
  415. cancel = true;
  416. goto("checkgame");
  417. @player_drop
  418. cancel = true;
  419. goto("checkgame");
  420. @block_break
  421. @block_place
  422. cancel = true;
  423. goto("checkgame");
  424. @loop
  425. for(i = 0; i < list.getSize(player_list); i++) {
  426. p = player.get(list.getIndex(player_list, i));
  427. p_name = player.getName(p);
  428. team = map.get(players, p_name);
  429. player.setHunger(p, 20);
  430. player.setSaturation(p, 5);
  431. player.action(p, text.new(string.concat(map.get(colorcodes, team), "Team ", map.get(teamcolortext2, team))));
  432. equipPlayer(p, team);
  433. }
  434. sgoto(40, "loop");
  435. goto("checkgame");
  436. @player_giveup
  437. @player_quit
  438. team = map.get(players, player_name);
  439. color = map.get(colorcodes, team);
  440. minigame.speakAll(gamename, string.concat(color, player_name, " §ehas left the game."));
  441. teamlist = map.get(team_lists, team);
  442. list.remove(teamlist, player_name);
  443. map.remove(players, player_name);
  444. script = script.getFromId(script_id);
  445. minigame.kickplayer(script, player);
  446. if(list.getSize(teamlist) == 0) {
  447. colorgameover(team);
  448. }
  449. goto("checkgame");
  450. @gravitation
  451. //adds gravitational pull to entitys in the gravitors list
  452. //grav_locs = gravitors_loc();
  453. list_iterator = iterator(gravitors);
  454. while(hasnext(list_iterator)){
  455. entity = next(list_iterator);
  456. Snow.gravitate(entity);
  457. //particle.spawn(entity.getLocation(entity), snow_particle);
  458. if (isPlayer(entity)){
  459. if (get_distance(entity) < 10){
  460. motion = entity.getMotion(entity);
  461. entity.setMotion(entity, motion[0]/5, motion[1]/5, motion[2]/5);
  462. entity.setGravity(entity, true);
  463. remove(list_iterator);
  464. }
  465. }
  466. elseif (get_distance(entity) > 100){
  467. remove(list_iterator);
  468. entity.remove(entity);
  469. }
  470. }
  471. if(list.getSize(gravitors)>0){
  472. sgoto(5, "gravitation");
  473. }
  474. goto("checkgame");
  475. @candle
  476. //relights the candles
  477. b_candle_block = list.getIndex(relit_candles, 0);
  478. loc = block.getLocation(b_candle_block);
  479. loc.add(loc,0.5, 0.5, 0.5);
  480. particle.spawn(loc, fire_particle, 5, 0.1);
  481. Candle.change_lit(b_candle_block);
  482. list.removeIndex(relit_candles, 0);
  483. goto("checkgame");
  484. function Snow.end(){
  485. //if script is supposed to end, remove snowballs and light candles
  486. list_iterator = iterator($relit_candles);
  487. while(hasnext(list_iterator)){
  488. b_candle_block = next(list_iterator);
  489. Candle.change_lit(b_candle_block);
  490. remove(list_iterator);
  491. }
  492. list_iterator = iterator($gravitors);
  493. while(hasnext(list_iterator)){
  494. entity = next(list_iterator);
  495. entity.setGravity(entity, true);
  496. if (!isPlayer(entity)){
  497. remove(list_iterator);
  498. entity.remove(entity);
  499. }
  500. }
  501. }
  502. function Snow.toggle_grav(){
  503. //toggles which holes are on, if none are stored in toggled_lists, then it turns gravity on
  504. temp = $toggled_black_holes;
  505. $toggled_black_holes = $black_holes;
  506. $black_holes = temp;
  507. temp = $toggled_white_holes;
  508. $toggled_white_holes = $white_holes;
  509. $white_holes = temp;
  510. if (list.getSize($black_holes) + list.getSize($white_holes) == 0){
  511. list_iterator = iterator($gravitors);
  512. while(hasnext(list_iterator)){
  513. entity = next(list_iterator);
  514. entity.setGravity(entity, true);
  515. }
  516. }
  517. elseif(list.getSize($toggled_black_holes) + list.getSize($toggled_white_holes) == 0){
  518. list_iterator = iterator($gravitors);
  519. while(hasnext(list_iterator)){
  520. entity = next(list_iterator);
  521. entity.setGravity(entity, false);
  522. }
  523. }
  524. }
  525. function Snow.check(entity){
  526. if (entity.getType(entity) != "snowball"){
  527. return true;
  528. }
  529. if (get_distance(entity) > 100){
  530. return true;
  531. }
  532. if (!list.contains($gravitors, entity)){
  533. return true;
  534. }
  535. return false;
  536. }
  537. function Candle.change_lit(hit_block){
  538. //negates the boolean of the blocktag "lit"
  539. block_data = block.getData(hit_block);
  540. blockdata_string = string.blockData(block_data);
  541. blockdata_string = string.replace(blockdata_string, "lit=true", "lit=temp");
  542. blockdata_string = string.replace(blockdata_string, "lit=false", "lit=true");
  543. blockdata_string = string.replace(blockdata_string, "lit=temp", "lit=false");
  544. block_data = read.blockData(blockdata_string);
  545. block.setData(hit_block, block_data, false);
  546. }
  547. function Snow.launchback(player){
  548. //throws the player towards the black Hole (currently not in use)
  549. loc = entity.getLocation(player);
  550. motion = entity.getMotion(player);
  551. acc = Snow.get_acc(loc);
  552. x = -motion[0] + 2*acc[0];
  553. y = 2 + 4*acc[0];
  554. z = -motion[2] + 2*acc[0];
  555. entity.setMotion(player, x, y, z);
  556. }
  557. function Snow.setback(player){
  558. //resets the player to a spawn Location
  559. size = list.getSize($spawn_locs)-1;
  560. random = math.random(0,size);
  561. spawn_loc = list.getIndex($spawn_locs, random);
  562. entity.teleport(player, spawn_loc);
  563. entity.setMotion(player, 0, 0.5, 0);
  564. }
  565. function remove_snowballs(loc){
  566. //removes (currently just gives gravity etc) snowballs in a radius of the middle Location
  567. entity_list = entity.near(loc, 50);
  568. list_iterator = iterator(entity_list);
  569. while(hasnext(list_iterator)){
  570. ent = next(list_iterator);
  571. if (entity.getType(ent) == "snowball"){
  572. entity.setGravity(ent, true);
  573. list.add($gravitors, ent);
  574. //entity.remove(ent);
  575. }
  576. }
  577. }
  578. function get_distance(entity_){
  579. //returns the distance of an entity to the middle Location
  580. ent_loc = entity.getLocation(entity_);
  581. if (loc.getWorld($middleloc) != loc.getWorld(ent_loc)){
  582. return 50000;
  583. }
  584. x_dist = loc.getX($middleloc) - loc.getX(ent_loc);
  585. y_dist = loc.getY($middleloc) - loc.getY(ent_loc);
  586. z_dist = loc.getZ($middleloc) - loc.getZ(ent_loc);
  587. distance = math.sqrt(math.pow(x_dist, 2) + math.pow(y_dist, 2) + math.pow(z_dist, 2));
  588. return distance;
  589. }
  590. function Snow.aimassist(player){
  591. //creates particle effect of where a snowball would fly
  592. motion = entity.getLook(player);
  593. location = entity.getLocation(player);
  594. loc.addY(location, 1.5);
  595. for (i = 0; i < 50; i++){
  596. add_motion = Snow.get_acc(location);
  597. for (j = 0; j < 3; j++){
  598. motion[j] += add_motion[j];
  599. }
  600. //current_block = block.get(location);
  601. //Material = block.getType(current_block);
  602. //if (Material != $Air){
  603. //snuvi.debug(Material);
  604. // break;
  605. //}
  606. loc.add(location, 4*motion[0], 4*motion[1], 4*motion[2]);
  607. particle.spawnPlayer(location, $snow_particle, player, 0, 0 ,0);
  608. }
  609. }
  610. function gravitors_loc(){
  611. //returns the locations of the gravitor list
  612. grav_locs = list.new();
  613. list_iterator = iterator($gravitors);
  614. while(hasnext(list_iterator)){
  615. gravitor = next(list_iterator);
  616. gravitor_loc = entity.getLocation(gravitor);
  617. list.add(grav_locs, gravitor_loc);
  618. }
  619. return grav_locs;
  620. }
  621. function Snow.get_acc(location){
  622. //returns the accelleration of an object given the black/white holes in a map
  623. accvector1 = Snow.acc(location, $black_holes);
  624. accvector2 = Snow.acc(location, $white_holes);
  625. //accvector3 = Snow.acc(location, $grav_locs);
  626. //snuvi.debug($black_holes);
  627. accvector = array.new(3);
  628. for (i = 0; i<3; i++){
  629. accvector[i] = accvector1[i]-accvector2[i];// + 0.01*accvector3[i];
  630. }
  631. return accvector;
  632. }
  633. function Snow.acc(location, list){
  634. //returns the accelleration of an object given by the objects in the list
  635. G = 5;
  636. accvector = array.new(3);
  637. accvector[0] = 0;
  638. accvector[1] = 0;
  639. accvector[2] = 0;
  640. loc_X = loc.getX(location);
  641. loc_Y = loc.getY(location);
  642. loc_Z = loc.getZ(location);
  643. list_iterator = iterator(list);
  644. while(hasnext(list_iterator)){
  645. hole_loc = next(list_iterator);
  646. x_dist = loc.getX(hole_loc) - loc_X;
  647. y_dist = loc.getY(hole_loc) - loc_Y;
  648. z_dist = loc.getZ(hole_loc) - loc_Z;
  649. distance = math.sqrt(math.pow(x_dist, 2) + math.pow(y_dist, 2) + math.pow(z_dist, 2));
  650. if (distance > 50 || distance < 0.1){
  651. continue;
  652. }
  653. dist_sqrt = math.pow(distance,2);
  654. accvector[0] += x_dist/dist_sqrt;
  655. accvector[1] += y_dist/dist_sqrt;
  656. accvector[2] += z_dist/dist_sqrt;
  657. }
  658. for (i = 0; i<3; i++){
  659. accvector[i] *= G;
  660. }
  661. return accvector;
  662. }
  663. function Snow.change_polarity(){
  664. //changes black to white holes and the other way round
  665. temp_list = list.new();
  666. temp_list = $black_holes;
  667. $black_holes = $white_holes;
  668. $white_holes = $black_holes;
  669. }
  670. function Snow.gravitate(entity_){
  671. //sets the Motion of an entity to gravitate towards black holes and away from white holes
  672. ent_loc = entity.getLocation(entity_);
  673. accvector = Snow.get_acc(ent_loc);
  674. motion = entity.getMotion(entity_);
  675. x = motion[0];
  676. y = motion[1];
  677. z = motion[2];
  678. entity.setMotion(entity_, x + accvector[0], y + accvector[1], z + accvector[2]);
  679. }
  680. function colorgameover(team) {
  681. tempcolortext = map.get($teamcolortext, team);
  682. minigame.speakAll($gamename, string.concat("§cThe ", tempcolortext, " §cTeam has been eliminated."));
  683. list.remove($allteams, team);
  684. if(list.getSize($allteams) == 1) {
  685. $endtime = time.getMillis();
  686. kickteam(team, true, false);
  687. win_team = list.getIndex($allteams, 0);
  688. kickteam(win_team, true, true);
  689. minigame.clearItems($middleloc, $radius);
  690. script = script.getFromId($script_id);
  691. minigame.term(script, $gamesignloc);
  692. term();
  693. }
  694. kickteam(team, false, false);
  695. }
  696. function kickteam(team, show_time, won) {
  697. teamlist = map.get($team_lists, team);
  698. for(i = 0; i < list.getSize(teamlist); i++) {
  699. p_name = list.getIndex(teamlist, i);
  700. p = read.player(p_name);
  701. showstats(p, show_time, won);
  702. script = script.getFromId($script_id);
  703. minigame.kickplayer(script, p);
  704. if(won) {
  705. //money.addBoost(p, 128);
  706. } else {
  707. //money.addBoost(p, 32);
  708. }
  709. }
  710. }
  711. function showstats(player, show_time, won) { //Player player, Boolean show_time, Boolean won
  712. player_name = player.getName(player);
  713. player_id = player.getId(player);
  714. last_record = ranking.getPoints($rankingtable, player_id);
  715. playedgames = minigame.getPlayed(player_id, $game_short) + 1;
  716. minigame.setPlayed(player_id, $game_short, playedgames);
  717. kills = map.get($kills_map, player_name);
  718. record = last_record + kills;
  719. ranking.setPoints($rankingtable, player_id, record);
  720. deaths = map.get($deaths_map, player_name);
  721. wongames = minigame.getWon(player, $game_short);
  722. if(won) {
  723. wongames++;
  724. minigame.setWon(player, $game_short, wongames);
  725. }
  726. minigame.statsHeader(player, $gamename, "§e");
  727. if(show_time) {
  728. time = ($endtime - $starttime) / 1000;
  729. minigame.statsLine(player, "§e", "Time", string.concat(string.number(math.rounddown(time / 60)), " min ", string.number(math.round(time % 60)), " s"));
  730. }
  731. minigame.statsLine(player, "§e", "Kills", string.number(kills));
  732. minigame.statsLine(player, "§e", "Deaths", string.number(deaths));
  733. if(deaths != 0) {
  734. kd = kills / deaths;
  735. minigame.statsLine(player, "§e", "K/D", string.number(math.roundcomma(kd, 2)));
  736. }
  737. minigame.statsLine(player, "§e", "Won games", string.number(wongames));
  738. minigame.statsLine(player, "§e", "Played games", string.number(playedgames));
  739. if(playedgames != 0) {
  740. minigame.statsLine(player, "§e", "Win ratio", string.concat(string.number(math.roundComma((wongames / playedgames) * 100, 2)), "%"));
  741. }
  742. }
  743. function giveSnowballs(player) {
  744. player.giveItem(player, $snow_stack);
  745. player.giveItem(player, $snow_stack);
  746. player.giveItem(player, $snow_stack);
  747. player.giveItem(player, $snow_stack);
  748. player.giveItem(player, $snow_stack);
  749. player.giveItem(player, $snow_stack);
  750. player.giveItem(player, $snow_stack);
  751. player.giveItem(player, $snow_stack);
  752. player.giveItem(player, $snow_stack);
  753. }
  754. function equipPlayer(player, team) {
  755. if(living.getEquip(player, slot.getHead()) == null) {
  756. color = map.get($cloth_color, team);
  757. living.setEquip(player, slot.getHead(), read.item(string.concat("{id:'minecraft:leather_helmet',Count:1b,tag:{display:{color:", color, "}}}")));
  758. living.setEquip(player, slot.getChest(), read.item(string.concat("{id:'minecraft:leather_chestplate',Count:1b,tag:{display:{color:", color, "}}}")));
  759. living.setEquip(player, slot.getLegs(), read.item(string.concat("{id:'minecraft:leather_leggings',Count:1b,tag:{display:{color:", color, "}}}")));
  760. living.setEquip(player, slot.getFeet(), read.item(string.concat("{id:'minecraft:leather_boots',Count:1b,tag:{display:{color:", color, "}}}")));
  761. }
  762. }
  763. function minigame.canStartIndiv() {
  764. player_list = minigame.getPlayers($script_id);
  765. p_amount = list.getSize(player_list);
  766. if(p_amount < minigame.getMinPlayers()) {
  767. return false;
  768. }
  769. if(p_amount > 0 && list.getSize($waiters) > 0) {
  770. return true;
  771. }
  772. for(i = 0; i < $numberofteams; i++) {
  773. teamlist = map.get($team_lists, i);
  774. team_size = list.getSize(teamlist);
  775. if(team_size == p_amount) {
  776. return false;
  777. }
  778. }
  779. return true;
  780. }