Zmud Convert - Can MC do [x]?

Posted by Peglegz on Fri 17 Dec 2010 03:04 AM — 6 posts, 23,276 views.

#0
I'm slowly learning my way around Lua (Very. Slowly.) but there are some things not obvious to me when figuring out how to do some things I used to do in zmud.

I used to have lists of my directions, set via alias, from point A to point B - and each time I'd hit my macro to send the current direction, it'd 'pop' the first direction off the list - like so:

Directions = n,e,n,n,e,n,w,w,s,sw,in

*hit macro*

Directions = e,n,n,e,n,w,w,s,sw,in

So I could use an alias to change the value of my 'Directions' variable, and hitting the macro would execute the first direction and pop it from the list, so that the next hit of the macro does the second direction, until it runs out of directions. I preferred this method over scripting an auto walk path because it allowed me to deal with aggressive mobs or stop and talk to a friend without needing to pause anything. So, my (first) question is, how do I use lua to 'pop' that first direction off my variable?
Australia Forum Administrator #1
First, let's put your directions into a table variable:


Directions = "n,e,n,n,e,n,w,w,s,sw,in"

-- populate table
dir_table = {}

for dir in string.gmatch (Directions, "%w+") do
  table.insert (dir_table, dir)
end -- for


The string.gmatch pulls out "words" and puts them into the table.

Now, in your "move one direction" alias, you just pop the first entry:


-- if table not empty
if next (dir_table) then
  dir = table.remove (dir_table, 1)
  Send (dir)  -- send to MUD
else
  Note "No further directions"
end -- if
Amended on Fri 17 Dec 2010 03:25 AM by Nick Gammon
Australia Forum Administrator #2
There is actually an easier way of populating the table:


-- populate table
t = utils.split (Directions, ",")


http://www.gammon.com.au/scripts/doc.php?lua=utils.split

So your alias to remember the directions is basically a single line:


<aliases>
  <alias
   match="path *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
dir_table = utils.split ("%1", ",")
Note ("Generated ", #dir_table, " directions")
</send>
  </alias>
</aliases>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


(I added the Note to confirm it did something)
Amended on Fri 17 Dec 2010 03:32 AM by Nick Gammon
Australia Forum Administrator #3
Thus the popping alias could look like this:


<aliases>
  <alias
   match="move_once"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
-- if table not empty
if dir_table and next (dir_table) then
  dir = table.remove (dir_table, 1)
  Send (dir)  -- send to MUD
else
  Note "No further directions"
end -- if
</send>
  </alias>
</aliases>


Now just make a macro that sends "move_once" and that will call this alias.
Australia Forum Administrator #4
Example output:


> path n,e,n,n,e,n,w,w,s,sw,in
Generated 11 directions

> move_once
n
You dream about moving north.

> move_once
e
You dream about moving east.

> move_once
n
You dream about moving north.

> move_once
n
You dream about moving north.


(I was asleep at the time)
Australia Forum Administrator #5
You might also want to check out:

Template:function=EvaluateSpeedwalk
EvaluateSpeedwalk

The documentation for the EvaluateSpeedwalk script function is available online. It is also in the MUSHclient help file.



That lets you type a "speedwalk string" and have it converted. Then you could modify the alias to break up on newlines rather than commas. So for example your path might be:


path n e 2n e n 2w s (sw) (in)