Skip to Content
API ReferenceMUD Interaction

MUD Interaction

Functions for interacting with the MUD server and terminal output.


Sending Commands

send

Send a command to the MUD server.

send(command)
ParameterTypeRequiredDescription
commandstringYesThe command to send to the MUD

Example:

-- Send a simple command send("look") -- Send movement commands send("north") send("go north") -- Send commands with arguments send("say Hello, everyone!") send("tell bob How are you?")

executeCommand

Execute a command through the command dispatcher.

executeCommand(command)
ParameterTypeRequiredDescription
commandstringYesThe command to execute

Terminal Output

echo

Output text to the terminal (visible to the user but not sent to MUD).

echo(text, color?)
ParameterTypeRequiredDefaultDescription
textstringYes-Text to display in terminal
colorstringNo-Optional color for the text

Note: For most use cases, prefer print() for plain text or utilprint() for colored output with color codes.

Example:

-- Prefer print() or utilprint() for output: print("Plugin loaded successfully!") utilprint("$GSuccess: $wPlugin loaded!") -- Green "Success:" with white text -- echo() still works for backwards compatibility: echo("Legacy message", "#ff0000")

print

Print a message to the plugin output/terminal.

print(message)
ParameterTypeRequiredDescription
messagestringYesMessage to print

Example:

print("Debug: Current HP = " .. hp) print("Processing trigger...")

utilprint

Print colored text to the terminal with automatic color code parsing. This is the recommended function for colored output.

utilprint(message)
ParameterTypeRequiredDescription
messagestringYesText with color codes to print

Color Codes:

CodeColorExample
$RRed$RError
$GGreen$GSuccess
$BBlue$BInfo
$YYellow$YWarning
$CCyan$CNote
$MMagenta$MSpecial
$wWhite$wText
$xNNNxterm 256$x092 (bright green)
$XRRGGBBTrue color$XFF0000 (red)

Example:

-- Basic colors utilprint("$RError: $wConnection failed") utilprint("$GSuccess: $wOperation complete") utilprint("$YWarning: $wLow health!") -- xterm 256 colors (for more color options) utilprint("$x092Fancy $x091colored $x090text") -- True color RGB hex utilprint("$XFF0000Red $X00FF00Green $X0000FFBlue") -- Status messages utilprint("$C[Info] $wPlayer joined the game") utilprint("$M[System] $wSaving data...")

tprint

Print a Lua table in a readable format (for debugging).

tprint(table, indent?, done?)
ParameterTypeRequiredDefaultDescription
tabletableYes-Table to print
indentnumberNo0Initial indentation
doneSetNoTables already printed (prevents circular refs)

Example:

local player = { name = "Hero", level = 10, stats = { hp = 100, mp = 50 } } tprint(player) -- Output: -- "name" = "Hero" -- "level" = 10 -- "stats": -- "hp" = 100 -- "mp" = 50

colourNote

Output colored text to the terminal.

colourNote(foreground, background, text)
ParameterTypeRequiredDescription
foregroundstringYesForeground color name
backgroundstringYesBackground color name (can be empty "")
textstringYesText to display

Supported Color Names:

  • black, red, green, yellow
  • blue, magenta, cyan, white

Example:

-- Red text on default background colourNote("red", "", "DANGER: Low health!") -- Green text on black background colourNote("green", "black", "You found 100 gold!") -- Yellow warning colourNote("yellow", "", "Warning: Player approaching")

Note

Echo text to the terminal.

Note(text)
ParameterTypeRequiredDescription
textstringYesText to display

Example:

Note("This is displayed in the terminal")

Plugin Commands

registerCommand

Register a custom command that can be executed from the terminal.

registerCommand(commandName, handler, description?)
ParameterTypeRequiredDefaultDescription
commandNamestringYes-Command name (without leading slash)
handlerfunctionYes-Function to handle the command
descriptionstringNo""Description for help text

Example:

-- Register a simple command registerCommand("hello", function(args) print("Hello, " .. (args or "world") .. "!") utilprint("$G[Greeting] $wHello, " .. (args or "world") .. "!") end, "Say hello to someone") -- Register a status command registerCommand("status", function() print("HP: " .. getVariable("hp") .. "/" .. getVariable("maxhp")) print("MP: " .. getVariable("mp") .. "/" .. getVariable("maxmp")) utilprint("$RHP: $w" .. getVariable("hp") .. "/" .. getVariable("maxhp")) utilprint("$BMP: $w" .. getVariable("mp") .. "/" .. getVariable("maxmp")) end, "Show character status") -- Register a command with arguments registerCommand("goto", function(args) if args then send("speedwalk " .. args) else print("Usage: /goto <destination>") utilprint("$YUsage: $w/goto <destination>") end end, "Go to a named location")

Usage: Once registered, commands can be invoked from the terminal with /commandName:

/hello World /status /goto tavern

Delayed Execution

DoAfter

Execute a command after a delay.

DoAfter(seconds, command)
ParameterTypeRequiredDescription
secondsnumberYesDelay in seconds
commandstringYesCommand to execute

Example:

-- Send "look" after 2 seconds DoAfter(2, "look") -- Chain delayed commands DoAfter(1, "drink potion") DoAfter(2, "cast heal") DoAfter(3, "attack")

DoAfterSpecial

Execute a command or script after a delay with specified send-to target.

DoAfterSpecial(seconds, code, sendto)
ParameterTypeRequiredDescription
secondsnumberYesDelay in seconds
codestringYesCommand or script to execute
sendtonumberYesSend-to constant (see below)

Send-to Constants:

ConstantValueDescription
sendto.world0Send to MUD
sendto.output1Echo to terminal
sendto.execute10Execute as command
sendto.speedwalk11Execute as speedwalk
sendto.script12Execute as script
sendto.variable14Store in variable

Example:

-- Send to MUD after delay DoAfterSpecial(5, "drink potion", sendto.world) -- Echo message after delay DoAfterSpecial(10, "Timer expired!", sendto.output) -- Execute script after delay DoAfterSpecial(3, "healIfLow()", sendto.script)

Complete MUD Interaction Example

-- Combat helper plugin print("Combat plugin loading...") local combatActive = false local targetName = nil registerCommand("attack", function(args) local target = args[1] if target then targetName = target combatActive = true send("kill " .. target) print("Starting combat with " .. target) utilprint("$R[Combat] $wTargeting: " .. target) else print("Usage: /attack <target>") utilprint("$RUsage: $w/attack <target>") end end, "Start combat with a target") registerCommand("flee", function() if combatActive then combatActive = false send("flee") print("Fleeing from combat!") utilprint("$Y[Flee] $wEscaping combat!") else print("Not in combat") utilprint("$w[Info] Not in combat") end end, "Flee from combat") -- Low health warning addTrigger("Your health is critical", function() colourNote("red", "", "!!! CRITICAL HEALTH !!!") DoAfter(0.5, "drink healing potion") end) -- Combat end detection addTrigger("is DEAD", function(line) if combatActive then combatActive = false print("Combat ended - " .. targetName .. " defeated!") utilprint("$G[Victory] $w" .. targetName .. " defeated!") targetName = nil end end) print("Combat plugin loaded!")
Last updated on