This page very likely contains outdated information (last updated in 2005).
|UESP Main Page
Feel free to Contact the Webmaster to contribute any suggestions or content.
The use of scripts in Morrowind's Construction Set allows the plugin creator to perform a large amount of things within the game but, unfortunately, successfully writing scripts can be a difficult chore, even for the experience programmer. Morrowind's scripting is limited and not very powerful compared to some of the scripting available in other games, but with practice you'll find that you can still produce wonderful effects from it (such as a working chess game).
To start a script open the Gameplay-Edit Scripts menu in the Construction Set to open the script window. Select the Script-New... menu to begin a new script and enter something like the following:
begin TestScript01 endThe TestScript01 will become the name of the script and it must be unique (no other script can exist with the same name). To assign a script to an object open the window to edit the object and select your new script in the script dropdown list. You can assign a script to more than one object, though you must design the script properly.
; Remove the sword from the player after 10 days if ( NumDays > 10 ) player->RemoveItem, "my_new_sword_01", 1 endif
begin TestScript02 short DaysPassed long SecondsCalc float PlayerXPos ; etc...Variables declared in this manner are known as local variables and belong to whatever object the script is attached to. You can also create global variables in a similar manner using the Gameplay--Globals... menu in the editor. Note that variables always default to the value of 0 before they are used or defined.
short DaysPassed long SecondsCalc float PlayerXPos set DaysPassed to 0 ; Use a literal value set DaysPassed to ( DayPassed + Day ) ; Simple addition of two variables set SecondsCalc to ( DaysPassed * 86400 ) ; Multiplication of a variable and a number set PlayerXPos to ( player->GetPos, X ) ; Using a function set objectID.varName to 100 ; Setting a variable belong to another object set "object ID".varName to 100 ; Use quotes for object IDs with spaces in themYou can set variables to literal numbers, to other variables (local/global) or perform simple arthimitec (+, - ,* or /). You can also access variables belong to other objects by using the objects name followed by a period and the variable name.
if ( DaysPassed <= 3 ) MessageBox, "Not enough time has passed" elseif ( DaysPassed <= 10 ) MessageBox, "You feel the time approaching" else MessageBox, "The time is NOW!" endifYou can, of course, have more than one line in the if statements and can put if statements within other if statements as well. You can use the tests
short Value set Value to 0 while ( Value < 10 ) MessageBox, "Countdown %D...", Value set Value to ( Value + 1 ) endwhile
MessageBox, "Welcome to scripting..." ; Display a message to the player if ( player->GetPos, X > 100 ) ; Check the player's position if ( "achel"->GetSpell, "ash woe blight" == 1 ) ; Check for a disease on an NPCFor exact use and description of the functions, see the Construction Set help file, the above Functions page, or look at some of the many scripts in the game. Note that sometimes the editor's help file is not exactly correct. Also note that most functions do not accept variables as input, for example:
float XPos set XPos to -10 AiTravel, -10, 1000, 501, 0 ; Literal values work fine AiTravel, XPos, 1000, 501, 0 ; Does NOT work as AiTravel does not accept variables SetPos, X, XPos ; Works because the SetPos function accepts variables (Tribunal required)See the description of the various functions to learn whether they accept variables or not (most functions do not).
if ( SomeValue == 1 ) ; 1, use spaces after/before brackets in if statements AiActivate, ObjectID, 0 ; 2, use commas when calling functions endif "urzul gra-agum"->Enable ; 3, use quotes to surround object IDs containing spaces
This is one of the things which makes scripting in Morrowind so confusing to use, especially for those familiar to real programming languages.
begin TrickChestScript short OpenAttempt ; Check for the player attempting to open the chest. Use the OpenAttempt variable as ; putting all the code into the OnActivate if statement becomes difficult for more ; complex scripts. if ( OnActivate == 1 ) set OpenAttempt to 1 end if ; Stop the script if not trying to open the chest if ( OpenAttempt == 0 ) return endif ; Check the player for the 'secret' key, which is 10 pillows if ( player->GetItemCount, "misc_uni_pillow_01" >= 10 ) Activate ; Open the container normally Set OpenAttempt to 0 MessageBox, "The chest opens mysteriously..." ; The player doesn't have 10 pillows, activate trap else PlaySound3D, "Heavy Armor Hit" ; Play ominous sound Set OpenAttempt to 0 ; Cast trap on player depending on level if ( player->GetLevel < 10 ) Cast, "poisontrap_10", Player elseif ( player->GetLevel < 25 ) Cast, "poisontrap_50", Player elseif ( player->GetLevel < 50 ) Cast, "poisontrap_150", Player else Cast, "poisontrap_250", Player endif endif end
Display this document for printing (some pages may not display properly).
If you have any problems, suggestions or comments on this page or website, please
feel free to use the Contact Form to send
a message to the WebMaster.
This document was last modified on: Saturday, 19 February 2011, at 09:55:40 and has been accessed 12831 times ( /morrow/editor/mw_scripting.shtml ).
Please note that this site is Completely Unofficial and is in no way connected to Bethesda softworks or Zenimax. Bethesda Softworks, Battlespire, XnGine, Morrowind, Redguard, Daggerfall, Arena and The Elder Scrolls are trademarks of Media Technology Limited, Copyright © 1994-2001 Media Technology Limited.