jr_core.txt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. @core_start
  2. maxplayers = 1;
  3. sign.started(gamesignloc);
  4. event.load("player_join");
  5. event.load("player_move");
  6. event.load("living_pre_hurt");
  7. event.load("player_post_respawn");
  8. event.load("player_toss");
  9. event.load("player_logout");
  10. event.load("player_giveup");
  11. event.load("block_break");
  12. event.load("block_place");
  13. event.load("function_key");
  14. @wait
  15. wait();
  16. if(event == "living_pre_hurt") {
  17. if(!isPlayer(living_entity)) {
  18. goto("wait");
  19. }
  20. player = living_entity;
  21. }
  22. if(player.hasMinigameId(player, script_id)) {
  23. gosub("event_specific");
  24. ignoreGoto(event);
  25. }
  26. goto("wait");
  27. @player_join
  28. amount_checkpoints = list.getSize(spawn_locs) - 1;
  29. single_uuid = player.getUuid(player);
  30. jr.setStarttime();
  31. all_modules = jr.getModule(player);
  32. if(all_modules < amount_checkpoints) {
  33. jumpstage = all_modules;
  34. run_time = jr.getTime(player);
  35. jr.setLoopTime(run_time);
  36. jr.setRunTime(player, run_time);
  37. } else {
  38. jumpstage = jr.getRunModule(player);
  39. jr.setLoopTime(jr.getRunTime(player));
  40. }
  41. checkpoints = list.new();
  42. for(i = 0; i < list.getSize(spawn_locs); i++) {
  43. loc = list.getIndex(spawn_locs, i);
  44. b_loc = loc.mod(loc, -0.5, 0, -0.5);
  45. loc.setYaw(b_loc, 0);
  46. loc.setPitch(b_loc, 0);
  47. list.add(checkpoints, b_loc);
  48. b_loc_2 = loc.mod(b_loc, 1, 1, 1);
  49. if(i <= jumpstage) {
  50. continue;
  51. }
  52. event.addMoveData(b_loc, b_loc_2, -1, -1, player);
  53. }
  54. player.blockCommands(player);
  55. entity.teleport(player, list.getIndex(spawn_locs, jumpstage));
  56. player.clearInventory(player);
  57. display.reset(player);
  58. display.add(player, 0, gamename);
  59. stacks.set(player, 0, "km:refresh_red");
  60. stacks.set(player, 1, "km:return_red");
  61. stacks.setActive(player, true);
  62. title.clear(player);
  63. title.setTime(player, 20, 20, 20);
  64. title.setSub(player, mapname);
  65. title.send(player, gamename);
  66. gosub("stage_specific");
  67. player.setGamemode(player, "adventure");
  68. player.setFly(player, false);
  69. sgoto(20, "loop");
  70. goto("wait");
  71. @player_toss
  72. living.setEquip(player, "hand", item);
  73. cancel = true;
  74. goto("wait");
  75. @function_key
  76. if(key == 1) {
  77. living.setHealth(player, 20);
  78. jr.teleportModule(player, jumpstage);
  79. entity.setBurning(player, 0);
  80. jr.setLoopTime(jr.getRunTime(player));
  81. jr.setStarttime();
  82. goto("wait");
  83. }
  84. if(key == 2) {
  85. for(i = 1; i < amount_checkpoints; i++) {
  86. location1 = list.getIndex(checkpoints, i);
  87. location2 = loc.mod(location1, 1, 1, 1);
  88. event.addMoveData(location1, location2, -1, -1, player);
  89. }
  90. living.setHealth(player, 20);
  91. jr.setStarttime();
  92. jr.setLoopTime(0);
  93. jr.setRunTime(player, 0);
  94. jumpstage = 0;
  95. jr.setRunModule(player, jumpstage);
  96. jr.teleportModule(player, jumpstage);
  97. entity.setBurning(player, 0);
  98. }
  99. goto("wait");
  100. @block_break
  101. @block_place
  102. cancel = true;
  103. goto("wait");
  104. @player_post_respawn
  105. entity.teleport(player, list.getIndex(spawn_locs, jumpstage));
  106. goto("wait");
  107. @living_pre_hurt
  108. damage_type = damage.getType(damage_source);
  109. if(damage_type == "fall") {
  110. cancel = true;
  111. goto("wait");
  112. }
  113. if(damage_type == "arrow") {
  114. cancel = true;
  115. goto("wait");
  116. }
  117. goto("wait");
  118. @player_move
  119. player_loc = entity.getLocation(player);
  120. x = loc.getCoord(player_loc, "bx");
  121. y = loc.getCoord(player_loc, "by");
  122. z = loc.getCoord(player_loc, "bz");
  123. loc = loc.new(gamesworld, x, y, z);
  124. index = list.getIndexOf(checkpoints, loc);
  125. if(index > jumpstage) {
  126. player.action(player, "§aCheckpoint gesetzt");
  127. money.addBoost(player, 10);
  128. msg.prefix(player, "§6Commands", concat("§r", text.number(index), ".Checkpoint erreicht"));
  129. jumpstage = index;
  130. gosub("stage_specific");
  131. }
  132. //Alltime first try or already done?
  133. all_modules = jr.getModule(player);
  134. if(all_modules == amount_checkpoints) {
  135. alltime_first_try = false;
  136. } else {
  137. alltime_first_try = true;
  138. }
  139. run_time = jr.addRunTime(player, time.getMillis() - starttime);
  140. jr.setRunModule(player, jumpstage);
  141. jr.setStarttime();
  142. all_time = jr.getTime(player);
  143. //if(alltime_first_try) {
  144. if(jumpstage > all_modules) {
  145. jr.setModuleAndTime(player, jumpstage, run_time);
  146. goto("wait");
  147. }
  148. if(jumpstage == all_modules) {
  149. if(all_time == 0 || run_time < all_time) {
  150. jr.setModuleAndTime(player, jumpstage, run_time);
  151. msg.prefix(player, gamename, "Neuer Rekord!!!");
  152. }
  153. }
  154. goto("wait");
  155. //}
  156. /*if(jumpstage == amount_checkpoints) {
  157. if(all_time == 0 || run_time < all_time) {
  158. jr.setModuleAndTime(player, jumpstage, run_time);
  159. msg.prefix(player, gamename, "Neuer Rekord!!!");
  160. }
  161. }*/
  162. goto("wait");
  163. @loop
  164. player = player.get(single_uuid);
  165. seconds++;
  166. if(seconds == 60) {
  167. minutes++;
  168. seconds = 0;
  169. }
  170. if(seconds < 10) {
  171. display.add(player, 5, concat("Zeit: §e", text.number(minutes), ":0", text.number(seconds)));
  172. } else {
  173. display.add(player, 5, concat("Zeit: §e", text.number(minutes), ":", text.number(seconds)));
  174. }
  175. player.setHunger(player, 20);
  176. player.setSaturation(player, 5);
  177. sgoto(20, "loop");
  178. goto("wait");
  179. @player_logout
  180. @player_giveup
  181. player.setGamemode(player, "survival");
  182. player.unblockCommands(player);
  183. all_time = jr.getTime(player);
  184. all_module = jr.getModule(player);
  185. minigame.statsHeader(player, gamename, "§e");
  186. minigame.statsLine(player, "§e", "Checkpoints", text.number(all_module));
  187. minigame.statsLine(player, "§e", "Time", time.getClockString(all_time / 1000));
  188. script = script.getFromId(script_id);
  189. minigame.kickPlayer(script, player);
  190. minigame.term(script, gamesignloc);
  191. term();
  192. function jr.teleportModule(player, jumpstage) {
  193. entity.teleport(player, list.getIndex($spawn_locs, jumpstage));
  194. }
  195. function jr.setLoopTime(time) {
  196. time /= 1000;
  197. $minutes = math.roundDown(time / 60);
  198. $seconds = math.round(time % 60);
  199. }
  200. function jr.setStarttime() {
  201. $starttime = time.getMillis();
  202. }
  203. //THIS RUN
  204. function jr.setRunModule(player_or_id, module) {
  205. config = playerdata.getGames(player_or_id);
  206. config.set(config, $module_tag_run, module);
  207. config.saveAsync(config);
  208. }
  209. function jr.getRunModule(player_or_id) {
  210. config = playerdata.getGames(player_or_id);
  211. return config.getDouble(config, $module_tag_run, 0);
  212. }
  213. function jr.addRunTime(player_or_id, time) {
  214. run_time = jr.getRunTime(player_or_id) + time;
  215. jr.setRunTime(player_or_id, run_time);
  216. return run_time;
  217. }
  218. function jr.setRunTime(player_or_id, time) {
  219. config = playerdata.getGames(player_or_id);
  220. config.set(config, $time_tag_run, time);
  221. config.saveAsync(config);
  222. }
  223. function jr.getRunTime(player_or_id) {
  224. config = playerdata.getGames(player_or_id);
  225. return config.getDouble(config, $time_tag_run, 0);
  226. }
  227. //ALLTIME
  228. function jr.setModuleAndTime(player_or_id, module, time) {
  229. ranking.setSecPoints($rankingtable, player_or_id, module, time);
  230. }
  231. function jr.getTime(player_or_id) {
  232. return ranking.getSecPoints($rankingtable, player_or_id);
  233. }
  234. function jr.getModule(player_or_id) {
  235. return ranking.getPoints($rankingtable, player_or_id);
  236. }