gravity_core.txt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. sign.started(gamesignloc);
  2. maxplayers = 1;
  3. gamename = "§aGravity";
  4. x1 = math.min(loc.getX(edge1), loc.getX(edge2));
  5. x2 = math.max(loc.getX(edge1), loc.getX(edge2));
  6. y1 = math.min(loc.getY(edge1), loc.getY(edge2));
  7. y2 = math.max(loc.getY(edge1), loc.getY(edge2));
  8. z1 = math.min(loc.getZ(edge1), loc.getZ(edge2));
  9. z2 = math.max(loc.getZ(edge1), loc.getZ(edge2));
  10. mid_x = (x1+x2)/2;
  11. mid_y = (y1+y2)/2;
  12. mid_z = (z1+z2)/2;
  13. //------------------
  14. air_material = material.get("AIR");
  15. stone_material = material.get("STONE");
  16. /*box_iterator = loc.iterator(games, x1,y1,z1,x2,y2,z2);
  17. grav_down = list.new();
  18. while(hasnext(box_iterator)){
  19. temp_block = block.get(next(box_iterator));
  20. temp_type = block.getType(temp_block);
  21. if(temp_type != air_material){
  22. temp_array = array.new(2);
  23. temp_array[0] = temp_block;
  24. temp_array[1] = temp_type;
  25. list.add(grav_down, temp_array);
  26. }
  27. }
  28. //grav_down
  29. grav_up = list.new();
  30. grav_north = list.new();
  31. grav_south = list.new();
  32. grav_west = list.new();
  33. grav_east = list.new();
  34. box.create_rotations();*/
  35. active_grav = "down";
  36. possible_names_map = list.new();
  37. list.add(possible_names_map, "down");
  38. list.add(possible_names_map, "up");
  39. list.add(possible_names_map, "north");
  40. list.add(possible_names_map, "south");
  41. list.add(possible_names_map, "west");
  42. list.add(possible_names_map, "east");
  43. item_down = item.new(material.get("purple_concrete"),1);
  44. item.setName(item_down, text.new("down"));
  45. item_up = item.new(material.get("yellow_concrete"),1);
  46. item.setName(item_up, text.new("up"));
  47. item_north = item.new(material.get("pink_concrete"),1);
  48. item.setName(item_north, text.new("north"));
  49. item_south = item.new(material.get("magenta_concrete"),1);
  50. item.setName(item_south, text.new("south"));
  51. item_west = item.new(material.get("red_concrete"),1);
  52. item.setName(item_west, text.new("west"));
  53. item_east = item.new(material.get("blue_concrete"),1);
  54. item.setName(item_east, text.new("east"));
  55. //---events---
  56. event.load("block_click");
  57. event.load("entity_damage");
  58. event.load("player_move");
  59. event.load("player_quit");
  60. event.load("player_giveup");
  61. event.load("minigame_join");
  62. event.load("block_break");
  63. //------------
  64. @wait
  65. wait();
  66. if(event == "entity_damage") {
  67. if(!isPlayer(entity)) {
  68. goto("wait");
  69. }
  70. player = entity;
  71. }
  72. if(!player.hasMinigameId(player, script_id)) {
  73. goto("wait");
  74. }
  75. if(event == "minigame_join"){
  76. player.clearInventory(player);
  77. entity.teleport(player, Start_Pos);
  78. player_inv = player.getInv(player);
  79. inv.setItem(player_inv, 0, item_down);
  80. inv.setItem(player_inv, 1, item_up);
  81. inv.setItem(player_inv, 2, item_north);
  82. inv.setItem(player_inv, 3, item_south);
  83. inv.setItem(player_inv, 4, item_west);
  84. inv.setItem(player_inv, 5, item_east);
  85. box_iterator = loc.iterator(games, x1,y1,z1,x2,y2,z2);
  86. grav_down = list.new();
  87. while(hasnext(box_iterator)){
  88. temp_block = block.get(next(box_iterator));
  89. temp_type = block.getType(temp_block);
  90. if(temp_type != air_material){
  91. temp_array = array.new(2);
  92. temp_array[0] = temp_block;
  93. temp_array[1] = temp_type;
  94. list.add(grav_down, temp_array);
  95. }
  96. }
  97. //grav_down
  98. grav_up = list.new();
  99. grav_north = list.new();
  100. grav_south = list.new();
  101. grav_west = list.new();
  102. grav_east = list.new();
  103. box.create_rotations();
  104. }
  105. if(event == "block_break"){
  106. cancel = true;
  107. goto("wait");
  108. }
  109. if(event == "entity_damage") {
  110. cancel = true;
  111. goto("wait");
  112. }
  113. if(event == "block_click"){
  114. if(action == "PHYSICAL"){
  115. goto("wait");
  116. }
  117. player_hand = living.getHand(player);
  118. if(!item.hasName(player_hand)){
  119. goto("wait");
  120. }
  121. item_name = string.text(item.getName(player_hand));
  122. if(!list.contains(possible_names_map, item_name)){
  123. goto("wait");
  124. }
  125. cancel = true;
  126. active_grav = box.rotate(active_grav, item_name);
  127. }
  128. if(event == "player_move"){
  129. game_stop("You did it!");
  130. goto("wait");
  131. }
  132. if(event == "player_quit"){
  133. box.rotate(active_grav, "down");
  134. game_stop(null);
  135. }
  136. if(event == "player_giveup"){
  137. box.rotate(active_grav, "down");
  138. game_stop("You have left the game");
  139. }
  140. goto("wait");
  141. //---functions---
  142. function box.create_rotations(){
  143. list_iterator = iterator($grav_down);
  144. a = 0;
  145. while(hasnext(list_iterator)){
  146. if(a++ > 75){
  147. waitfor(2);
  148. a = 0;
  149. }
  150. temp_array = next(list_iterator);
  151. temp_loc = block.getLocation(temp_array[0]);
  152. list.add($grav_up, array.create(block.get(box.rotate_location(temp_loc, "down", "up")), temp_array[1]));
  153. list.add($grav_north, array.create(block.get(box.rotate_location(temp_loc, "down", "north")), temp_array[1]));
  154. list.add($grav_south, array.create(block.get(box.rotate_location(temp_loc, "down", "south")), temp_array[1]));
  155. list.add($grav_west, array.create(block.get(box.rotate_location(temp_loc, "down", "west")), temp_array[1]));
  156. list.add($grav_east, array.create(block.get(box.rotate_location(temp_loc, "down", "east")), temp_array[1]));
  157. }
  158. }
  159. function array.create(arg1, arg2){
  160. temp_array = array.new(2);
  161. temp_array[0] = arg1;
  162. temp_array[1] = arg2;
  163. return temp_array;
  164. }
  165. function box.rotate(from_rotation, to_rotation){
  166. New_Motion = box.rotate_Rotation(box.rotate_Rotation(entity.getMotion($player), from_rotation), to_rotation);
  167. Look_Array = entity.getLook($player);
  168. New_Look = box.rotate_Rotation(box.rotate_Rotation(Look_Array, from_rotation), to_rotation);
  169. player_loc = entity.getLocation($player);
  170. teleport_location = box.rotate_location(player_loc, from_rotation, to_rotation);
  171. entity.setGravity($player, false);
  172. entity.setMotion($player, 0, 0, 0);
  173. box.place(from_rotation, true);//clear
  174. box.place(to_rotation, false);//place
  175. entity.teleport($player, teleport_location);
  176. entity.setGravity($player, true);
  177. entity.setMotion($player, New_Motion[0], New_Motion[1], New_Motion[2]);
  178. entity.setLook($player, New_Look[0], New_Look[1], New_Look[2]);
  179. return to_rotation;
  180. }
  181. function box.place(rotation, clear){
  182. if(rotation == "down"){
  183. list_iterator = iterator($grav_down);
  184. }elseif(rotation == "up"){
  185. list_iterator = iterator($grav_up);
  186. }elseif(rotation == "north"){
  187. list_iterator = iterator($grav_north);
  188. }elseif(rotation == "south"){
  189. list_iterator = iterator($grav_south);
  190. }elseif(rotation == "west"){
  191. list_iterator = iterator($grav_west);
  192. }elseif(rotation == "east"){
  193. list_iterator = iterator($grav_east);
  194. }
  195. while(hasnext(list_iterator)){
  196. temp_array = next(list_iterator);
  197. if(clear){
  198. block_type = $air_material;
  199. }else{
  200. block_type = temp_array[1];
  201. }
  202. block.setMaterial(temp_array[0], block_type, false);//block.getType(temp_block));
  203. }
  204. }
  205. function box.rotate_location(loc, from_rotation, to_rotation){
  206. abs_loc = loc.mod(loc, 0, 0, 0);
  207. if(from_rotation == to_rotation){
  208. return abs_loc;
  209. }
  210. Coord_Array = array.new(3);
  211. Coord_Array[0] = loc.getX(abs_loc)-$mid_x;//X
  212. Coord_Array[1] = loc.getY(abs_loc)-$mid_y;//Y
  213. Coord_Array[2] = loc.getZ(abs_loc)-$mid_z;//Z
  214. //Coord_Array = box.rotate_Rotation(Coord_Array, from_rotation);
  215. Coord_Array = box.rotate_Rotation(box.rotate_Rotation(Coord_Array, from_rotation), to_rotation);
  216. loc.set(abs_loc, Coord_Array[0] + $mid_x, Coord_Array[1] + $mid_y, Coord_Array[2] + $mid_z);
  217. return abs_loc;
  218. }
  219. function box.rotate_Rotation(Coord_Array, rotation){
  220. New_Coord_Array = array.new(3);
  221. if(rotation == "down"){
  222. return Coord_Array;
  223. }elseif(rotation == "up"){
  224. New_Coord_Array[0] = Coord_Array[0]; // X = X
  225. New_Coord_Array[1] = -Coord_Array[1]; // Y = -Y
  226. New_Coord_Array[2] = Coord_Array[2]; // Z = Z
  227. }elseif(rotation == "north"){
  228. New_Coord_Array[0] = Coord_Array[0]; // X = X
  229. New_Coord_Array[1] = Coord_Array[2]; // Y = Z
  230. New_Coord_Array[2] = Coord_Array[1]; // Z = Y
  231. }elseif(rotation == "south"){
  232. New_Coord_Array[0] = Coord_Array[0]; // X = X
  233. New_Coord_Array[1] = -Coord_Array[2]; // Y = -Z
  234. New_Coord_Array[2] = -Coord_Array[1]; // Z = -Y
  235. }elseif(rotation == "west"){
  236. New_Coord_Array[0] = Coord_Array[1]; // X = -Y
  237. New_Coord_Array[1] = Coord_Array[0]; // Y = X
  238. New_Coord_Array[2] = Coord_Array[2]; // Z = Z
  239. }elseif(rotation == "east"){
  240. New_Coord_Array[0] = -Coord_Array[1]; // X = Y
  241. New_Coord_Array[1] = -Coord_Array[0]; // Y = -X
  242. New_Coord_Array[2] = Coord_Array[2]; // Z = Z
  243. }
  244. return New_Coord_Array;
  245. }
  246. function box.rotate_look(){
  247. return;
  248. }
  249. function box.get_look(){
  250. return;
  251. }
  252. function game_stop(message){
  253. if(message != null){
  254. msg.prefix($player, $gamename, message);
  255. }
  256. script = script.getFromId($script_id);
  257. minigame.kickPlayer(script, $player);
  258. minigame.term(script, $gamesignloc);
  259. term();
  260. }