Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Guest Lecture- MW Scripting by: Fliggerty


Fliggerty
 Share

Recommended Posts

Good morning class and welcome to Morrowind Scripting 101

I am your instructor Fliggerty. You can call me Mr. E. if you wish.

Before we being, I want to discuss the primary goals and objectives of this course. First and foremost you are here to learn how to use Morrowind scripts to accomplish various effects in your mods.

But why am I here? Simply put, I have learned many tips and tricks over the years. I have pioneered various techniques, and done what others have said is impossible. And I give full credit to those who have shared their knowledge with, and those who have created new tools for us to use. I believe in giving freely of what I have freely received.

I am not much of a programmer. I understand the theory of various programming languages, and have certainly tried to learn how to use it. I just have a hard time with programming for the most part. And yet I understand scripting. So that's good news you don't have to be a programmer to be a scripter! In fact many programmers find themselves bored and frustrated with the simplistic scripting language we use (which has worked in our favor by enticing them to create things such as MWSE.)

So what is going to make this class any different than the myriad scripting tutorials available? Variety, for one thing. But while I am going to start at the beginning, we will go through that part quickly. I intend to spend the majority of our time on more advanced concepts. I am going to include using MWSE and MGE nearly from the beginning. I am going to teach you things that are not found in any tutorial yet written.

Since we are going to go through the beginning quickly, this may be nothing more than a boring read. If you want a more interactive version of Lesson 1, I would suggest creating my_first_script as outlined starting on page 13 of Morrowind Scripting for Dummies. (I suggest that for everyone, even if you do read through all of this.)

What is a script?

When someone is making a movie they use a script to tell the actors what to say, when to say it, and where to stand. A script in Morrowind is essentially the same thing. It tells the game engine what to do, how to do it, and when. In fact, in many tutorials you read, an NPC might be referred to as an actor.

There are two types of scripts: local and global. A local script is one that is attached to a specific object and is always running when the object is present. An example of this is the OutsideBanner script which makes banners wave in the wind. The second type of script is a global script. A global script, once started, will always be running until it is stopped regardless of objects that are or are not present. An example of this is dbattackscript which makes the Dark Brotherhood attack no matter where the player is. There is a type of global script that we call a targeted script. To better explain what that is though, we ought to first discuss some terminology.

Script Terminology and Syntax

Functions are the building blocks of a script. A function is a command that is used to retrieve information from the engine, or to pass information back to it. For example, the function GetHealth will tell you how many health points are left. SetHealth will change the health points to the value you specify.

The next major component of a script is the variable. MW scripting has 3 types of variables: short,long, and float. A short variable is used for smaller integer values, those from -32768 to 32767; a long is for integer values from -2,147,483,648 to 2,147,483,647; and a float is used for decimal integers, or partial numbers. MWSE also introduces string variables, which we will discuss later. Most functions will return or require a specific type of variable, so make sure to use the correct one.

Before you can use any variable, you have to first declare it. This will tell the script what the variable name is and what type. Let's say we want to use a variable that will store the players current health. GetHealth returns a float variable according to MWSFD (Morrowind Scripting for Dummies.) So we will declare a float variable and call it PCHealth: float PCHealth

This is usually done at the top of the script. It's a good idea to declare all of your variables together. I try to keep them nice and neat, placing all of the shorts together, then the longs, and the floats. Its not necessary, but it sure does help in keeping them straight. Some people also identify what type of variable they declared by appending an s, l, or f to the beginning. So they would have ftemp, or stemp instead of just temp.

Generally when you use a function you need four things: a condition, an operator, an infix, and a postfix. Take this line (by the way, a line such as the one below is called a conditional statement):

if ( player->GetHealth > 1 )

The condition here is if Other conditions are while, else, and elseif.

The operator is > (greater than.) Others are < (less than,) == (equal to,) != (not equal,) <less>= (greater than or equal.)

The infix (also called a calling actor or reference, which is the term I will usually use) is player. Infix refers to the data that is being passed into the function. We are telling the GetHealth function to look at the player reference.

Postfix refers to the data returned by the function. In our example the postfix is 1. With most vanilla scripting functions the postfix is a numerical value.

Let's now assume that we will need to know how much health the player has left in several parts of a script. We could call the GetHealth function each time, or we could simply use a variable.

set PCHealth to player->GetHealthif ( PCHealth > 1 )

This is essentially the same as the statement we used above, except that we can now use that same variable in more than one place, for as many statements as we need.

There are a few things to note about Morrowind scripting. Spacing can be a very important thing. It is imperative that you put a single space on each side of every parenthesis ( or ) that you use. Failure to do so will cause weird errors. Also, never put a space on either side of a -> despite what some tutorials say. I have seen lots of glitches caused by doing this.

