Page 1 of 1

Generic Categoriser/Inventory or Contents Lister - with colours

Posted: Sat Mar 10, 2018 10:02 am
by ulysses

Here is a script I wrote for CthulhuMUD ( 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:
(9.63 KiB) Downloaded 120 times
  1. 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.
  2. 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:

    Code: Select all

    if not string.match(line, 'It contains') then
    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.
  3. 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.
  4. Other parts of the script should be portable, except perhaps the read quantity part in CaptureContents (line 35ff).
  5. 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.
  6. All strings are lower case in the categories. The script takes case of variations in case in the items being matched.
  7. 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.
  8. 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.
  9. Pleeeease reply if you have any issues with this script, or have any suggestions for improvement. If generic I will happily make improvements.

Re: Generic Categoriser/Inventory or Contents Lister - with colours

Posted: Sun Mar 11, 2018 3:38 am
by Vadi
Nice! Could you show a screenshot?

Re: Generic Categoriser/Inventory or Contents Lister - with colours

Posted: Sun Mar 11, 2018 6:17 pm
by ulysses
Vadi wrote:
Sun Mar 11, 2018 3:38 am
Nice! Could you show a screenshot?
Thanks, Vadi. Here's a screenshot of the first part of the listing:
Screenshot 2018-03-11 18.08.19.png
And another a bit further down:
Screenshot 2018-03-11 18.27.42.png
I'm thinking that a two-column (or N-column) output might be a next big improvement. Just having things categorised and sorted alphabetically is a massive bonus - before it was a complete jumble and very time consuming to find one particular item. I just noticed that all the keyrings end up in JEWELS not KEYS because of 'ring' - something to fix!