Code: Select all
walklist = {}
walkdelay = 0
function speedwalktimer()
send(walklist[1])
table.remove(walklist, 1)
if #walklist>0 then
tempTimer(walkdelay, [[speedwalktimer()]])
end
end
function speedwalk(dirString, backwards, delay)
local dirString = dirString:lower()
walklist = {}
walkdelay = delay
local reversedir = {
n = "s",
en = "sw",
e = "w",
es = "nw",
s = "n",
ws = "ne",
w = "e",
wn = "se",
u = "d",
d = "u",
ni = "out",
tuo = "in"
}
if not backwards then
for count, direction in string.gmatch(dirString, "([0-9]*)([neswudio][ewnu]?t?)") do
count = (count == "" and 1 or count)
for i=1, count do
if delay then walklist[#walklist+1] = direction
else send(direction)
end
end
end
else
for direction, count in string.gmatch(dirString:reverse(), "(t?[ewnu]?[neswudio])([0-9]*)") do
count = (count == "" and 1 or count)
for i=1, count do
if delay then walklist[#walklist+1] = reversedir[direction]
else send(reversedir[direction])
end
end
end
end
if walkdelay then speedwalktimer() end
end
- The true/false flag will reverse the path, if set to true. It is optional and defaults to false.
- The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- explicitly indicate true or false for the reverse flag.)
- The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.
If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. (See the link at the beginning of my post for something like that.)
Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.
Examples of correct usage:
speedwalk("16d1se1u")
Will walk 16 times down, once southeast, once up. All in immediate succession.
speedwalk("2ne,3e,2n,e")
Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.
speedwalk("IN N 3W 2U W", false, 0.5)
Will walk in, north, thrice west, twice up, west, with half a second delay between every move.
speedwalk("5sw - 3s - 2n - w", true)
Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.
speedwalk("3w, 2ne, w, u", true, 1.25)
Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.
P.S. The probably most logical usage of this would be to put it in an alias. For example, have the pattern "^/(.+)$" execute: speedwalk(matches[2], false, 0.7)
And have "^//(.+)$" execute: speedwalk(matches[2], true, 0.7)
Or make aliases like: ^banktohome$ to execute speedwalk("2ne,e,ne,e,3u,in", true, 0.5)