u_quest.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. function stage.increase(player) {
  2. $stage++;
  3. quest.display(player, $quest_name, $stage, $all_stages);
  4. sound = sound.get("minecraft:entity.experience_orb.pickup");
  5. category = sound.getCategory("MASTER");
  6. sound.spawnForPlayer(player, sound, category);
  7. }
  8. function quest.start(player, path) {
  9. modTimer(-45);
  10. script = script.start(path, "utils/u_quest", "utils/u_general", "utils/u_questerror");
  11. if(script == null) {
  12. msg.dev("quest not started");
  13. return;
  14. }
  15. quest.addPlayer(script, player);
  16. script.setVar(script, "player", player);
  17. script.setVar(script, "script", script);
  18. script.callEvent("quest_start", script);
  19. inv.close(player);
  20. }
  21. function player.unlockedLumberjack(player_or_id) {
  22. config = playerdata.getSurvival(player_or_id);
  23. return config.getBool(config, "skillshop.lumberjack", false);
  24. }
  25. function player.unlockLumberjack(player_or_id) {
  26. config = playerdata.getSurvival(player_or_id);
  27. config.set(config, "skillshop.lumberjack", true);
  28. config.saveAsync(config);
  29. }
  30. function player.unlockedMage(player_or_id) {
  31. config = playerdata.getSurvival(player_or_id);
  32. return config.getBool(config, "skillshop.mage", false);
  33. }
  34. function player.unlockMage(player_or_id) {
  35. config = playerdata.getSurvival(player_or_id);
  36. config.set(config, "skillshop.mage", true);
  37. config.saveAsync(config);
  38. }
  39. function player.getShipProgress(player_or_id) {
  40. config = playerdata.getSurvival(player_or_id);
  41. return config.getDouble(config, "ship.progress", 0);
  42. }
  43. function player.setShipProgress(player_or_id, progress) {
  44. config = playerdata.getSurvival(player_or_id);
  45. old_progress = config.getDouble(config, "ship.progress", 0);
  46. if(progress > old_progress) {
  47. config.set(config, "ship.progress", progress);
  48. config.saveAsync(config);
  49. }
  50. }
  51. function citizen.giveItem(citizen_name, player, needed_type_or_tag, needed_amount) {
  52. if(needed_amount == 0) {
  53. return -1;
  54. }
  55. item = living.getHand(player);
  56. if(item == null) {
  57. return needed_amount;
  58. }
  59. item_type = item.getType(item);
  60. citizen_name = string.concat("§d", citizen_name);
  61. needed = false;
  62. tag_check = false;
  63. if(isMaterial(needed_type_or_tag)) {
  64. if(item_type == needed_type_or_tag) {
  65. needed = true;
  66. }
  67. } else {
  68. if(item.hasTag(item, needed_type_or_tag)) {
  69. needed = true;
  70. tag_check = true;
  71. }
  72. }
  73. if(needed) {
  74. amount_not_removed = player.removeItem(player, item.new(item_type, needed_amount));
  75. if(amount_not_removed == 0) {
  76. return 0;
  77. }
  78. player.removeItem(player, item.new(item_type, amount_not_removed));
  79. rest_item_amount = needed_amount - amount_not_removed;
  80. rest_item = item.new(item_type, rest_item_amount);
  81. rest_item = player.removeItemNbt(player, rest_item);
  82. rest_item_amount = item.getAmount(rest_item);
  83. if(rest_item_amount > 0) {
  84. if(tag_check) {
  85. rest_item = player.removeItemTag(player, needed_type_or_tag, rest_item_amount);
  86. rest_item_amount = item.getAmount(rest_item);
  87. if(rest_item_amount > 0) {
  88. msg.prefix(player, citizen_name, string.concat("I need ", string.number(rest_item_amount), " more of these please."));
  89. }
  90. } else {
  91. msg.prefix(player, citizen_name, string.concat("I need ", string.number(rest_item_amount), " more of these please."));
  92. }
  93. }
  94. return rest_item_amount;
  95. }
  96. msg.prefix(player, citizen_name, "I do not need this.");
  97. return needed_amount;
  98. }
  99. /*
  100. stable(stable_mid_loc, stable_spawn_loc_list) while there aren't enough, spawns animals
  101. */
  102. function stable(stable_mid_loc, stable_spawn_loc_list){
  103. living_list = living.near(stable_mid_loc, 10);
  104. list_iterator = iterator(living_list);
  105. cow_count = 0;
  106. pig_count = 0;
  107. sheep_count = 0;
  108. while(hasnext(list_iterator)){
  109. living_entity_type = entity.getType(next(list_iterator));
  110. if(living_entity_type == "cow"){
  111. cow_count++;
  112. }elseif(living_entity_type == "pig"){
  113. pig_count++;
  114. }elseif(living_entity_type == "sheep"){
  115. sheep_count++;
  116. }
  117. }
  118. while(cow_count < 4){//cow_max
  119. spawned_entity = entity.spawn(loc.mod(list.getIndex(stable_spawn_loc_list, math.random(0, $spawn_list_size)), 0.5, 0, 0.5), "COW");
  120. cow_count++;
  121. }
  122. while(pig_count < 3){//pig_max
  123. spawned_entity = entity.spawn(loc.mod(list.getIndex(stable_spawn_loc_list, math.random(0, $spawn_list_size)), 0.5, 0, 0.5), "PIG");
  124. pig_count++;
  125. }
  126. while(sheep_count < 5){//sheep_max
  127. spawned_entity = entity.spawn(loc.mod(list.getIndex(stable_spawn_loc_list, math.random(0, $spawn_list_size)), 0.5, 0, 0.5), "SHEEP");
  128. sheep_count++;
  129. }
  130. }
  131. /*
  132. stable.getSpawn_locs(loc) returns list with all spawn_locations for animals in given surrounding stable
  133. */
  134. function stable.getSpawn_locs(loc){
  135. stable_spawn_loc_list = list.new();
  136. list.add(stable_spawn_loc_list, loc.mod(loc, 0.5, 1, 0.5));
  137. $stable_temp_list = list.new();
  138. $stable_temp_list2 = list.new();
  139. list.add($stable_temp_list, loc);
  140. while(list.getSize($stable_temp_list) != 0){
  141. block_loc = list.getIndex($stable_temp_list, 0);
  142. list.removeIndex($stable_temp_list, 0);
  143. distance = loc.distance(block_loc, loc);
  144. if(distance < 25){
  145. temp_block = stable.addLoc_if(loc.mod(block_loc,1,0,0));
  146. if(temp_block != null){
  147. list.add(stable_spawn_loc_list, temp_block);
  148. }
  149. temp_block = stable.addLoc_if(loc.mod(block_loc,-1,0,0));
  150. if(temp_block != null){
  151. list.add(stable_spawn_loc_list, temp_block);
  152. }
  153. temp_block = stable.addLoc_if(loc.mod(block_loc,0,0,1));
  154. if(temp_block != null){
  155. list.add(stable_spawn_loc_list, temp_block);
  156. }
  157. temp_block = stable.addLoc_if(loc.mod(block_loc,0,0,-1));
  158. if(temp_block != null){
  159. list.add(stable_spawn_loc_list, temp_block);
  160. }
  161. temp_block = stable.addLoc_if(loc.mod(block_loc,1,1,0));
  162. if(temp_block != null){
  163. list.add(stable_spawn_loc_list, temp_block);
  164. }
  165. temp_block = stable.addLoc_if(loc.mod(block_loc,-1,1,0));
  166. if(temp_block != null){
  167. list.add(stable_spawn_loc_list, temp_block);
  168. }
  169. temp_block = stable.addLoc_if(loc.mod(block_loc,0,1,1));
  170. if(temp_block != null){
  171. list.add(stable_spawn_loc_list, temp_block);
  172. }
  173. temp_block = stable.addLoc_if(loc.mod(block_loc,0,1,-1));
  174. if(temp_block != null){
  175. list.add(stable_spawn_loc_list, temp_block);
  176. }
  177. temp_block = stable.addLoc_if(loc.mod(block_loc,1,-1,0));
  178. if(temp_block != null){
  179. list.add(stable_spawn_loc_list, temp_block);
  180. }
  181. temp_block = stable.addLoc_if(loc.mod(block_loc,-1,-1,0));
  182. if(temp_block != null){
  183. list.add(stable_spawn_loc_list, temp_block);
  184. }
  185. temp_block = stable.addLoc_if(loc.mod(block_loc,0,-1,1));
  186. if(temp_block != null){
  187. list.add(stable_spawn_loc_list, temp_block);
  188. }
  189. temp_block = stable.addLoc_if(loc.mod(block_loc,0,-1,-1));
  190. if(temp_block != null){
  191. list.add(stable_spawn_loc_list, temp_block);
  192. }
  193. }
  194. }
  195. return stable_spawn_loc_list;
  196. }
  197. function stable.addLoc_if(temp_loc){
  198. if(!list.contains($stable_temp_list2, temp_loc)){
  199. temp_block = block.get(temp_loc);
  200. temp_block2 = loc.mod(temp_loc, 0, 1, 0);
  201. temp_type1 = block.getType(temp_block);
  202. temp_type2 = block.getType(block.get(temp_block2));
  203. temp_type3 = block.getType(block.get(loc.mod(temp_block2, 0, 1, 0)));
  204. if(temp_type1 == $grass_block_material && temp_type2 == $air_material && temp_type3 == $air_material){
  205. list.add($stable_temp_list, temp_loc);
  206. list.add($stable_temp_list2, temp_loc);
  207. return temp_block2;
  208. }
  209. }
  210. }