Zmud <-> MC speedwalk converter.

Posted by Poromenos on Mon 18 Apr 2005 11:27 PM — 3 posts, 21,007 views.

Greece #0
This poorly commented piece of code will convert a MC speedwalk string to Zmud stacked dirs and vice-versa:

def fnConvertDirs(strDirs, strFormat = 0):
    """0: Zmud to MUSHclient
       1: MUSHclient to Zmud"""

    lstNewDirs = []
    if strFormat == 0:
        # Strip list items.
        lstDirs = map(string.strip, strDirs.split(";"))
        strRepeat = ""

        # Repeat commands as many times as required.
        for strCommand in lstDirs:
            if strCommand[0] == "#":
                for strLetter in strCommand[1:]:
                    if strLetter.isdigit():
                        strRepeat += strLetter
                    else:
                        for intCounter in range(int(strRepeat)):
                            lstNewDirs.append(strCommand[strCommand.find(strLetter):].strip())
                        strRepeat = ""
                        break
            else:
                lstNewDirs.append(strCommand)

        # Enclose long commands in parentheses.
        lstNewDirs = map(lambda x: len(x) > 1 and "(" + x + ")" or x, lstNewDirs)

        intOccurrenceCounter = 1
        lstDirs = []
        # Append an empty element so the following algorithm works.
        lstNewDirs.append("")

        # Join adjacent same dirs in one ("n n" -> "2n").
        for intCounter in range(1, len(lstNewDirs)):
            if lstNewDirs[intCounter - 1] == lstNewDirs[intCounter]:
                intOccurrenceCounter += 1
            else:
                if intOccurrenceCounter > 1:
                    lstDirs.append(str(intOccurrenceCounter) + lstNewDirs[intCounter - 1])
                else:
                    lstDirs.append(lstNewDirs[intCounter - 1])
                intOccurrenceCounter = 1
        return(string.join(lstDirs))

    else:
        strTemp = ""
        strTimes = ""
        blnInCommand = False
        blnEvaluate = True
        for strLetter in strDirs:
            if strLetter == "(":
                blnInCommand = True
            elif strLetter == "/" and blnInCommand:
                blnEvaluate = False
            elif strLetter == ")" and blnInCommand:
                blnInCommand = False
                if strTimes != "":
                    lstNewDirs.append("#" + strTimes + " " + strTemp + ";")
                else:
                    lstNewDirs.append(strTemp  + ";")
                blnEvaluate = True
                strTimes = ""
                strTemp = ""
            elif strLetter.isdigit() and not blnInCommand:
                strTimes += strLetter
            elif strLetter.isspace() and not blnInCommand:
                pass
            elif blnInCommand:
                if blnEvaluate:
                    strTemp += strLetter
            else:
                if strTimes != "":
                    lstNewDirs.append("#" + strTimes + " " + strLetter + ";")
                else:
                    lstNewDirs.append(strLetter + ";")
                strTimes = ""
                strTemp = ""
        return(string.join(lstNewDirs)[:-1])
Amended on Tue 19 Apr 2005 12:45 AM by Poromenos
#1
I'm more of a vbscript person, would anyone be willing to take the time to convert this to a plugin?, perhaps to send the speedwalk on an alias.
USA #2
I was making a Lua plugin for this a while ago. I gave up when I was getting odd errors with parsing the zMUD sws into MUSHclient sws. Works great going from a stored alias to a zMUD alias though. I do not normally use the speedwalk function for MUSHclient though, since the mud I play supports a faster "run" command, where you can just spit out "run 3n5w2s" and it will just show room names while zipping along faster than a normal walk delay.

I'll see if I can scrounge up the script and fix it up again.