Home
New Adventurer? Start Here!
Guilds Races Hunting Weapons Armor Magic Maps Skills and Trades Herbs and Alchemy Miscellaneous Contact Us Favors Gems Juggling Links Mindstates Scripting Tutorial Smoke Images Stats and Attributes Time In The Realms
Donate
Scripting Tutorial

We would like to thank Kalysta Kilia's darker half for submitting this information.

Introduction

Okay, for those of you who don't know what a script is, it's a very small program that you write, and run within Dragonrealms. It causes your characters to follow a pattern of actions without you having to type in each command separately. Scripts can be very simple, or disgustingly complicated. We'll start simple, and work our way about halfway up.

Mechanics

First things first. If you're using the Wizard, click on the Scripts tab at the top of the screen. From there, go to Create a New Script. A window will pop up with two small checkboxes and two lines where text can be entered. For now, click the Command Line checkbox. This means that rather than entering the script menu to run the script, you can just type the name of the script in game, and the script will start. The top line will be the name of the script (you can name it whatever you want, but you'll want to name it something that will remind you what the script does), and the bottom line is for entering a short description of what the script does. You don't have to enter anything in the bottom line unless you want to. Once you've named the script, click the Create button, and begin writing the script in the notepad that pops up.

When you are finished writing a wizard script, you must save it. Unless it is saved in the scripts folder that's in the DragonRealms folder, the script will not run, so make sure that it is saved properly.

If you're using Stormfront, click on Options at the top of the page, click on the Scripts option, then click the Create button in the window that pops up. A second window will pop up, with two lines for text at the top, and a larger window below. Name the script as you would if you were using the wizard, and give it a description if you desire, then begin writing the script in the larger window.

When you've finished writing a Stormfront script, you can merely close it, it will autosave.

Scripting Commands

