Advertisement
Guest User

Untitled

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