GMCP Mudlet Tutorial

From LegendMUD
Jump to navigation Jump to search

Enabling GMCP[edit]

In Mudlet you can enable GMCP via the Settings for your session. Once a session is opened, open the Settings:

How to open settings

In the settings, under the Game Protocols section, ensure the Enable GMCP checkbox is checked.

How to enable GMCP

Receiving a GMCP message[edit]

Once GMCP is enabled, the MUD will begin sending GMCP messages.

There are two types of GMCP messages, broadcasts and requested messages. Broadcast messages will happen automatically, while requested messages will only be sent by the MUD if the client requests them. The full list of packages and their message types can be found here.

Mudlet automatically saves all data from GMCP messages in a global gmcp variable. For example, if you wanted to read the area name from the prompt, you can do this at any time, from anywhere via the following variable:

gmcp.char.prompt.an

For debugging purposes, please note that the echo function will not work with objects, only strings. If you try to echo(gmcp.char.prompt.an), it will work because that is a string for the Area Name. If you try to echo(gmcp.char.prompt) however, it will not work because that is an object containing all of the prompt code values. Instead, it is recommended to use the display function to print objects to the screen.

Sometimes you need to be able to trigger off of a GMCP message. This can be done by creating a GMCP script.

Create a new script (not a trigger) and give it a name. Enter the package name in the Add User Defined Event Handler field and hit the "plus" sign to add it. This package name must be prepended by gmcp.. For example, the char.status package would be added to the event handlers as gmcp.char.status. A full list of available packages can be found here.

Creating a GMCP trigger in Mudlet

You can also match partial packages to trigger on multiple GMCP messages. For example, you can set the pattern to gmcp.char to trigger on any character related GMCP message.

Sending a GMCP message[edit]

The MUD will not broadcast every message that is available. Some messages must be manually requested. Additionally, some broadcasted messages can also be requested if you need to refresh the data before the MUD would broadcast again.

The following script can be used to send a request to the MUD:

sendGMCP("char.prompt")

If you need to send additional parameters for the requested package, you can do so:

sendGMCP([[char.prompt {"additional": 1, "parameters": "hello"}]])

You can also use the following syntax:

sendGMCP("char.prompt"..yajl.to_string({"additional": 1, "parameters": "hello"})

Note that as of writing, none of the Legend packages take any parameters, required or optional.