When writing a script, you can use the same commands that you would use when playing the game. In order to have them register correctly though, you will need to use the command PUT before each command. For example (we'll name this script "mock"):

    #mock

    put look Ahni
    put point Ahni
    put laugh Ahni
    put laugh
    put laugh
    put fall

I'm sure you've noticed by now that each command is on a separate line. Keep things that way, it's the only way they'll work properly. Now that we've discussed PUT, we will move onto PAUSE. If you were to use the script as it is shown above, it would input all the commands at once, and the wizard would spit something back at you like: Sorry, you may only type ahead 1 command. Also, in the case of actions which result in roundtimes, putting one command right after the other will input the second command before the roundtime for the first command is over. In order to avoid this, we use PAUSE. Example:

    #mock

    put look Ahni
    pause 1
    put point Ahni
    pause 1
    put laugh Ahni

and so on and so forth. If you are dealing with commands that result in roundtimes, you'll want to use WAITs in place of pauses. In order to illustrate this, we'll need to add a new line to our script. Here we go:

    #mock

    pause 1
    put appraise Ahni
    pause 1
    wait
    put point Ahni
    pause 1
    put laugh Ahni

That was one way to write it. Here is another way that works. Keep in mind that this format is more susceptible to game lag problems:

    #mock

    put look Ahni
    pause 1
    put appraise Ahni
    waitfor roundtime
    put point Ahni
    pause 1
    put laugh Ahni

WAIT can also be used in another fashion. If you want the script to wait for something specific to happen in game before continuing, you can WAITFOR that action. Example:

    #mock

    put look Ahni
    pause 1
    put appraise Ahni
    waitfor Ahni says, "What?."
    put point Ahni
    pause 1
    put laugh Ahni
Variables

Now on to variables, just in case you want a script that you can use to point and laugh at every single person you meet. When you add a variable to a script, it allows you to change certain commands in the script without having to rewrite it each time. In wizard scripts, a variable is entered as a percent sign followed by a single digit. Example:

    #mock

    put look at %1
    pause 1
    put appraise %1
    waitfor roundtime
    put point %1
    pause 1
    put laugh at %1

When you start this script, you would start it by typing .mock ahni, and when the script runs, the %1 will be entered as Ahni's name. It will end up the same as the script above. You can enter any name or any object in place of Ahni. If you were to start the script by typing .mock Anoushka, the script would instead point and laugh at Anoushka. You can add more than one variable to a more complex script. Use %2 for a second variable, %3 for a third, and so on.

Sections

Now we'll start to get more complicated. So far we've been dealing with a script that has only one section. Now we'll break it up into different sections. To make things easier on yourself, each section of the script should have a different label. Example:

    #mock

    look:
    pause 1
    put look at %1
    goto appraise
    matchwait

    appraise:
    pause 1
    put appraise %1
    goto point
    matchwait

    point:
    pause 1
    put point %1
    goto laugh
    matchwait

    laugh:
    pause 1
    put laugh at %1

and so on. Notice that each label is followed by a colon. That distinguishes it from all the other normal lines in the script. Also notice that each section begins with a pause. This isn't strictly necessary, but it's a good precaution against having game lag stop your script in the middle. And while we're making observations, I'm sure you noticed a couple of new commands in the script; namely GOTO and MATCHWAIT. GOTO makes sure that you go on to the next section. As long as the GOTO is pointing at the right section, you can mix all the sections up and they'll still run in the correct order. MATCHWAIT basically acts as a WAIT, making sure that one section is finished before the script goes on to the next.

Matches

So far, this script will only perform one set of commands, no matter what happens. We're going to change that now. In order to do this, you must first know what you want your script to do, and what is likely to happen when these commands are carried out. We will assume, for the purpose of demonstration, that when you appraise your friend, they might or might not hide in order to escape your ridicule.

    #mock

    look:
    pause 1
    put look at %1
    goto appraise
    matchwait

    appraise:
    pause 1
    put appraise %1
    goto point
    matchwait

    point:
    pause 1
    put point %1
    match laugh You point at
    match search what you were referring
    matchwait

Here we are using something called a match table. It includes the possible results of your actions. The MATCH command indicates that you are going to be going to a different section of the script, and that which section you go to depends on the game's response to this section. After the MATCH, comes the name of the section that the script will be going to. Now comes the tricky part. After the name of the section, you must put a piece of THE GAME's possible responses to your actions. If you point at Ahni when he is not hidden, the game will tell you You point at Ahni. If you look at the match table, you'll see that if you manage to point at someone, the script will match to (or go to) the laugh section of the script. If you try to point at Ahni when he is hidden, the game will tell you I could not find what you were referring to. If that happens, the script will match to a new section, called search which I will now add, along with three other sections. One for if you find the hidden person, one just in case you don't, and one to finish things off.

    search:
    pause 1
    put search
    match search signs
    match pointout remain hidden
    match shout find anything of interest
    matchwait

Notice that if you search and find signs of the person hidden, the script goes back to the top of the search section and starts again. If you keep seeing signs, you will keep searching either until you find the person, or until you can't see signs anymore.

    pointout:
    pause 1
    put point %1
    waitfor roundtime
    goto laugh

    shout:
    pause 1
    put yell %1 is a wimp!!!
    goto end
    matchwait

    laugh:
    pause 1
    put laugh at %1
    goto end
    matchwait

    end:
    pause 1
    put smile

Keep in mind what when you are using match tables, the section of the game's response that you use must be EXACTLY the same as the wording that the game uses.

Conclusion

Well, you now know the basics of scripting. Here's the entire script in its finished form, just so it's easier to look at.


    #mock

    look:
    pause 1
    put look at %1
    goto appraise
    matchwait

    appraise:
    pause 1
    put appraise %1
    goto point
    matchwait

    point:
    pause 1
    put point %1
    match laugh You point at
    match search what you were referring
    matchwait

    search:
    pause 1
    put search
    match search signs
    match pointout remain hidden
    match shout find anything of interest
    matchwait

    pointout:
    pause 1
    put point %1
    waitfor roundtime
    goto laugh

    shout:
    pause 1
    put yell %1 is a wimp!!!
    goto end
    matchwait

    laugh:
    pause 1
    put laugh at %1
    goto end
    matchwait

    end:
    pause 1
    put smile