Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. // Pocket Priest
  2. // Will follow your party around and auto-heal the members based on a priority calculation.
  3. // It looks at their max hp vs current hp and heals the person with the highest percentage loss.
  4. //Courtesy of: Sulsaries and JourneyOver
  5. //Version 1.1.0
  6.  
  7. //Automatic Potion Purchasing!
  8. var purchase_pots = true; //Set to true in order to allow potion purchases
  9. var pots_minimum = 50; //If you have less than this, you will buy
  10. var pots_to_buy = 1000; //This is how many you will buy
  11.  
  12. var party_list = [
  13. {
  14. name: "",
  15. priority: 0.0
  16. },
  17. {
  18. name: "",
  19. priority: 0.0
  20. },
  21. {
  22. name: "",
  23. priority: 0.0
  24. },
  25. {
  26. name: "",
  27. priority: 0.0
  28. },
  29. {
  30. name: "",
  31. priority: 0.0
  32. },
  33. {
  34. name: "",
  35. priority: 0.0
  36. }]
  37.  
  38. var party_count = 0;
  39. //Fills the Party List
  40. function fill_party_list() {
  41. var min_d = 999999,
  42. target = null;
  43. party_count = 0;
  44. set_message("Making party_list");
  45. party_list[party_count].name = character.name;
  46. party_count++;
  47. for (id in parent.entities) {
  48.  
  49. var current = parent.entities[id];
  50. if (current.player === false || current.dead || current.party != character.party /* || current.hp==current.max_hp*/ ) {
  51.  
  52. continue;
  53. }
  54. var c_dist = parent.distance(character, current);
  55. if (c_dist < min_d && current.player === true) {
  56. target = current;
  57. party_list[party_count].name = target.name;
  58. party_count++;
  59. set_message("Added a member.");
  60. }
  61. }
  62. return;
  63. }
  64.  
  65. setInterval(function() {
  66.  
  67. //Loot available chests
  68. loot();
  69.  
  70.  
  71. //Heal and restore mana if required
  72. if (character.hp / character.max_hp < 0.3) {
  73. parent.use('hp');
  74. if (character.hp <= 100)
  75. parent.socket.emit("transport", {
  76. to: "main"
  77. });
  78. //Panic Button
  79. }
  80.  
  81. if (character.mp / character.max_mp < 0.3)
  82. parent.use('mp');
  83. //Constrained Healing
  84.  
  85. //Place inside setInterval to check potions when turned on.
  86. if (purchase_pots) {
  87. purchase_potions();
  88. }
  89.  
  90. //Re-enable this line if you need to move without using abilities
  91. //if(character.moving) return;
  92.  
  93. //Set target to null;
  94. var target = null;
  95. //Update party list
  96. fill_party_list();
  97. //show_json(party_list);
  98. set_message(party_count);
  99. //set_message(party_list[0].name);
  100.  
  101. for (var x = 0; x < party_count; x++) {
  102. set_message("Setting Priority");
  103. target = get_player(party_list[x].name);
  104. set_message("Not broken!");
  105. set_message(target.name);
  106. if (target) change_target(target);
  107. party_list[x].priority = (target.max_hp - target.hp) / target.max_hp;
  108. set_message(party_list[x].priority);
  109. set_message("Priority set.");
  110. }
  111.  
  112. var highest_priority = 0;
  113. for (var x = 0; x < party_count; x++) {
  114. set_message("Finding highest priority.");
  115. if (party_list[x].priority > party_list[highest_priority].priority) {
  116. highest_priority = x;
  117. }
  118. }
  119. set_message("Highest priority found.");
  120.  
  121.  
  122. //target = get_player(party_list[0].name);
  123.  
  124. target = get_player(party_list[highest_priority].name);
  125. if (party_list[highest_priority].priority > .10 && !target.rip) {
  126. if (target) change_target(target);
  127. heal(target);
  128. set_message("Healing");
  129. }
  130.  
  131. if (!in_attack_range(target)) {
  132. move_to(target, character.range);
  133.  
  134. set_message("Moving to Priority");
  135. }
  136.  
  137. //set_message(party_count);
  138.  
  139. }, 1000 / 3); // Loops every 1/4 seconds.
  140.  
  141. function purchase_potions() {
  142. set_message("Buying pots.");
  143. if (character.items[0].q < pots_minimum) {
  144. parent.buy("hpot0", pots_to_buy);
  145. }
  146. if (character.items[1].q < pots_minimum) {
  147. parent.buy("mpot0", pots_to_buy);
  148. }
  149. }
  150.  
  151. function move_to(char, distance) {
  152. if (!char) return;
  153. var dist_x = character.real_x - char.real_x;
  154. var dist_y = character.real_y - char.real_y;
  155.  
  156. var from_char = sqrt(dist_x * dist_x + dist_y * dist_y);
  157.  
  158. var perc = from_char / distance;
  159.  
  160. if (perc > 1.01) {
  161. move(
  162. character.real_x - (dist_x - dist_x / perc),
  163. character.real_y - (dist_y - dist_y / perc)
  164. );
  165. return true;
  166. }
  167. return false;
  168. };
  169. var attack_mode=true
  170. setInterval(function(){
  171. if (character.hp / character.max_hp < 0.5) {
  172. parent.use('hp');
  173. }
  174. if (character.mp / character.max_mp < 0.3)
  175. parent.use('mp');
  176. loot();
  177. if(!attack_mode || character.moving) return;
  178. var target=get_targeted_monster();
  179. if(!target)
  180. {
  181. target=get_nearest_monster({min_xp:16010,max_att:275});
  182. if(!target){
  183. target=get_nearest_monster({min_xp:16010,max_att:275});
  184. }
  185. if(target) change_target(target);
  186. else
  187. {
  188. set_message("No Monsters");
  189. return;
  190. }
  191. }
  192. if(!in_attack_range(target))
  193. {
  194. move(
  195. character.real_x+(target.real_x-character.real_x)/2,
  196. character.real_y+(target.real_y-character.real_y)/2
  197. );
  198. }
  199. else if(can_attack(target))
  200. {
  201. set_message("Attacking");
  202. attack(target);
  203. }
  204. },1000/4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement