Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getAdjacentTiles()
- local pos = Self.Position()
- local tiles = {
- {x=pos.x,y=pos.y-1},
- {x=pos.x+1,y=pos.y},
- {x=pos.x,y=pos.y+1},
- {x=pos.x-1,y=pos.y},
- {x=pos.x-1,y=pos.y+1},
- {x=pos.x+1,y=pos.y+1},
- {x=pos.x-1,y=pos.y-1},
- {x=pos.x+1,y=pos.y-1}
- }
- return tiles
- end
- function comparePositions(pos1, pos2)
- return pos1.x == pos2.x and pos1.y == pos2.y
- end
- function getDirectionTo(pos1, pos2)
- local dir = SOUTH
- if(pos1.x > pos2.x) then
- dir = WEST
- if(pos1.y > pos2.y) then
- dir = NORTHWEST
- elseif(pos1.y < pos2.y) then
- dir = SOUTHWEST
- end
- elseif(pos1.x < pos2.x) then
- dir = EAST
- if(pos1.y > pos2.y) then
- dir = NORTHEAST
- elseif(pos1.y < pos2.y) then
- dir = SOUTHEAST
- end
- elseif(pos1.y > pos2.y) then
- dir = NORTH
- elseif(pos1.y < pos2.y) then
- dir = SOUTH
- end
- return dir
- end
- function getTileScore(tilePos, toPos, history)
- local g = (getDirectionTo(Self.Position(), tilePos) > 3) and 15 or 10
- local f = getDistanceBetween(tilePos, toPos)
- local o = 0
- local key = table.serialize(tilePos)
- if(history[key])then
- o = history[key] * 150
- end
- return g + f + o
- end
- function getLowestNode(dest, history)
- local tiles = getAdjacentTiles()
- local target = 500
- local chosen = nil
- for i = 1, #tiles do
- local pos = tiles[i]
- local walkable = Map.IsTileWalkable(pos.x, pos.y, Self.Position().z)
- print(tostring(walkable))
- if(walkable)then
- local score = getTileScore(pos, dest, history)
- if(score < target)then
- target = score
- chosen = pos
- end
- end
- end
- return chosen
- end
- function walk(dest, nodes)
- local history = {}
- wait(1500)
- local nodes = nodes or 1000
- while(true)do
- nodes = nodes - 1
- if(nodes < 0)then
- break
- end
- local pos = Self.Position()
- if(getDistanceBetween(pos, dest) <= 1)then
- break
- end
- local nextPos = getLowestNode(dest, history)
- if(not nextPos)then
- break
- end
- local key = table.serialize(nextPos)
- if(history[key])then
- history[key] = history[key] + 1
- else
- history[key] = 1
- end
- Self.Step(getDirectionTo(pos, nextPos))
- waitLimit = 600
- repeat
- wait(200)
- waitLimit = waitLimit - 1
- until (comparePositions(Self.Position(), nextPos)) or waitLimit < 0
- end
- end
- walk({x=32108,y=32208,z=7})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement