Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getNextDir(cid, playerpos, finalpos)
- local result = {}
- local xy = 999999
- for newDir = 0, 3 do
- local p = getPosByDir(playerpos, newDir)
- if doTileQueryAdd(cid, p, config.EMPURRAR_CRIATURAS and 4 or 0) == 1 or config.ATRAVESSAR_OBSTACULOS then
- local d = math.abs(p.x - finalpos.x) + math.abs(p.y - finalpos.y)
- if d < xy then result = {newDir} xy = d
- elseif d == xy then table.insert(result, newDir) end
- end
- end
- if #result == 0 then
- for newDir = 4, 7 do
- local p = getPosByDir(playerpos, newDir)
- if doTileQueryAdd(cid, p, config.EMPURRAR_CRIATURAS and 4 or 0) == 1 or config.ATRAVESSAR_OBSTACULOS then
- local d = math.abs(p.x - finalpos.x) + math.abs(p.y - finalpos.y)
- if d < xy then result = {newDir} xy = d
- elseif d == xy then table.insert(result, newDir) end
- end
- end
- return #result == 0 and false or result[math.random(#result)]
- else
- return result[math.random(#result)]
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment