Difference between revisions of "TRIGEDIT-ADVANCED-TUTORIAL"
(Bot: Automated import of articles) |
m |
||
Line 1: | Line 1: | ||
'''TRIGEDIT-ADVANCED-TUTORIAL''' | '''TRIGEDIT-ADVANCED-TUTORIAL''' | ||
[[Category:Help Files]] | [[Category:Help Files]] | ||
− | + | [[Category:Building]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Latest revision as of 11:28, 14 July 2017
TRIGEDIT-ADVANCED-TUTORIAL
This section is a step by step tutorial to explain the writing of scripts
(triggers). It goes through the script creation process developing a practical
script.
Decide what you want the script to do.
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 allows you to produce 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 group 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 trigger types can be added by one of the implementors if needed. All
types are listed in the help files {cRHELP TRIGEDIT-TYPE{c0.
Our gate guard needs to react to five different events:
- A character entering the room from the south, the road leading away from the
- town, needs to be informed of the price for entrance. This will be a greet
- trigger.
- When the guard is given ten or more coins, the guard must open the gate. This
- is done by a bribe trigger.
- 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.
- When someone passes through the gate into the city, the guard must close the
- gate behind them. This is done with an act trigger.
- 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 of the triggers. Read the
specifications on trigger types, and decide what the values for argument and
Numeric Arg must be for the trigger to react appropriately to the events.
{cRHELP TRIGEDIT-MOB-GREET{c0
Argument : not used
Numeric Arg : 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.
{cRHELP TRIGEDIT-MOB-BRIBE{c0
Argument : not used
Numeric Arg . minimum number of gold pieces required to activate this trigger.
The guard should only open the gate when given 10 coins, so it
should be 10.
For the second bribe trigger, the guard must respond whenever someone gives
him 1 or more coins, so Numeric Arg should be 1.
{cRHELP TRIGEDIT-MOB-ACT{c0
Argument : the text the mob should react to. Since I want the guard to
react to a character going north, argument should be "leaves
north."
Numeric Arg : Since argument is a phrase, NArg should be 0.
The second act trigger should trigger on text "The gate is opened from the other
side", so it is triggered whenever someone opens the gate from inside the town.
Again, Numeric Arg 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 help files and on the webpage. Variables
and expressions are also used in the commands list.
For the greet trigger, I want the guard to inform anyone entering from the
south how to get into the city. First, I must check if the character is
entering from the south. 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% == south)
wait 1 sec
emote snaps to attention as you approach.
wait 1 sec
say Admittance to the city is 10 coins.
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 "south". If these are equal, the
statements between this line and the line "end" will be executed. The "wait 1 sec"
pauses briefly 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.
The guard must open the gate if ten or more coins were given to him. The
command list looks like this:
wait 1 sec
unlock gate
open gate
wait 10 sec
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 10 seconds, even if
no one passes through it.
The guard must inform the character that his payment was not enough, and
return the money. The commands list will be:
wait 1 sec
say This is not enough!
give %amount% coins %actor.name%
For the line "give %amount% coins %actor.name%", 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.
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 sec
close gate
lock gate
For the last act trigger 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 sec
close gate
lock gate
The "wait 5 sec" 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 Numeric Arg 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 Numeric Arg 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. In this example, it means place the bribe trigger for 10 or more
coins BEFORE the bribe trigger for 1 coin.
Test the script.
You should see how the script actually works in the game, and watch other
people interact with it. Often you will see ways you can improve it.
{cRGOTO 1310{c0 and work your way north to test these out. Triggers 4-8.