|
This section is a step by step tutorial to explain the basics on writing
scripts. It goes through the script creation process developing a practical
script. For more details for a step, refer to the appropriate section in the
later portion of this document.
- Decide what the script should do.
First, consider how your mob, item,
or room should behave. Doing this before worrying what can be done prevents
you from limiting yourself to what you have seen other scripts do, and
produces a more interesting script.
For example, I want to create a gate guard for a small walled
town. The ruler of the town has decided that each groups of people will be
charged ten coins to enter his domain. The gate guard must notify travelers
of the cost to enter, collect the money, allow people who have payed to
enter the city, and close the gate after them. This will be a mob script.
- Decide what trigger types you need.
Look through the section on triggers
to see the currently available trigger types. New triggers can be added by one
of the implementors if needed.
Our gate guard needs to react to five different events:
- a. A character entering the room from the north, the road leading away
from the town, needs to be informed of the price for entrance. This will
be a greet trigger.
- b. When the guard is given ten or more coins, the guard must open the
gate. This is done by a bribe trigger.
- c. If the guard is given less than ten coins, the guard needs to
inform the character that it is insufficient. This is also a bribe
trigger.
- d. When someone passes through the gate into the city, the guard must
close the gate behind them. This is done with an act trigger.
- e. When the gate is opened from the other side, the guard must
eventually close it. This will be another act trigger.
- Determine the argument and the numerical argument (NArg) of the
triggers.
Read the specifications on trigger
types, and decide what the values for argument and NArg must be for the
trigger to react appropriately to the events.
- a. The argument for the greet trigger is not used. The NArg is the
percent chance that the trigger is run when checked. Since I want it run
every time someone enters the room, it should be 100.
- b. The argument for the bribe trigger is not used. The NArg is the
minimum amount that must be given to the guard for him to react. The guard
should only open the gate when given 10 coins, so NArg should be 10.
- c. For this bribe trigger, the guard must respond whenever someone
gives him 1 or more coins, so NArg should be 1.
- d. The argument for the act trigger is the text of the mob should
react to. Since I want the guard to react to a character going south and
entering the city, the argument should be "leaves south." Since argument
is a phrase, NArg should be 0.
- e. I want the text for this act trigger to be "The gate is opened from
the other side", so it is triggered whenever someone opens the gate from
inside the town. Again, NArg should be 0 for a phrase.
- Write the list of commands for the trigger.
This is the most complex
and time consuming part of a trigger to write. The valid commands are
explained in the Commands
chapter. Variables
and expressions
are also used in the commands list, which are covered in later sections.
- a. For the greet trigger, I want the guard to inform anyone entering
from the north how to get into the city. First, I must check if the
character is entering from the north. If they are entering from that
direction, the guard should tell the character the cost of entry. The
command list for this trigger will be as follows:
if (%direction% == north) wait 1
emote snaps to attention as you approach. wait 1 say Admittance to the
city is now 10 coins for your group. end Checking the
specifications of the greet trigger, we see that the variable "direction"
is set to the direction that the character entered. The percent sign
surrounding direction means it is a variable. The two equal signs together
compare the value of the variable to the word "north". If these are equal,
the statements between this line and the line "end" will be
executed. The "wait 1" pauses briefly (about two seconds) while
the character finishes his move. (The greet trigger is actually checked
before the character enters the room, so if we did not have this line, he
or she would never see the guard snap to attention.) After another brief
pause, the guard announces the cost to enter the town. The indentations
are not needed, but make it easier to read.
- b. The guard must open the gate if ten or more coins were given to
him. The command list looks like this:
wait 1 unlock gate open gate wait 20 s close gate lock gate After
a brief wait (so everything doesn't happen at once), the guard unlocks the
gate and opens it. The guard will close the gate after 20 seconds, even if
no one passes through it.
- c. The guard must inform the character that his payment was not
enough, and return the money. The commands list will be:
wait 1 say This is not enough! give %amount% coins %actor% For
the line "give %amount% coins %actor%", the variables amount and
actor, both set when the bribe trigger is called, are substituted into the
line before the guard performs the command. The gate guard returns the
number of coins he was given.
- d. For the first act trigger, I want the guard to close and lock the
gate after someone passes through the gate. The guard should wait briefly
so he isn't shutting the gate on the character's back, and close and lock
the gate. The command list will be:
wait 1 close gate lock gate
- e. For the last act trigger, the we want the guard to close and lock
the gate when it is opened from the other side. The commands will look
like:
wait 5 close gate lock gate The "wait 5" gives time
for someone on the other side to get through the gate.
- Decide the order of the triggers.
The triggers are checked from first
to last. If there are two triggers of the same type, the first one run will be
the only one run.
There are two sets of triggers which are the same type, the
bribe triggers and the act triggers. If the bribe trigger with the NArg of 1
is first, the other trigger would never be run, since ten or more coins is
still one or more. In order for my triggers to work right, the trigger with
NArg of 10 must be before the trigger with the NArg of 1 in the list. The
other possible conflict is with the act triggers. Since both have arguments
that will not occur together, the order does not matter.
- Create the trigger file.
Simply use trigedit
to create your triggers and they will be saved for you when you exit the
editor.
- Put the triggers into the game.
In the OasisOLC medit / redit / oedit
menus, use menu option S to enter the script editor. Then select the triggers
that will be part of your script. Note, that order is important! If
there are two possible triggers that could both be executed at the same time,
only the first one found in the list will be activated.
- Test the script.
You should see how the script actually work in the
game, and watch other people interact with it. Often you will see ways you can
improve it.
|