Chat command parser

A framework for Neverwinter Nights 1 persistent world servers.

This submodule’s canonical repository is available at https://git.highlandarrow.com/Waymark/command-parser

This documentation is current as of the 1.1 version of the command parser module.

@commands parsing

A common method of interfacing with certain things - emotes in particular - is to use chat commands. Waymark implements an abstraction interface to allow developers to easily add new chat commands in a standardized format.

The wm_chat script, when used as the onPlayerChat() script, will automatically manage commands sent to the game server with the given prefix.

const string WM_CHAT_SCRIPT_PREFIX = "wmc_";

Changing this constant, located at the top of wm_chat.nss, will change the prefix used for chat command scripts.

The command prefix is, by default, an at sign. You can change this in the same place:

const string WM_CHAT_COMMAND_PREFIX = "@";

Creating a script for parsing

It is easy to create a script that is parsed in this way, you only have to create a script that is named PREFIX_COMMANDNAME so for instance, if you wanted to make a command @emote you create wmc_emote.nss by default.

All command arguments (ie, the stuff following @emote, in the examples case) are passed to the main() procedure in the given file using script params. You can retrieve them with:

string sParams = GetScriptParam("CMD_PARAMS");

You can of course name the variable whatever you like.

Otherwise it really is as simple as that. There isn’t any complicated magic to coding these things.