Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.15 KB | None | 0 0
  1. script_runner = {
  2.         nRcombo = 0, -- selected destination number (combo box)
  3.         runit = false,
  4.         distDestination = 0,
  5.     useNaveMesh = false,
  6.     enemyObj = nil,-- from script grind
  7.     lastnavIndex = 0,
  8.         nextNodeDistance = 5,
  9.         tx = 0,
  10.         ty = 0,
  11.         tz = 0,
  12.     dx = 0,
  13.     dy = 0,
  14.     dz = 0,
  15.         _x = 0,
  16.         _y = 0,
  17.         _z = 0,
  18.     destination = {},
  19.     destinationName = {},
  20.     destNum = 1,
  21.     isSetup = false,
  22.     tic = 150,
  23.     timer = 0,
  24.     destinationChanged = false,
  25.     genTimer = 0,
  26.     movingToSafespot = false,
  27.     waitTimer  = 0,
  28.     generating = false
  29. }
  30.  
  31. function script_runner:setup()
  32.     -- Add Destinations
  33.    
  34.     script_runner:addDestination("shimmering flats near finish line", -6170.06, -4014.37, -58.75, 1, 400);
  35.     script_runner:addDestination("shimmering flats half way", -5980.17, -4015.87, -58.75, 1, 400);
  36.     script_runner:addDestination("desolace innkeeper ally", 247.23300170898, 1255.0699462891, 192.16200256348, 1, 405);
  37.     script_runner:addDestination("desolace outside niehls point", -58.16849899292, 1217.5465087891, 91.539474487305, 1, 405);
  38.  
  39.     script_runner:addDestination("wetlands center gob vendor", -3198.2846679688, -2471.3728027344, 10.032402992249, 0, 11);
  40.     script_runner:addDestination("westfal near gy", -10476.274414063, 1190.9742431641, 56.2785987854, 0, 40);
  41.  
  42.  
  43.  
  44.     self.isSetup = true;
  45. end
  46.  
  47. function script_runner:addDestination(name, x, y, z, continentID, mapID)
  48.     -- Extra table for the combo box
  49.     self.destinationName[self.destNum] = name;
  50.  
  51.     self.destination[self.destNum] = {};
  52.     self.destination[self.destNum]['name'] = name;
  53.     self.destination[self.destNum]['x'] = x;
  54.     self.destination[self.destNum]['y'] = y;
  55.     self.destination[self.destNum]['z'] = z;
  56.     self.destination[self.destNum]['continentID'] = continentID;
  57.     self.destination[self.destNum]['mapID'] = mapID;
  58.     self.destNum = self.destNum + 1;
  59. end
  60.  
  61. local function rP(text, r, g, b)
  62.     r = r or .91
  63.     g = g or .91
  64.     b = b or .91
  65.     local header = "|cFFFC0000[|r|cFFFF7F00oGasai - Runner|r|cFFFC0000]|r "
  66.     DEFAULT_CHAT_FRAME:AddMessage(header .. text, r, g, b)
  67. end
  68.      
  69. local function GetDistance2D(_1x, _1y, _2x, _2y)
  70.     return math.sqrt((_1x - _2x)^2 + (_1y - _2y)^2)
  71. end
  72.  
  73. --short handle for toconsole
  74. function tc1(text)
  75. ToConsole(text)
  76. end
  77.  
  78. --short handle for rare toconsole
  79. function tc2(text)
  80. ToConsole(text)
  81. end
  82.  
  83. -- for short term debugging "toConsoleTest"
  84. function tct(text)
  85. ToConsole(text)
  86. end
  87.  
  88. -- tc for obj table in CheckNextNodeToMobsDistance
  89. function tcOT1(text)
  90. --ToConsole(text)
  91. end
  92.  
  93. function script_runner:setWaitTimer(ms)
  94.     self.waitTimer = GetTimeEX() + ms;
  95. end
  96.  
  97. function script_runner:drawAvoidMobTriangle() -- not used atm
  98. -- need to draw 3 lines my xyz mob xzy safespot xyz
  99. local x1, y1, onScreen1 = WorldToScreen(triangleDrawdangerMob_x,triangleDrawdangerMob_y,triangleDrawdangerMob_z)
  100. local x2, y2, onScreen2 = WorldToScreen(triangleDrawMy_x,triangleDrawMy_y,triangleDrawMy_z)
  101. local x3, y3, onScreen3 = WorldToScreen(triangleDrawSafespot1_x,triangleDrawintersection1_y,triangleDrawSafespot1_z)
  102.  
  103. -- if start and end of the line are onscrenn
  104.     if onScreen1 == true and onScreen2 == true then
  105.         DrawLine(x1, y1, x2, y2, 250, 0, 0, 5);
  106.         DrawLine(x2, y2, x3, y3, 250, 0, 0, 5);
  107.         DrawLine(x3, y3, x1, y1, 250, 0, 0, 5);
  108.     end
  109. end
  110.  
  111.  
  112. function script_runner:DrawMonsterAggroCircles()
  113.     for i,v in pairs(objectTable) do
  114.         -- DRAW CIRCLES AROUND MOBS (AGGRO RANGE)
  115.         if
  116. --      i:IsDead() == false and
  117.             v.type == 3
  118.         and i:CanAttack() == true
  119.             and i:IsCritter() == false
  120.             then
  121.                 script_runner:DrawCircles(v.x,v.y,v.z,v.r, 255, 255, 0, 1, 15)
  122.         end
  123.        
  124.        
  125.     end
  126. end
  127.  
  128. function script_runner:DrawCircles(pointX,pointY,pointZ,radius, redVar, greenVar, blueVar, lineThickness, quality)
  129.     local r = 255;
  130.     local g = 2;
  131.     local b = 233;
  132.     -- position
  133.     local x = 25;
  134.     -- info
  135.     if debugText == nil then debugText = "" end;
  136.    
  137.     -- we will go by radians, not degrees
  138.     local sqrt, sin, cos, PI, theta, points, point = math.sqrt, math.sin, math.cos,math.pi, 0, {}, 0;
  139.     while theta <= 2*PI do
  140.         point = point + 1 -- get next table slot, starts at 0
  141.         points[point] = { x = pointX + radius*cos(theta), y = pointY + radius*sin(theta) }
  142.         theta = theta + 2*PI / quality -- get next theta
  143.     end
  144.     for i = 1, point do
  145.         local firstPoint = i
  146.         local secondPoint = i + 1
  147.         if firstPoint == point then
  148.             secondPoint = 1
  149.         end
  150.         if points[firstPoint] and points[secondPoint] then
  151.             local x1, y1, onScreen1 = WorldToScreen(points[firstPoint].x, points[firstPoint].y, pointZ)
  152.            
  153.             local x2, y2, onScreen2 = WorldToScreen(points[secondPoint].x, points[secondPoint].y, pointZ)
  154.             -- make boolean string so i can post it to console
  155.             onScreen1String = tostring(onScreen1);
  156.            
  157.             --ToConsole('x1 inside draw cirlces: ' .. x1 .. 'onScreen1: ' .. onScreen1String .. y1 .. x2 .. y2 .. redVar .. greenVar .. blueVar .. lineThickness);
  158.             if onScreen1 == true and onScreen2 == true then
  159.                 DrawLine(x1, y1, x2, y2, redVar, greenVar, blueVar, lineThickness)
  160.                
  161.             end
  162.         end
  163.     end
  164. end
  165.  
  166.  
  167. function script_runner:FunkyStuffWithMobtable()
  168.     -- post player distance to mobs in console
  169.     local localObj = GetLocalPlayer();
  170.     local my_x, my_y, my_z = localObj:GetPosition();
  171.    
  172.     for i,v in pairs(objectTable) do
  173.         if
  174.             --i:IsDead() == false and  <- needs debuging
  175.             v.type == 3
  176.         and i:CanAttack() == true
  177.             and i:IsCritter() == false
  178.             then
  179.             -- put my distance to the sourrounding mobs into the console
  180.             MydistToMobs = GetDistance3D(my_x, my_y, my_z, v.x, v.y, v.z);
  181.             ToConsole('my distance to mobs is: ' .. MydistToMobs );
  182.         end
  183.     end
  184.     -- make the console less ugly
  185.     ToConsole('==================');
  186.    
  187. end
  188.  
  189.  
  190.  
  191.  
  192. function script_runner:triAngleCentroid(x1,y1,x2,y2,x3,y3)
  193. -- returns x and y of the centroid
  194. --https://brilliant.org/wiki/triangles-centroid/
  195.  
  196. triAngleCentroid_x = (x1+x2+x3)/3
  197. triAngleCentroid_y = (y1+y2+y3)/3
  198. return triAngleCentroid_x, triAngleCentroid_y
  199.  
  200. end
  201.  
  202. function script_runner:CheckNextNodeToMobsDistance()
  203.     -- checks if the next node (1+), next after(2+) etc of the navmeshpath is in aggro range of a mob, if so start  FindNewStartLogic
  204.     local NextNavIndex =  1 + self.lastnavIndex;
  205.     --ToConsole( 'Zerger-> nextnavindex :' .. NextNavIndex)
  206.     -- NNI is next nav index
  207.     local NNI_x, NNI_y, NNI_z = GetPathPositionAtIndex(5, NextNavIndex);
  208.    
  209.     for i,v in pairs(objectTable) do
  210.         if
  211.             --i:IsDead() == false and  <- needs debuging
  212.             v.type == 3
  213.         and i:CanAttack() == true
  214.             and i:IsCritter() == false
  215.             then
  216.             -- put next nav index distance to the sourrounding mobs into the console
  217.             NextNavIndexToMobsDistance = GetDistance3D(NNI_x, NNI_y, NNI_z, v.x, v.y, v.z);
  218.             tcOT1('Next Node [' .. NextNavIndex .. '] distance to ' .. v.name .. ' is: ' .. NextNavIndexToMobsDistance );
  219.             dangerMob_x = v.x;
  220.             dangerMob_y = v.y;
  221.             dangerMob_z = v.z;
  222.             dangerMob_r = v.r;
  223.             --
  224.             if
  225.                 NextNavIndexToMobsDistance < v.r + 1 --!!!!! important var
  226.             then
  227.              ToConsole(':::::: Danger!  index ' .. NextNavIndex .. ' is too close to a mob ::::::')
  228.              script_runner:FindNewStartLogic();
  229.             end
  230.            
  231.         end
  232.     end
  233.     -- make the console less ugly
  234.     ToConsole('==================');   
  235. end
  236.  
  237. function script_runner:FindNewStartLogic()
  238. --[[ we noticed our next nav spot is too close to a mob so we need to find a new safer spot
  239.  -stop
  240.  -calc distance to the dangerous mob -> use as 1 leg of the trapezoid  
  241.  -calc xy of safespot with calcIntersections which will return 2 xy, one left and one right of the mob
  242.  -go to safespots (wp1, wp2)
  243.  -contiune normal script
  244.  todo:
  245.  check dist to mobs, los, ray cast, gen nav path test
  246. --]]
  247.  
  248.  
  249.     local localObj = GetLocalPlayer();
  250.     local my_x, my_y, my_z = localObj:GetPosition();
  251.     local safedistanceVar = 5 -- IMPORTANT!! the distance from the aggo cirlce which is considered safe
  252.     local mob_radius = dangerMob_r + safedistanceVar  -- mobradius is NOT mob aggro range, (1 yard outside aggrorange should be safe)
  253.     self.movingToSafespot = false                         -- it is the distane mob <---> safespot
  254.    
  255.    
  256.     if (IsMoving()) then
  257.         StopMoving(); -- stop pathing along normal navpath
  258.     end
  259.            
  260.     local triangleSideA = math.floor(math.sqrt((my_x-dangerMob_x)*(my_x-dangerMob_x)+(my_y-dangerMob_y)*(my_y-dangerMob_y)));
  261.     local hypothenuse = math.floor(math.sqrt((triangleSideA)^2+mob_radius^2));
  262.    
  263.     -- this will find me two spots in an right angle from the mob (left and right side)
  264.     --- to do rewrite claclbla so it returns into var like raycast-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ works, make use . self bla
  265.     script_runner:calcIntersections(my_x,my_y,hypothenuse, dangerMob_x, dangerMob_y,mob_radius );
  266.    
  267.     -- point1 and point2 XY (they are the 'x' in the drawing which are right and left of the mob)
  268.     -- todo is intersection1 always right side?
  269.     local rightPoint_x = intersection1_x
  270.     local rightPoint_y = intersection1_y
  271.     local leftPoint_x = intersection2_x
  272.     local leftPoint_y = intersection2_y
  273.    
  274.    
  275.     -- now we use each of these spots
  276.    
  277.     --safedistance from mob is aggrorange + safedistanceVar
  278.     --[[
  279.         R = aggrorange (the real one ;) )
  280.        
  281.                  \Waypoint 3
  282.                   \
  283.                    \
  284.                     \
  285.                      \
  286.                       \
  287.                        \  Waypoint 2
  288.                         |               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
  289.                         |               !!!!!!!! MOB <-> X is (aggrorange + safedistanceVar) not R * something!!!!!!!!!!!!!!!!
  290.                         |  
  291.                         |              (Waypoint 1 to Waypoint 2  is 1.5*R)
  292.         MOB ------------X               "X" is our former triangle safespot and halfway between Waypoint 1 and 2
  293.                         |               so Waypoint 1 <---> "X" is 1.5*R/2 or 0.75*R and we can calc MOB <---> WP
  294.                         |               MOB <---> WP1 = sqrRoot((R+safedistanceVar)^2+(0.75*R)^2) = MOB <---> WP2
  295.                         |               Put these values in our 'calcIntersections' and we get XY of WP1 and WP2
  296.                         |
  297.                        / Waypoint 1
  298.                       /
  299.                      /
  300.                     /
  301.                    /
  302.                   /
  303.                  /
  304.                 /
  305.         Player /
  306.    
  307.    
  308.        
  309.         X _______ Waypoint           X <---> Waypoint is 0.75*R
  310.          |      /                    X <---> MOB is R+safedistanceVar
  311.          |     /                     hypothenuse^2  = (R+safedistanceVar)^2 + (0.75*R)^2
  312.    sideA |    / hypothenuse
  313.          |   /
  314.          |  /
  315.          | /
  316.          |/
  317.          MOB
  318.    
  319.    
  320.    
  321.     --]]
  322.    
  323.     local hypothenuse = math.floor(math.sqrt((dangerMob_r + safedistanceVar)*(dangerMob_r + safedistanceVar)+(0.75*dangerMob_r)*(0.75*dangerMob_r)))
  324.    
  325.     -- this will find me two spots in an right angle from right side X (WP 1,2)
  326.     script_runner:calcIntersections(dangerMob_x,dangerMob_y,hypothenuse, rightPoint_x, rightPoint_y, 0.75*dangerMob_r );
  327.     -- todo what if its a cave?
  328.     local isVis, _hx, _hy, _hz = Raycast(rightPathWP1_x, rightPathWP1_y, -10000, rightPathWP1_x, rightPathWP1_y, 10000)
  329.     rightPathWP1_x = intersection1_x
  330.     rightPathWP1_y = intersection1_y
  331.     rightPathWP1_z = _hz
  332.     local isVis, _hx, _hy, _hz = Raycast(rightPathWP2_x, rightPathWP2_y, -10000, rightPathWP2_x, rightPathWP2_y, 10000)
  333.     rightPathWP2_x = intersection2_x
  334.     rightPathWP2_y = intersection2_y
  335.     rightPathWP2_z = _hz
  336.     -- this will find me two spots in an right angle from left side X (WP 1,2)
  337.     script_runner:calcIntersections(dangerMob_x,dangerMob_y,hypothenuse, leftPoint_x, leftPoint_y, 0.75*dangerMob_r );
  338.    
  339.     -- todo is intersection1 always wp1 ? NO! its the opposite for the left side !
  340.     local isVis, _hx, _hy, _hz = Raycast(leftPathWP1_x, leftPathWP1_y, -10000, leftPathWP1_x, leftPathWP1_y, 10000)
  341.     leftPathWP1_x = intersection2_x
  342.     leftPathWP1_y = intersection2_y
  343.     leftPathWP1_z = _hz
  344.     local isVis, _hx, _hy, _hz = Raycast(leftPathWP2_x, leftPathWP2_y, -10000, leftPathWP2_x, leftPathWP2_y, 10000)
  345.     leftPathWP2_x = intersection1_x
  346.     leftPathWP2_y = intersection1_y
  347.     leftPathWP2_z = _hz
  348.     -- decide if we go around the mob left or right ---------------------
  349.     -- can each wp1 wp2 be reached? are there mobs blocking a side? which wp2 is closer to final destination? whats the path lenth for each side
  350.    
  351.     -- calc direct distance for each wp 2 to final destination for now in 2d
  352.     rightPathWP2toFinalDestination = GetDistance3D(self.tx,self.ty,self.tz,rightPathWP2_x,rightPathWP2_y,rightPathWP2_z)
  353.     leftPathWP2toFinalDestination = GetDistance3D(self.tx,self.ty,self.tz,leftPathWP2_x,leftPathWP2_y,leftPathWP2_z)
  354.     tc1(rightPathWP2toFinalDestination .. ' / ' .. leftPathWP2toFinalDestination  .. ' right/left path wp2 distance to final destination')
  355.    
  356.    
  357.    
  358.      if rightPathWP2toFinalDestination > leftPathWP2toFinalDestination then
  359.          goLeft = true
  360.          tc2('left WP2 is closer')
  361.      elseif rightPathWP2toFinalDestination < leftPathWP2toFinalDestination then
  362.          goLeft = false
  363.           tc2('right WP2 is closer')
  364.      end
  365.    
  366.     local isVis, _hx, _hy, _hz = Raycast(leftPathWP2_x, leftPathWP2_y, -10000, leftPathWP2_x, leftPathWP2_y, 10000)
  367.     -- test if wp2 left side or wp2 right side is closer to the !general destination!
  368.     --GeneratePath(leftPathWP2_x, leftPathWP2_y, leftPathWP2_z, self.tx, self.ty, self.tz);
  369.     tc1('_hz ' .. _hz .. ' self.tz ' .. self.tz)
  370.    
  371.    
  372.    
  373.    
  374.    
  375.    
  376.    
  377.     --todo fix!!!!!!!!!!!!!!!!!!!!!!!!!!! the green mess
  378.     --local searching = IsSearchingForPath()
  379.     --local rightPathSize = GetPathSize(5);
  380.     if IsPathLoaded(5) then
  381.      tc1('isloaded')
  382.      local PathSize = GetPathSize(5);
  383.      tct('PathSize: ' .. PathSize)
  384.      end
  385.    
  386.    
  387.      if (not IsPathLoaded(5)) then
  388.       tc1('is NOT loaded')
  389.      end
  390.      
  391.     --tc1('are we searching? '.. tostring(searching) .. rightPathSize .. ' isleaoded: ' .. isloaded)
  392.    
  393.     --[[ wait till we finished genpath todo: get it working
  394.     if searching == true then
  395.     local searching = IsSearchingForPath();
  396.     return
  397.     end
  398.    
  399.     local rightPathSize = GetPathSize(5);
  400.     --GeneratePath(rightPathWP2_x, rightPathWP2_y, my_z, d_x, d_y, d_z);
  401.     local rightPathSize = GetPathSize(5);
  402.     tc1('rightPathSize ' .. righttPathSize)
  403.     ]]--
  404.    
  405.     -- move to safespot and stop script for now, need to get a good z also 
  406.     local isVis, _hx, _hy, _hz = Raycast(intersection1_x, intersection1_y, -10000, intersection1_x, intersection1_y, 10000)
  407.    
  408.    
  409.     ToConsole(tostring(isVis) .. _hz .. ' my_z: ' .. my_z .. ' intersection1_x: ' .. intersection1_x);
  410.    
  411.     -- decide whic hside we go
  412.    
  413.    
  414.     if goLeft == true then
  415.     tct('+++++++++++++++**********************+++++++++++we go left' .. leftPathWP1_x .. leftPathWP1_y .. leftPathWP1_z)
  416.     Move(leftPathWP1_x, leftPathWP1_y, leftPathWP1_z);
  417.     elseif goLeft == false then
  418.     tct('+++++++++++++++**********************+++++++++++we go right' .. rightPathWP1_x .. rightPathWP1_y .. rightPathWP1_z)
  419.     Move(rightPathWP1_x, rightPathWP1_y, rightPathWP1_z);
  420.     end
  421.     self.movingToSafespot = true
  422.    
  423.    
  424. end
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432. function script_runner:calcIntersections(x1,y1,r1,x2,y2,r2)
  433.     --http://walter.bislins.ch/blog/index.asp?page=Schnittpunkte+zweier+Kreise+berechnen
  434.     --https://translate.google.com/translate?sl=de&tl=en&u=http%3A%2F%2Fwalter.bislins.ch%2Fblog%2Findex.asp%3Fpage%3DSchnittpunkte%2Bzweier%2BKreise%2Bberechnen%2B(JavaScript)
  435.     -- WAS used for triangle safespot, still used to calc a 3rd point in a triangle
  436.     -- calculate the intersections of 2 circles -> "my circle" and "mob circle" which helps us find a safespot to nav from
  437.     -- acutally we are using a right angle triangle where we have A) at mob and rightangle B) our xy and C) is the safespot
  438.     -- so my circle has the hypothenuse as radius and mobradius is is the safedistance
  439.     -- data i take from other function: my_x,my_y,hypothenuse, dangerMob_x, dangerMob_y,mob_radius
  440.     -- (var names are not great, relict from former version of the function)
  441.     local my_x = x1
  442.     local my_y = y1
  443.     local a = r1
  444.     local mob_x = x2
  445.     local mob_y = y2
  446.     local b = r2
  447.     triangleSideA = (math.sqrt((my_x-mob_x)*(my_x-mob_x)+(my_y-mob_y)*(my_y-mob_y)));
  448.     AB0 = (mob_x - my_x); --vector  (mobx - my x)
  449.     AB1 = mob_y - my_y ;  
  450.     c = math.sqrt( AB0 * AB0 + AB1 * AB1 ); --distance between both cirlce centers so my sideA
  451.     x = (a*a + c*c - b*b) / (2*c);-- )
  452.     y = math.sqrt(a*a - x*x);--  sideC  mob <---> safespot
  453.     ex0 = AB0 / c;
  454.     ex1 = AB1 / c;
  455.     ey0 = -ex1;
  456.     ey1 = ex0;
  457.     Q1x = my_x + x * ex0;
  458.     Q1y = my_y + x * ex1;
  459.     -- two intersections
  460.     intersection1_x = Q1x - y * ey0;
  461.     intersection1_y = Q1y - y * ey1;
  462.     intersection2_x = Q1x + y * ey0;
  463.     intersection2_y = Q1y + y * ey1;
  464.     return intersection1_x, intersection1_y, intersection2_x, intersection2_y;
  465.    
  466. end
  467.  
  468. function script_runner:MobTable()
  469. -- put enemies in a table  
  470.     local me = GetLocalPlayer();
  471.     objectTable = {};
  472.     local obj_, type_ = GetFirstObject();
  473.     while obj_ ~= 0 do
  474.         if type_ == 3 or type_ == 4 then
  475.             local objX, objY, objZ = obj_:GetPosition();
  476.             -- objR is mob aggro ranged, i tested it  and it is at least 6 and maximum 46, on same lvl its 21
  477.             local objR = obj_:GetLevel() - me:GetLevel() + 21
  478.             if objR > 46 then objR = 46 end;
  479.             if objR < 6 then objR = 6 end;
  480.             local objGUID = obj_:GetGUID();
  481.             local objName = obj_:GetUnitName();
  482.             objectTable[obj_] = {x = objX, y = objY, z = objZ, type = type_, r = objR, GUID = objGUID, name = objName};
  483.         end
  484.         obj_, type_ = GetNextObject(obj_);
  485.     end
  486. end
  487.  
  488.  
  489.  
  490. function script_runner:draw()
  491.  
  492.     -- setview(3) so the camera is always behindthe bot !!!!
  493.     SetView(3);
  494.  
  495.     -- put monster in a table for draw and avoid if called, in run its too late for draw
  496.     script_runner:MobTable();
  497.    
  498.     --[[ draw avoidance triangle
  499.     if self.movingToSafespot == true then
  500.         script_runner:drawAvoidMobTriangle();
  501.     end
  502.     ]]--
  503.    
  504.     -- Draw path
  505.     if (IsPathLoaded(5)) then
  506.         if (self.lastnavIndex-1 <= GetPathSize(5)-1) then
  507.             for index = self.lastnavIndex-1, GetPathSize(5) - 2 do
  508.                 local _x, _y, _z = GetPathPositionAtIndex(5, index);
  509.                 local _xx, _yy, _zz = GetPathPositionAtIndex(5, index+1);
  510.                 local _tX, _tY, onScreen = WorldToScreen(_x, _y, _z);
  511.                 local _tXX, _tYY, onScreens = WorldToScreen(_xx, _yy, _zz);
  512.                 if(onScreen and onScreens) then
  513.                     DrawLine(_tX, _tY, _tXX, _tYY, 255, 255, 0, 4);
  514.                 end
  515.             end
  516.         end
  517.        
  518.     end
  519.    
  520.     -- from radar, draw gets executed before run and i put fill monstertables in "run"
  521.     script_runner:DrawMonsterAggroCircles();
  522.      
  523.  
  524.    
  525.     -- Draw destination
  526.     _tX, _tY, onScreen = WorldToScreen(self.tx, self.ty, self.tz);
  527.     if (onScreen) then
  528.         DrawText("Destination:", _tX, _tY-10, 255, 255, 0);
  529.         DrawText(tostring(self.destination[self.nRcombo+1].name), _tX, _tY, 255, 255, 0);
  530.     end
  531.    
  532. end
  533.  
  534. function script_runner:run()
  535.    
  536.    
  537.     --check various things
  538.     --script_runner:FunkyStuffWithMobtable();
  539.    
  540.     -- Setup destinations
  541.     if (not self.isSetup) then
  542.         script_runner:setup();
  543.         return;
  544.     end
  545.  
  546.     -- Update player coordinates
  547.     local localObj = GetLocalPlayer();
  548.     local    my_x, my_y, my_z = localObj:GetPosition();
  549.     local d_x, d_y, d_z = self.tx, self.ty, self.tz;
  550.  
  551.     -- Update distance to destination
  552.     self.distDestination = GetDistance3D(my_x, my_y, my_z, self.tx, self.ty, self.tz);
  553.  
  554.     if (GetTimeEX() < self.timer) then
  555.         return;
  556.     end
  557.  
  558.     self.timer = GetTimeEX() + self.tic;
  559.  
  560.     -- If the target destination has changed, generate a new path
  561.     if(self.dx ~= self.tx or self.dy ~= self.ty or self.dz ~= self.tz) then
  562.  
  563.         -- update destination position
  564.         self.dx, self.dy, self.dz = d_x, d_y, d_z;
  565.  
  566.         -- reset node index
  567.         self.lastnavIndex = 1;
  568.        
  569.         -- generate a new path
  570.         GeneratePath(my_x, my_y, my_z, d_x, d_y, d_z);
  571.     end
  572.  
  573.     -- Return until path has been generated
  574.    
  575.    
  576.    
  577.     -- if there is no navmesh path loaded
  578.     if (not IsPathLoaded(5)) then
  579.        
  580.         --stop
  581.         if (IsMoving()) then
  582.             StopMoving();
  583.         end
  584.        
  585.         -- when we are not generating a path and generation timer is less than current time
  586.         if (not self.generating and self.genTimer < GetTimeEX()) then
  587.             rP("Generating path to " .. tostring(self.destination[self.nRcombo+1].name) .. '...');
  588.             self.generating = true;
  589.             self.genTimer = GetTimeEX() + 4500;
  590.         end
  591.        
  592.         if (GetTimeEX() > self.genTimer and self.generating) then
  593.             self.generating = false;
  594.             self.runit = false;
  595.             self.dx = 0;
  596.             ClearPath(5);
  597.             rP("Failed to generate path to " .. tostring(self.destination[self.nRcombo+1].name) .. '...');
  598.         end
  599.    
  600.         return;
  601.     else
  602.         self.generating = false;
  603.     end
  604.  
  605.     -- Get the next node's id
  606.     local _ix, _iy, _iz = GetPathPositionAtIndex(5, self.lastnavIndex);
  607.     --ToConsole('lastnavIndex: ' .. self.lastnavIndex);
  608.    
  609.  
  610.    
  611.     --distance to next node zerger
  612.     local nextNodeDist = (GetDistance3D(my_x, my_y, my_z, _ix, _iy, _iz));
  613.     --ToConsole('my distance to next node: ' .. nextNodeDist);
  614.    
  615.     if(GetDistance3D(my_x, my_y, my_z, _ix, _iy, _iz) < self.nextNodeDistance) then
  616.        
  617.         -- check if next node is  in aggro cirlce, to do
  618.         script_runner:CheckNextNodeToMobsDistance();--------------------------------------------------------------------------
  619.         if findingNewStart == true then
  620.             ToConsole('----------------------------------------------need to find new start')
  621.         end
  622.        
  623.        
  624.         -- If we are close to the next path node, increase our nav node index
  625.         self.lastnavIndex = 1 + self.lastnavIndex;
  626.         ToConsole('we just increased self.lastnavIndex:')
  627.  
  628.         -- if Destination reached  
  629.         if (GetPathSize(5) <= self.lastnavIndex) then
  630.             self.lastnavIndex = GetPathSize(5)-1;
  631.             self.runit = false;
  632.             rP("Destination " .. tostring(self.destination[self.nRcombo+1].name .. ' reached...'));
  633.         end
  634.     end
  635.    
  636.    
  637.     -- need to add a good logic to check if we go to safespot and restart navigation
  638.     --ToConsole('self.movingToSafespot: ' .. tostring(self.movingToSafespot));
  639.     if self.movingToSafespot == true then
  640.         --ToConsole('my_x :' .. math.floor(my_x) .. ' intersection1_x: ' .. math.floor(intersection1_x));
  641.          
  642.         --------------------------------------------------------------- todo move wp 2 pathing into function?
  643.         --all just temp stuff !!
  644.         -- right path stuff
  645.         if goLeft == false then
  646.             -- if we are at a wp    1
  647.             if math.floor(my_x) == math.floor(rightPathWP1_x) or -- 0.5 + 0.5 area
  648.             math.floor(my_x) == math.floor(rightPathWP1_x) +1 or
  649.             math.floor(my_x) == math.floor(rightPathWP1_x) -1
  650.             then
  651.             Move(rightPathWP2_x, rightPathWP2_y, my_z);
  652.  
  653.             end
  654.            
  655.             -- if we are at a wp    2
  656.             if math.floor(my_x) == math.floor(rightPathWP2_x) or -- 0.5 + 0.5 area
  657.             math.floor(my_x) == math.floor(rightPathWP2_x) +1 or
  658.             math.floor(my_x) == math.floor(rightPathWP2_x) -1
  659.             then
  660.            
  661.             --we arrived at savespot, gen path to target again
  662.                 ToConsole('we are at savespot');
  663.                 self.lastnavIndex = 1;
  664.                 GeneratePath(my_x, my_y, my_z, d_x, d_y, d_z);
  665.                
  666.                 self.movingToSafespot = false;
  667.                
  668.                
  669.             else
  670.                 return
  671.             end
  672.         end
  673.        
  674.         --- go left pat hstuff
  675.         if goLeft == true then 
  676.             -- if we are at a wp    1
  677.             if math.floor(my_x) == math.floor(leftPathWP1_x) or --0.5 + 0.5 area
  678.             math.floor(my_x) == math.floor(leftPathWP1_x) +1 or
  679.             math.floor(my_x) == math.floor(leftPathWP1_x) -1
  680.             then
  681.             Move(leftPathWP2_x, leftPathWP2_y, my_z);
  682.  
  683.             end
  684.            
  685.             -- if we are at a wp    2
  686.             if math.floor(my_x) == math.floor(leftPathWP2_x) or -- 0.5 + 0.5 area
  687.             math.floor(my_x) == math.floor(leftPathWP2_x) +1 or
  688.             math.floor(my_x) == math.floor(leftPathWP2_x) -1
  689.             then
  690.            
  691.             --we arrived at savespot, gen path to target again
  692.                 ToConsole('we are at savespot');
  693.                 self.lastnavIndex = 1;
  694.                 GeneratePath(my_x, my_y, my_z, d_x, d_y, d_z);
  695.                
  696.                 self.movingToSafespot = false;
  697.                
  698.                
  699.             else
  700.                 return
  701.             end
  702.         end
  703.  
  704.  
  705.  
  706.        
  707.        
  708.            
  709.     end
  710.    
  711.     -- Move to the next node in the path
  712.  
  713.     Move(_ix, _iy, _iz);
  714.     ToConsole('end of run')
  715. end
  716.  
  717. function script_runner:menu()
  718.     if (CollapsingHeader("[Rot's Runner - edited by Logitech")) then
  719.  
  720.         -- Setup destinations
  721.         if (not self.isSetup) then
  722.             script_runner:setup();
  723.             return;
  724.         end
  725.  
  726.         Separator()
  727.         Text("Choose Destination")
  728.         self.destinationChanged , self.nRcombo = ComboBox("", self.nRcombo, unpack(self.destinationName));
  729.        
  730.         -- Update destination position
  731.         if self.destinationChanged or self.tx == 0 then
  732.             self.tx = self.destination[self.nRcombo+1].x
  733.             self.ty = self.destination[self.nRcombo+1].y
  734.             self.tz = self.destination[self.nRcombo+1].z
  735.             local x, y, z = GetLocalPlayer():GetPosition();
  736.             self.distDestination = GetDistance3D(x, y, z, self.tx, self.ty, self.tz);
  737.             self.status = "New destination selected...";
  738.             rP("New destination selected " .. tostring(self.destination[self.nRcombo+1].name) .. '...');
  739.         end
  740.  
  741.         Separator()
  742.         Text("Distance to destination: " .. string.format("%.0f", self.distDestination) .. ' yards.')
  743.        
  744.         self.useNaveMesh = IsUsingNavmesh();
  745.        
  746.         if self.useNaveMesh then
  747.        
  748.             if not self.runit then
  749.                 if Button("Run to destination") then
  750.                     self.runit = true;
  751.                     StartBot();
  752.                 end
  753.             else
  754.                 if Button("Stop running") then
  755.                     self.runit = false;
  756.                     StopBot();
  757.                 end
  758.             end
  759.         else
  760.             Text("Please enable and load the nav mesh...");
  761.         end
  762.        
  763.         Separator()
  764.        
  765.         if Button("save player location to textfile") then
  766.         local localObj = GetLocalPlayer();
  767.         local my_x, my_y, my_z = localObj:GetPosition();
  768.         local myGetContinentID = GetContinentID();
  769.         local myMapID = GetMapID();
  770.         DEFAULT_CHAT_FRAME:AddMessage("Your XYZ coordinates have been saved!");
  771.         DEFAULT_CHAT_FRAME:AddMessage("Check your gasaibot/Logs  folder and copy your destination to scripts/script_runner.lua");
  772.             ToFile('script_runner:addDestination("enter destination name here", ' .. my_x ..', '.. my_y .. ', ' .. my_z  .. ', ' .. myGetContinentID ..', ' .. myMapID ..');')
  773.        
  774.                    
  775.         end
  776.        
  777.        
  778.         -- Running with StartBot() now instead
  779.         --if (self.runit) then
  780.             -- Run to destination
  781.         --  script_runner:run();
  782.         --end
  783.     end
  784. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement