This system lets you organize your chat commands, easily adding or disabling commands without having to compile the whole system because of a few little changes.
Of note, only the server needs the 2DAs, and they can be in the override directory; they do NOT need to be distributed in a hakpak. (My demonstration module only does this to keep its resources together.)
There are two demos of the command processor, one showing use with OnPlayerChat and one with the NWNX chat plugin. The 2DAs and other scripts used are the same, making chat commands compatible regardless of how you retrieve chat.
Also available are some sample tables awaiting your commands, and erfs for quickly setting up OnPlayerChat or NWNX versions of the system.
chat_tables.2da This table helps you break up chat commands based on common prefixes.
All commands are assumed to begin with "/" and if a command matches none of the prefixes, then index 0 (default) is the assumed "prefix".
chat_*.2da Referenced by the chat_tables 2DA, this indicates what local variables to set on the speaker for use in what script.
The code box shows how to set up an example command. The demo shows off some simple commands, including an echo and a dice roller.
Concerns: Obviously, each command will end up with its own script. Some builders feel that this is bloat, however, it keeps each command independent of all other commands. They don't share dependencies and bugs in one command can't result in problems for another command. It also makes it easier to look up where a command is implemented, as well as import specifically desired commands from a compatible package without having to delete lines of code.
Sample chat_tables.2da, chat_default.2da, and chat_commands.2da to get you started; you can copy and rename chat_commands to chat_emotes, for example, to organize your emote chat scripts.