Ok, here's the original script posted on EUO.com:
http://www.easyuo.com/forum/viewtopic.php?p=189786Saves me posting the full description again.
The whole thing is recursive too, so if the pathfind fails, but is yet within it's timelimit, it will call itself to get around large obstacles like mountains and player houses.
For lulz try pathfinding straight through a large town like Britain. For
Epic Lulz try to pathfind across an ocean (to an island from mainland) and set a really long timeout, It'll keep tying, persistent bastard that it is

But the interesting bit for this task is the ScaledLine sub. Which I originally wrote a full fixed point square root function for, until I realized that all 8 directions are the same distance according to the UO client...
Take this grid: (works better in monospace font)
123
456
789
in the real world, moving from 1 to 9 is a longer distance than moving from 7 to 9. Diagonal, hypotenuse and all that. In UO it's the same distance. A right triangle where side A and B are of equal length would have an equal length hypotenuse too (wrap your head around that for a bit

). So that simplified the math required almost infinitely.
So here's a sub you can use alongside the pathfinding sub(s) to do what you want, right out of the box.
Note that you could use event pathfind instead of calling my sub here, or even move, if the distance is always reasonably short.
Interesting things are the ScaledLine sub, which takes two sets of coordinates, X1, Y1 and X2,Y2, and a distance, it returns a XXX_YYY formatted set of coordinates *distance* tiles away from X1,Y1 along the straight line to X2,Y2.
Sub XYReadout simply changes those to separate variables, saves a few lines of code.
;#############################
;# KeepDistance Sub
;# %1 is the target to keep at distance
;# %2 is the distance to keep
;#############################
SUB KeepDistance
SET !target %1
SET !distance %2
FINDITEM !target
IF #FINDKIND = -1
RETURN
IF #FINDDIST <> !distance
{
GOSUB ScaledLine #FINDX #FINDY #CHARPOSX #CHARPOSY !distance
GOSUB XYReadout #RESULT targx targy
GOSUB Distance #CHARPOSX #CHARPOSY !targx !targy
GOSUB BMPathfind !targx !targy 0
}
RETURN