Chapter 1: Your first script
This chapter walks you through setting a script on a mob and seeing it run. By the end you will understand the OLC workflow and have a mob that greets people when they enter the room.
Step 1: Pick a mob to edit
Choose a mob vnum in a zone you have access to. For this example we will use vnum 1200. Open it for editing:
olc medit 1200
You should see a message like "Now editing mobile 1200." If the vnum does not exist yet, OLC will create a new mob prototype.
Step 2: Open the script editor
olc mset script
This opens the built-in text editor (TEDII). You will see a ruler line and a line-number prompt. Everything you type from here is script source code.
The editor commands all start with &:
| Command | What it does |
|---|---|
&h |
Show help |
&r |
Refresh / redisplay |
&l N text |
Replace line N |
&d N |
Delete line N |
&i N text |
Insert before line N |
&e |
Save and exit |
&q |
Quit without saving |
@ |
Save and exit (shortcut) |
Step 3: Write the script
Type the following script into the editor, one line per prompt:
after enter {
do "say Welcome, [name $actor]!"
}
That is three lines. After typing the closing }, press enter, then
type @ on a new line to save and compile the script.
If the script compiles successfully, you will see a message confirming
the save. If there is a compile error, the error message will tell you
which line has the problem — fix it with &l and save again.
Step 4: Load the mob
olc mload 1200
This loads a copy of mob 1200 into your current room. The mob now has your script attached.
Step 5: Trigger the event
Walk out of the room and back in. When you enter, you should see the mob say:
A guard says, 'Welcome, Yourname!'
Congratulations — your first script is running.
What just happened?
Let's break down the script:
after enter {
do "say Welcome, [name $actor]!"
}
after enter— this is a handler. It runs after someone enters the room. Theafteris the phase andenteris the event.{ ... }— the body of the handler, a block of code that runs when the event fires.$actor— a variable automatically set to the creature who triggered the event (the person who entered).[name $actor]— a command substitution. It calls thenamebuiltin with$actoras its argument, and the result (the creature's name) is spliced into the surrounding string.do "say ..."— thedocommand makes the mob execute a game command. Here the mob says something. The double-quoted string allows substitutions with$and[...].
Updating a script
To change the script, repeat the process:
olc medit 1200olc mset script— the editor opens with the current script.- Make your changes.
@to save.
The new script takes effect immediately on all loaded copies of mob 1200 — you do not need to reload the mob.
Saving to disk
Everything so far lives in memory. To persist your changes across reboots:
olc msave
This writes the mob (and its script) to the zone's world files.
Try it yourself
Modify the script to also react when someone leaves:
after enter {
do "say Welcome, [name $actor]!"
}
before leave {
do "say Safe travels, [name $actor]!"
}
Walk in and out of the room. The mob should greet you on entry and wish you well when you leave.
Note the before phase on leave — the mob needs to speak while the
player is still in the room. An after leave handler would run after
the player has already gone.
Key points
- OLC workflow:
medit→mset script→ write →@→mload→ trigger. - Handlers bind code to events. The format is
phase event { body }. $actoris the creature that caused the event.domakes the mob execute a game command.[name $x]calls a builtin inside a string (command substitution).- Double-quoted strings (
"...") allow$varand[cmd]substitutions.