mobarena.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. event.load("player_move");
  2. event.load("living_death");
  3. event.load("entity_join");
  4. x1 = 1000;
  5. y1 = 0;
  6. z1 = 1000;
  7. x2 = 1153;
  8. y2 = 56;
  9. z2 = 1129;
  10. overworld = world.getOverworld();
  11. loc1 = loc.new(overworld, x1, y1, z1);
  12. loc2 = loc.new(overworld, x2, y2, z2);
  13. cooldown = 400; //3 exe per minute
  14. arena_id = event.addMoveData(loc1, loc2, cooldown, -1);
  15. spawns = list.new();
  16. list.add(spawns, loc.new(overworld, 1030, 20, 1039));
  17. list.add(spawns, loc.new(overworld, 1051, 28, 1083));
  18. list.add(spawns, loc.new(overworld, 1008, 23, 1092));
  19. list.add(spawns, loc.new(overworld, 1082, 25, 1118));
  20. list.add(spawns, loc.new(overworld, 1087, 21, 1050));
  21. list.add(spawns, loc.new(overworld, 1072, 23, 1021));
  22. list.add(spawns, loc.new(overworld, 1135, 21, 1071));
  23. list.add(spawns, loc.new(overworld, 1125, 21, 1088));
  24. bosses = list.new();
  25. list.add(bosses, "zombie");
  26. list.add(bosses, "spider");
  27. list.add(bosses, "cave_spider");
  28. list.add(bosses, "wither_skeleton");
  29. list.add(bosses, "rabbit");
  30. list.add(bosses, "magma_cube");
  31. entities_list = list.new();
  32. iron_sword = read.item("minecraft:iron_sword");
  33. copper_coin = read.item("km:coin_copper");
  34. silver_coin = read.item("km:coin_silver");
  35. ruby = item.getRuby();
  36. msg("dev", "§bMobarena §rloaded.");
  37. @main
  38. wait();
  39. if(event == "player_move") {
  40. if(id == arena_id) {
  41. spawnArenaMob();
  42. }
  43. goto("main");
  44. }
  45. if(event == "living_death") {
  46. player = player.getFromDamageSource(damage_source);
  47. if(player == null) {
  48. goto("main");
  49. }
  50. ent_loc = entity.getLocation(living_entity);
  51. world_name = world.getName(loc.getWorld(ent_loc));
  52. if(world_name != "overworld") {
  53. goto("main");
  54. }
  55. x = loc.getX(ent_loc);
  56. z = loc.getZ(ent_loc);
  57. if(x < x1 || x > x2) {
  58. goto("main");
  59. }
  60. if(z < z1 || z > z2) {
  61. goto("main");
  62. }
  63. r = math.random(1, 200);
  64. if(r == 1) {
  65. item.drop(ent_loc, ruby);
  66. }
  67. if(entity.hasTag(living_entity, "mod_spawned")) {
  68. item.drop(ent_loc, silver_coin);
  69. } else {
  70. item.drop(ent_loc, copper_coin);
  71. }
  72. goto("main");
  73. }
  74. if(event == "entity_join") {
  75. if(!isLiving(entity)) {
  76. goto("main");
  77. }
  78. entity_type = entity.getType(entity);
  79. if(entity_type != "creeper") {
  80. goto("main");
  81. }
  82. ent_loc = entity.getLocation(entity);
  83. world_name = world.getName(loc.getWorld(ent_loc));
  84. if(world_name != "overworld") {
  85. goto("main");
  86. }
  87. x = loc.getX(ent_loc);
  88. y = loc.getY(ent_loc);
  89. z = loc.getZ(ent_loc);
  90. if(x < x1 || x > x2) {
  91. goto("main");
  92. }
  93. if(y < y1 || y > y2) {
  94. goto("main");
  95. }
  96. if(z < z1 || z > z2) {
  97. goto("main");
  98. }
  99. cancel = true;
  100. goto("main");
  101. }
  102. goto("main");
  103. function spawnArenaMob() {
  104. loc = getRandomLoc();
  105. boss = getRandomBoss();
  106. if(boss == "rabbit") {
  107. entity = entity.spawn(boss, loc, "{RabbitType:99}");
  108. } else {
  109. entity = entity.spawn(boss, loc);
  110. }
  111. if(boss == "zombie") {
  112. living.setPersistentMaxHealth(entity, 200);
  113. living.setHealth(entity, 200);
  114. living.setPersistentAttackDamage(entity, 10);
  115. living.setEquip(entity, "hand", $iron_sword);
  116. living.setPersistentKnockbackResistance(entity, 3);
  117. living.setPersistentFollowRange(entity, 50);
  118. living.setPersistentAttackKnockback(entity, 10);
  119. }
  120. elseif(boss == "wither_skeleton") {
  121. living.setPersistentMaxHealth(entity, 250);
  122. living.setHealth(entity, 250);
  123. living.setPersistentAttackDamage(entity, 15);
  124. living.setEquip(entity, "hand", $iron_sword);
  125. living.setPersistentKnockbackResistance(entity, 3);
  126. living.setPersistentFollowRange(entity, 50);
  127. living.setPersistentAttackKnockback(entity, 10);
  128. }
  129. elseif(boss == "spider") {
  130. living.setPersistentMaxHealth(entity, 150);
  131. living.setHealth(entity, 150);
  132. living.setPersistentAttackDamage(entity, 8);
  133. living.setPersistentKnockbackResistance(entity, 2);
  134. living.setPersistentFollowRange(entity, 50);
  135. living.setPersistentAttackKnockback(entity, 5);
  136. }
  137. elseif(boss == "cave_spider") {
  138. living.setPersistentMaxHealth(entity, 100);
  139. living.setHealth(entity, 100);
  140. living.setPersistentAttackDamage(entity, 7);
  141. living.setPersistentKnockbackResistance(entity, 2);
  142. living.setPersistentFollowRange(entity, 50);
  143. living.setPersistentAttackKnockback(entity, 5);
  144. }
  145. elseif(boss == "rabbit") {
  146. living.setPersistentMaxHealth(entity, 50);
  147. living.setHealth(entity, 50);
  148. living.setPersistentAttackDamage(entity, 6);
  149. living.setPersistentKnockbackResistance(entity, 2);
  150. living.setPersistentFollowRange(entity, 50);
  151. living.setPersistentAttackKnockback(entity, 5);
  152. }
  153. elseif(boss == "magma_cube") {
  154. living.setPersistentMaxHealth(entity, 50);
  155. living.setHealth(entity, 50);
  156. living.setPersistentAttackDamage(entity, 6);
  157. living.setPersistentKnockbackResistance(entity, 2);
  158. living.setPersistentFollowRange(entity, 50);
  159. living.setPersistentAttackKnockback(entity, 5);
  160. }
  161. list.add($entities_list, entity);
  162. sgoto(2, "sgoto_updateEntityName");
  163. //living.setEquip(entity, );
  164. //living.setMaxHealth(entity, );
  165. //living.setAttackKnockback(entity, );
  166. //living.setAttackDamage(entity, );
  167. //living.setAttackSpeed(entity, );
  168. //living.setFollowRange(entity, );
  169. //living.setArmor(entity, );
  170. //living.setArmorThoughness(entity, );
  171. //living.setMovementSpeed(entity, );
  172. //living.setKnockbackResistance(entity, );
  173. }
  174. @sgoto_updateEntityName
  175. iter = list.iterator(entities_list);
  176. while(hasNext(iter)) {
  177. updateEntityName(next(iter));
  178. }
  179. list.clear(entities_list);
  180. goto("main");
  181. function getRandomLoc() {
  182. index = math.random(0, list.getSize($spawns) - 1);
  183. return list.getIndex($spawns, index);
  184. }
  185. function getRandomBoss() {
  186. index = math.random(0, list.getSize($bosses) - 1);
  187. return list.getIndex($bosses, index);
  188. }
  189. function updateEntityName(living_entity) {
  190. entity_name = entity.getName(living_entity);
  191. max_health = living.getMaxHealth(living_entity);
  192. health = text.number(math.round(living.getHealth(living_entity)));
  193. max_health = text.number(math.roundComma(max_health, 1));
  194. heart_index = text.indexOf(entity_name, "❤", 0);
  195. if(heart_index == -1) {
  196. //Kein Herz gefunden
  197. setEntityName(living_entity, health, max_health, entity_name);
  198. return;
  199. }
  200. next_new_line = text.indexOf(entity_name, "\n", heart_index);
  201. if(next_new_line == -1) {
  202. //Rechts vom Herz keine New-Line gefunden
  203. setEntityName(living_entity, health, max_health, null);
  204. return;
  205. }
  206. entity_name = text.subString(entity_name, next_new_line + 1, text.length(entity_name));
  207. setEntityName(living_entity, health, max_health, entity_name);
  208. }
  209. function setEntityName(living_entity, health, max_health, entity_name) {
  210. if(entity_name == null) {
  211. entity.setName(living_entity, concat(health, "/", max_health, " §c❤"), false);
  212. return;
  213. }
  214. entity.setName(living_entity, concat(health, "/", max_health, " §c❤\n", entity_name), false);
  215. }