Here is a script I wrote for CthulhuMUD (www.cthulhumud.org) but could easily be adapted for other MUDs. The idea is to process a list of items, categorise them using pre-defined strings (which you will need to maintain) then output them by category in alphabetical order. Here it is:
- For other muds besides CthulhuMUD you will need to change the trigger from 'It contains:' to whatever the starting string is for the start of your list.
- If you've changed the trigger string, then also put that in the top line of the third script 'called 'Contents Lister', the one that looks like this:
This is necessary to prevent the gate opening and closing too quickly if the 'It contains' appears on the same line as the prompt, which it can do on CthulhuMUD. On other MUDs this might not be an issue, if you can guarantee that the prompt has a newline character after it.
Code: Select all
if not string.match(line, 'It contains') then
- Your prompt match will probably need changing in the 'Contents Lister' trigger (the one that closes the gate). Also I wrote a another function isMyPrompt (defined at the end of ContentGate) which matches my prompt, since the in-built isPrompt does not work on CthulhuMUD. If your MUD supports isPrompt, then you can replace both the perl regex and the function with isPrompt.
- Other parts of the script should be portable, except perhaps the read quantity part in CaptureContents (line 35ff).
- There is a separate category OTHER (which is distinct from MISC), which is ideally empty. The idea is that you stand in front of your locker/chest/whatever, repeatedly listing the contents, then adding items which appear in OTHER to the various categories defined in ContentGate, until OTHER is empty. The purpose of this is to ensure that no items are uncategorised and that all items that are purposefully MISC are put there. I didn't want to miss that all-important item lurking in a big MISC category just because I hadn't spotted it.
- All strings are lower case in the categories. The script takes case of variations in case in the items being matched.
- There is a pecking order in the matching, so weapons come first, then armor and so on, with misc and other last. You might find you need to shuffle the order around to get items properly categorised.
- If you want to add a new category, it's very easy. Add the strings at the top of ContentGate, an empty table called my<NAME>. Add a new branch to the if statement on line 80 of CaptureContents and finally add a call to the print function at the end of Contents Lister.
- Pleeeease reply if you have any issues with this script, or have any suggestions for improvement. If generic I will happily make improvements.