if (player->GetHealth > 1) ;wrongif ( player -> GetHealth > 1 ) ;wrongif ( player->GetHealth > 1 ) ;correct

Commas are another thing to be careful with. Consistency seems to be the important factor with them. Some functions supposedly require a comma between parameters:

PlaceAtPC, Fargoth, 1, 100, 1

I find that proper comma usage can become confusing, so I make it a practice to never use them. Everything works just fine without it. Remember that consistency is the key here, so either always use a comma or never use it.

I hold the same rule with quotes. I always put quotes around any ID, whether it be an NPC's ID, or the ID of a script that I am starting. It is necessary to use them when the ID happens to have two or more words, but not when it is only one word. However, once again being consistent is important.

Now that we've learned some terminology, I want to touch briefly on a targeted script. A targeted script is simply a global script. The difference between these and a normal global script is that they have an <em class='bbc'>inherited</em> infix. Let's say I have a script that will display the health of its target every 5 seconds. I would like it to work for any NPC, rather than just the player. So instead of using this statement:

set PCHealth to player->GetHealth

I would use this:

set PCHealth to GetHealth

Do you notice anything missing? Where is the infix? It doesn't have one. So how does the engine know what reference to look for?

The answer is simple. In another script I would have this line:

player->StartScript gethealth_script

That is defining the infix for the entire gethealth_script script. So any function called in that script that does not have a specific infix will default to the player. Alternatively, I could call StartScript in the results box of a dialogue entry and it would run on the NPC that I am talking to.

Basically every global script is a targeted script, with the exceptions being Start Scripts that the engine runs when the game is loaded (we'll touch on those more in Lesson 2.)

Every script has a beginning, a middle, and an end. The middle is optional, but the rest isn't. You tell the engine where your script starts, and what the script's ID is by using the begin statement. Likewise, you tell it where to finish by using end.

begin sample_script ;do some cool stuff hereend

Most tutorials will tell you to include the script ID after the end, but it's not necessary.

When a script is running, the engine will start at the top and work its way down, line by line, until it comes to the end, or it is interrupted. So if you want one thing to happen before another, all you need to do is put the first action above the second. In some cases though, we don't want the script to go past a certain point. In such a situation we use the return function. This will act like the end of the script, telling the engine to return back to the top. A common use of this is to halt the script entirely when the player is in a menu (this is a good idea to always include unless your script specifically needs to run while the player is in a menu.)

if ( MenuMode == 1 ) ReturnEndif

So whenever the player is in inventory, dialogue, or any other menu, the engine will not run anything past this point.

Another common function used in many scripts is the MessageBox. This is how we display data to the player, and also retrieve information. The primary use that I put it to is debugging. I will usually declare a variable called <em class='bbc'>debug</em> which I set to 1 when I am testing a script.

if ( debug == 1 );MessageBox it seems to be working just fine Endif

We'll be using some better examples of this in most of the following lessons.

The final basic concept we need to talk about is commenting your script. Do it! Do it well and thoroughly. I am horrible at following through with this advice, and I have paid the price by having to spend hours trying to decipher something I wrote months ago. You can put as many comments in a script as you like. All you have to do is precede it with the ; symbol. Anything after that will not be compiled and will not affect the function of the script.

Software We Use

Most people use the Construction Set for scripting. That's just fine, but I don't. It doesn't allow you to compile MWSE or MGE functions, and the compiler tends to miss things sometimes (it often won't tell you if you forget to declare a variable.) That is why I require you to write your scripts for this course in MWEdit.

There are many advantages to using MWEdit. It is simple and quick, you don't need to wait for Morrowind.esm to load, just your esp. It has a syntax highlighter, which means that different parts of your script will be displayed in various colors. This becomes incredibly helpful when trying to debug. It has a built-in indenter, which assists in reading a script. And the compiler is much more thorough than the CS.

So get MWEdit (the link is available in the syllabus thread) and install it. These tutorials will all be based around using it as our primary piece of software.

Enchanted Editor is another thing that we will use. It has capabilities that nothing else available does. I won't explain any of that here as the uses are pretty specific. But rest assured that we will need it, and you will find it to be a valuable tool.

Well that's the first lesson and the boring one. But all of that information is vital in being able to write a script.

Until I am able to finish lesson 2, I strongly suggest you take some time to read through any other tutorials you can find. Again I recommend the Scripting Tutorial found in MWSFD. It will take you through many essentials that I only briefly covered here.

Until next time, class dismissed!

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

Why doesn't it say anything here? I thought this was supposed to be "Morrowind Scripting"! Is there something that will be here at a later date? If so, it has been 2 years! Was something here originally & deleted? If so, why? Please answer!

I think there's still some wrinkles with the database since the forum upgrade; some older posts aren't displaying correctly (or at all, for that matter) as a result. DarkRider's aware of it and IPS are looking into it, I think.

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...