Portal.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. creative_world = world.get("creative");
  2. speed1 = event.addMoveData(loc.new(creative_world, 3043,53, 2897), loc.new(Overworld, 3045,54,2900), 5, -1);
  3. speed2 = event.addMoveData(loc.new(creative_world, 3060,64, 2897), loc.new(Overworld, 3062,65,2899), 5, -1);
  4. jump1 = event.addMoveData(loc.new(creative_world, 3043,53, 2900), loc.new(Overworld, 3045,54,2904), 5, -1);
  5. jump2 = event.addMoveData(loc.new(creative_world, 3055,60, 2893), loc.new(Overworld, 3057,61,2895), 5, -1);
  6. jump3 = event.addMoveData(loc.new(creative_world, 3057,59, 2910), loc.new(Overworld, 3059,60,2912), 5, -1);
  7. Portal1 = event.addMoveData(loc.new(creative_world, 3049,59, 2911), loc.new(Overworld, 3050,61,2912), 5, -1);
  8. Portal2 = event.addMoveData(loc.new(creative_world, 3051,60, 2893), loc.new(Overworld, 3052,61,2894), 5, -1);
  9. Portal3 = event.addMoveData(loc.new(creative_world, 3061,62, 2905), loc.new(Overworld, 3062,63,2906), 5, -1);
  10. Portal4 = event.addMoveData(loc.new(creative_world, 3043,65, 2899), loc.new(Overworld, 3044,67,2900), 5, -1);
  11. Portal5 = event.addMoveData(loc.new(creative_world, 3053,53, 2893), loc.new(Overworld, 3054,55,2894), 5, -1);
  12. Portal6 = event.addMoveData(loc.new(creative_world, 3061,53, 2901), loc.new(Overworld, 3062,55,2902), 5, -1);
  13. portals = map.new();
  14. map.add(portals, Portal1, portal.create(loc.new(creative_world, 3051.5,60,2893.5), loc.new(creative_world, 3049.5,59, 2911.5), "east", "east"));
  15. map.add(portals, Portal2, portal.create(loc.new(creative_world, 3049.5,59, 2911.5), loc.new(creative_world, 3051.5,60,2893.5), "east", "east"));
  16. map.add(portals, Portal3, portal.create(loc.new(creative_world, 3043.5,65, 2899.5), loc.new(creative_world, 3061.5,62, 2905.5), "south", "north"));
  17. map.add(portals, Portal4, portal.create(loc.new(creative_world, 3061.5,62, 2905.5), loc.new(creative_world, 3043.5,65, 2899.5), "south", "north"));
  18. map.add(portals, Portal5, portal.create(loc.new(creative_world, 3061.5,53, 2901.5), loc.new(creative_world, 3053.5,53, 2893.5), "east", "south"));
  19. map.add(portals, Portal6, portal.create(loc.new(creative_world, 3053.5,53, 2893.5), loc.new(creative_world, 3061.5,53, 2901.5), "south", "east"));
  20. id_effects = map.new();
  21. map.add(id_effects, speed1, "speed_gel");
  22. map.add(id_effects, speed2, "speed_gel");
  23. map.add(id_effects, jump1, "jump_gel");
  24. map.add(id_effects, jump2, "jump_gel");
  25. map.add(id_effects, jump3, "jump_gel");
  26. map.add(id_effects, Portal1, "portal");
  27. map.add(id_effects, Portal2, "portal");
  28. map.add(id_effects, Portal3, "portal");
  29. map.add(id_effects, Portal4, "portal");
  30. map.add(id_effects, Portal5, "portal");
  31. map.add(id_effects, Portal6, "portal");
  32. event.load("player_move");
  33. //----------------------------------------------------
  34. @wait
  35. wait();
  36. if(event == "player_move"){
  37. move_type = map.getOrDefault(id_effects, id, "none");
  38. if(move_type == "speed_gel"){
  39. gel.speed(player);
  40. }
  41. elseif(move_type == "jump_gel"){
  42. gel.jump(player);
  43. }
  44. elseif(move_type == "portal"){
  45. portal.enter(player, id);
  46. }
  47. }
  48. goto("wait");
  49. //----------------------------------------------------
  50. function gel.speed(player){
  51. living.addEffect(player,"SPEED",5,3,true);
  52. }
  53. function gel.jump(player){
  54. if(!player.isSneaking(player)){
  55. motion = entity.getMotion(player);
  56. look = entity.getLook(player);
  57. x = motion[0]+look[0]/3;
  58. y = 1.01;
  59. z = motion[2]+look[2]/3;
  60. entity.setMotion(player, x, y, z);
  61. }
  62. }
  63. function portal.create(to_loc, mid_loc, Direction_in, Direction_out){
  64. array = array.new(4);
  65. array[0] = Direction_in;//east // south
  66. array[1] = Direction_out;//east -> +X, west -> -X, south -> +Z, north -> -Z
  67. array[2] = to_loc;
  68. array[3] = mid_loc;
  69. return array;
  70. }
  71. function portal.enter(player, id){
  72. array = map.get($portals, id);
  73. Direction_in = array[0];
  74. Direction_out = array[1];
  75. to_loc = array[2];
  76. mid_loc = array[3];
  77. player_loc = entity.getLocation(player);
  78. player_yaw = loc.getYaw(player_loc);
  79. if(Direction_in == "east"){
  80. player_X = loc.getX(player_loc);
  81. mid_X = loc.getX(mid_loc);
  82. dif = mid_X - player_X;
  83. rel_yaw = player_yaw+90;
  84. }
  85. elseif(Direction_in == "south"){
  86. player_Z = loc.getZ(player_loc);
  87. mid_Z = loc.getZ(mid_loc);
  88. dif = mid_Z - player_Z;
  89. rel_yaw = player_yaw;
  90. }
  91. if(Direction_out == "east"){
  92. tp_loc = loc.mod(to_loc, 2*dif, 0, 0);
  93. rel_yaw += -90;
  94. }
  95. elseif(Direction_out == "south"){
  96. tp_loc = loc.mod(to_loc, 0, 0, 2*dif);
  97. }
  98. elseif(Direction_out == "west"){
  99. tp_loc = loc.mod(to_loc, -2*dif, 0, 0);
  100. rel_yaw += 90;
  101. }
  102. elseif(Direction_out == "north"){
  103. tp_loc = loc.mod(to_loc, 0, 0, -2*dif);
  104. rel_yaw += 180;
  105. }
  106. if(rel_yaw > 180){
  107. rel_yaw -= 360;
  108. }elseif(rel_yaw <= -180){
  109. rel_yaw += 360;
  110. }
  111. loc.setYaw(tp_loc, rel_yaw);
  112. loc.setPitch(tp_loc, loc.getPitch(player_loc));
  113. entity.teleport(player, tp_loc);
  114. }