Skymagnum

Untitled

Jun 13th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. local function getNextDir(cid, playerpos, finalpos)
  2. local result = {}
  3. local xy = 999999
  4. for newDir = 0, 3 do
  5. local p = getPosByDir(playerpos, newDir)
  6. if doTileQueryAdd(cid, p, config.EMPURRAR_CRIATURAS and 4 or 0) == 1 or config.ATRAVESSAR_OBSTACULOS then
  7. local d = math.abs(p.x - finalpos.x) + math.abs(p.y - finalpos.y)
  8. if d < xy then result = {newDir} xy = d
  9. elseif d == xy then table.insert(result, newDir) end
  10. end
  11. end
  12. if #result == 0 then
  13. for newDir = 4, 7 do
  14. local p = getPosByDir(playerpos, newDir)
  15. if doTileQueryAdd(cid, p, config.EMPURRAR_CRIATURAS and 4 or 0) == 1 or config.ATRAVESSAR_OBSTACULOS then
  16. local d = math.abs(p.x - finalpos.x) + math.abs(p.y - finalpos.y)
  17. if d < xy then result = {newDir} xy = d
  18. elseif d == xy then table.insert(result, newDir) end
  19. end
  20. end
  21. return #result == 0 and false or result[math.random(#result)]
  22. else
  23. return result[math.random(#result)]
  24. end
  25. return false
  26. end
Advertisement
Add Comment
Please, Sign In to add comment