MUD Interaction
Functions for interacting with the MUD server and terminal output.
Sending Commands
send
Send a command to the MUD server.
send(command)| Parameter | Type | Required | Description |
|---|---|---|---|
| command | string | Yes | The 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)| Parameter | Type | Required | Description |
|---|---|---|---|
| command | string | Yes | The command to execute |
Terminal Output
echo
Output text to the terminal (visible to the user but not sent to MUD).
echo(text, color?)| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| text | string | Yes | - | Text to display in terminal |
| color | string | No | - | Optional color for the text |
Note: For most use cases, prefer
print()for plain text orutilprint()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 a message to the plugin output/terminal.
print(message)| Parameter | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | Message 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)| Parameter | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | Text with color codes to print |
Color Codes:
| Code | Color | Example |
|---|---|---|
$R | Red | $RError |
$G | Green | $GSuccess |
$B | Blue | $BInfo |
$Y | Yellow | $YWarning |
$C | Cyan | $CNote |
$M | Magenta | $MSpecial |
$w | White | $wText |
$xNNN | xterm 256 | $x092 (bright green) |
$XRRGGBB | True 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?)| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| table | table | Yes | - | Table to print |
| indent | number | No | 0 | Initial indentation |
| done | Set | No | Tables 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" = 50colourNote
Output colored text to the terminal.
colourNote(foreground, background, text)| Parameter | Type | Required | Description |
|---|---|---|---|
| foreground | string | Yes | Foreground color name |
| background | string | Yes | Background color name (can be empty "") |
| text | string | Yes | Text to display |
Supported Color Names:
black,red,green,yellowblue,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)| Parameter | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | Text 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?)| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| commandName | string | Yes | - | Command name (without leading slash) |
| handler | function | Yes | - | Function to handle the command |
| description | string | No | "" | 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 tavernDelayed Execution
DoAfter
Execute a command after a delay.
DoAfter(seconds, command)| Parameter | Type | Required | Description |
|---|---|---|---|
| seconds | number | Yes | Delay in seconds |
| command | string | Yes | Command 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)| Parameter | Type | Required | Description |
|---|---|---|---|
| seconds | number | Yes | Delay in seconds |
| code | string | Yes | Command or script to execute |
| sendto | number | Yes | Send-to constant (see below) |
Send-to Constants:
| Constant | Value | Description |
|---|---|---|
| sendto.world | 0 | Send to MUD |
| sendto.output | 1 | Echo to terminal |
| sendto.execute | 10 | Execute as command |
| sendto.speedwalk | 11 | Execute as speedwalk |
| sendto.script | 12 | Execute as script |
| sendto.variable | 14 | Store 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!")