Advertisement
kolton

Untitled

Dec 14th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. function NTA_Dodge(target, distance) {
  2. var i, j, coordx, coordy, monster, count,
  3. maxcount = 999,
  4. coords = [],
  5. goodCoords = [],
  6. monList = [],
  7. angles = [45, 90, 135, 180, 225, 270, 305, 360];
  8.  
  9. for (i = 0; i < angles.length; i += 1) {
  10. coordx = Math.round((Math.cos(angles[i] * Math.PI / 180)) * distance + target.x);
  11. coordy = Math.round((Math.sin(angles[i] * Math.PI / 180)) * distance + target.y);
  12.  
  13. if (CheckCollision(me.areaid, coordx, coordy, 1)) {
  14. coords.push([coordx, coordy]);
  15. }
  16. }
  17.  
  18. if (coords.length === 0) { // no valid positions - don't move
  19. return true;
  20. }
  21.  
  22. coords.sort(NTA_SortRooms);
  23.  
  24. monster = GetUnit(1);
  25.  
  26. if (monster) {
  27. do {
  28. if (monster.hp > 0) {
  29. monList.push(new NTA_MonsterStats(target));
  30. }
  31. } while (monster.GetNext());
  32. }
  33.  
  34. for (i = 0; i < coords.length; i += 1) {
  35. count = 0;
  36.  
  37. for (j = 0; j < monList.length; j += 1) {
  38. if (monList[j].hp > 0 && GetDistance(monList[j].x, monList[j].y, coords[i][0], coords[i][1]) < 10) {
  39. count += 1;
  40. }
  41. }
  42.  
  43. if (count < maxcount) {
  44. goodCoords = [coords[i][0], coords[i][1]];
  45. maxcount = count;
  46.  
  47. if (count === 0) {
  48. break;
  49. }
  50. }
  51. }
  52.  
  53. if (goodCoords.length > 0) { // just in case goodCoords is empty (shouldn't happen)
  54. if (Math.abs(me.x - goodCoords[0]) < 3 && Math.abs(me.y - goodCoords[1]) < 3) { // close enough
  55. return true;
  56. }
  57.  
  58. Say("!Dodge " + target.name);
  59. NTM_MoveTo(me.areaid, goodCoords[0], goodCoords[1]);
  60. }
  61.  
  62. return true;
  63. }
  64.  
  65. function NTA_SortRooms(a, b) {
  66. if (GetDistance(me.x, me.y, a[0], a[1]) < GetDistance(me.x, me.y, b[0], b[1])) {
  67. return -1;
  68. }
  69.  
  70. return 1;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement