A speedwalking function

Share your scripts and packages with other Mudlet users.
Post Reply
Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

A speedwalking function

Post by Iocun »

Inspired by another thread I have written a more generalised speedwalking function, that will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.

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
- Call the function by doing: speedwalk("YourDirectionsString", true/false, delaytime)

- 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)

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: A speedwalking function

Post by Vadi »

Ill link to this in the manual. Very well done

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: A speedwalking function

Post by Vadi »


syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: A speedwalking function

Post by syrik »

ok, so do I copy/paste that into a script? or do I have to use aliases/triggers?
Edit: another cool way you could use this is to make buttons for all of the destinations!

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: A speedwalking function

Post by demonnic »

The function is now included with mudlet, so you can just start using it.

syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: A speedwalking function

Post by syrik »

what is the syntax? Speedwalk ("") does seem to work.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: A speedwalking function

Post by demonnic »

same as further up in this topic.. speedwalk(stringofdirections, backwards, delay)


so speedwalk("3n5e8s", false, 0.5) would walk you 3 north, 5 east, and 8 south with a half second delay between the steps.

if, instead of false, you specified true, it would walk you 8 north, 5 west, and 3 south.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: A speedwalking function

Post by Vadi »

This function is included in Mudlet now, and so I've copied Iocuns description for it onto the wiki: http://wiki.mudlet.org/w/Manual:Mapper_ ... #speedwalk

Post Reply