Chapter 2: Reacting to commands
The command event fires when a player types a game command in the
same room as the mob. This is the most common event — it is how you
make NPCs respond to what players say and do.
A mob that responds to "say"
Open your mob's script and enter:
after command (say) {
do "say Did you say something, [name $actor]?"
}
Load the mob and type:
say hello
The mob responds. Try say goodbye — same response. The handler fires
on every say command.
Filters
The (say) after command is a filter. It restricts the handler
to fire only for say commands. Without a filter, the handler would
fire on every command — look, north, get, everything.
You can list multiple commands in the filter:
after command (say sayto) {
do "say I heard that!"
}
Now the handler fires for both say and sayto.
The $arg and $args variables
When a command event fires, two extra variables are available:
$arg— the full text after the command verb, as a single string.$args— the same text, split into individual words.
after command (say) {
do "say You said: $arg"
}
If the player types say hello world, the mob responds with
"You said: hello world".
Checking specific words
Use keyword to check if specific words appear in $args:
after command (say) {
require [keyword $args help]
do "say You need help? Talk to the shopkeeper."
}
The require guard checks a condition. If [keyword $args help] is
false (the player did not say "help"), the handler stops and nothing
happens. If true, the mob responds.
keyword does case-insensitive matching, so "Help", "HELP", and
"help" all match.
You can check for multiple keywords at once:
after command (say) {
require [keyword $args hi hello hey greetings]
do "say Well met, [name $actor]!"
}
Checking abbreviations
Use abbrev for prefix matching — so a player typing "hel" matches
"help":
after command (say) {
require [abbrev $args help quest]
do "say I can help you with a quest!"
}
Now "hel", "help", "que", "quest" all match.
The $arg string vs $args words
Use $arg when you want the full text as a string (for display or
exact matching). Use $args when you want to check individual words.
after command (say) {
# Check exact string match (case-insensitive)
require [streqi $arg "open sesame"]
do "emote opens the secret door."
}
after command (say) {
# Check if any word matches
require [keyword $args password]
do "nod"
}
Responding to non-say commands
Any game command can be filtered:
after command (give) {
do "say Thank you for the gift, [name $actor]."
}
after command (bow) {
do "bow [name $actor]"
}
Example: a helpful guard
Here is a complete script combining several concepts:
after enter {
do "say Halt! State your business."
}
after command (say sayto) {
require [keyword $args quest job work]
do "say Speak with the elder in the temple to the north."
}
after command (say sayto) {
require [keyword $args shop store buy sell]
do "say The market is to the east."
}
after command (bow) {
do "bow [name $actor]"
}
Load the mob, enter the room, and try:
say where can I find work?say where is the shop?bow
Key points
commandhandlers react to player commands withafter command (verb) { ... }.- Filters
(say sayto)restrict which commands fire the handler. $argis the raw text after the verb;$argsis a word the same text split into individual words.keywordchecks for exact word matches (case-insensitive).abbrevchecks for prefix abbreviations.requireis a guard — if the condition is false, the handler stops.