Advertisement
lavalevel

Path Crazy

Sep 6th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1.     if currentMap.monsterList[gpMode.Mon].npcAction == "find" then
  2.     print ("FINDING!!!!!!!!!!!")
  3.  
  4.     local startx = gpMode.Mx
  5.     local starty = gpMode.My
  6.     local endx = gpMode.playerX
  7.     local endy = gpMode.playerY
  8.  
  9.    
  10.       local myFinder = Pathfinder(grid, 'JPS', walkable)
  11.  
  12.  
  13.         path = myFinder:getPath(startx, starty, endx, endy)
  14.         if path == nil then
  15.                 print("PATH IS NIL! CLEARING VARS!")
  16.                 resetVars() -- resetting the movement holders in the event of a non-viable path
  17.         else
  18.                 if path then
  19.                 successfulMove = true
  20.                 print(('Path found! Length: %.2f'):format(path:getLength()))
  21.                         for node, count in path:nodes() do
  22.                         print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY()))
  23.                         print(node:getX())
  24.                         print(node:getY())
  25.                         setX[#setX+1] = node:getX() -- populating coordinate table on each movement
  26.                         setY[#setY+1] = node:getY() -- populating coordinate table on each movement
  27.                         cellb[node:getY()][node:getX()].alpha = .8 -- see the path you've chosen!
  28.                         moveCount = moveCount+1
  29.                         end
  30.                 end
  31.         end
  32.  
  33.  
  34.  
  35.  
  36.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement