The reason I made this was so I could use it together with a navigation connection to hunt on my ED + EK by only actually playing the EK just for fun.
Because the built in reachcreature() function uses map-clicks to walk, it is a lot harder to make it cast runes with crosshairs, equip rings etc, which is something that doesn't happen if you walk with arrow keys. So well, that's about it, have fun using it or something : )
function reachcreature_keys(cr, reachDir)
c = getcreature(cr)
if (c.dist > reachDir) then
auto(50,150)
keyevent(getMoveDir(c))
else
auto(200,400)
end
end
function getMoveDir(c)
walkRight = false
walkLeft = false
walkUp = false
walkDown = false
VK_LEFT = "Left"
VK_RIGHT = "Right"
VK_UP = "Up"
VK_DOWN = "Down"
if (c.posx > $posx and tilewalkable($posx+1, $posy, $posz)) then
walkRight = true
end
if (c.posx < $posx and tilewalkable($posx-1, $posy, $posz)) then
walkLeft = true
end
if (c.posy > $posy and tilewalkable($posx, $posy+1, $posz)) then
walkDown = true
end
if (c.posy < $posy and tilewalkable($posx, $posy-1, $posz)) then
walkUp = true
end
dir = math.random(1, 100)
if (walkUp and walkLeft) then
--print('walk up and left')
if (dir > 50) then
--print('walk left')
return VK_LEFT
elseif (dir <= 50) then
--print('walk up')
return VK_UP
end
elseif (walkUp and walkRight) then
--print('walk up and right')
if (dir > 50) then
--print('walk right')
return VK_RIGHT
elseif (dir <= 50) then
--print('walk up')
return VK_UP
end
elseif (walkDown and walkLeft) then
--print('walk down and left')
if (dir > 50) then
--print('walk left')
return VK_LEFT
elseif (dir <= 50) then
--print('walk down')
return VK_DOWN
end
elseif (walkDown and walkRight) then
--print('walk down and right')
if (dir > 50) then
--print('walk right')
return VK_RIGHT
elseif (dir <= 50) then
--print('walk down')
return VK_DOWN
end
elseif (walkDown) then
--print ('walk only down')
return VK_DOWN
elseif (walkUp) then
--print ('walk only up')
return VK_UP
elseif (walkLeft) then
--print ('walk only left')
return VK_LEFT
elseif (walkRight) then
--print ('walk only right')
return VK_RIGHT
end
end
auto(200,400)
reachcreature_keys('Captain Fearless', 1)