Morrowind Scripting for Dummies 5

download Morrowind Scripting for Dummies 5

of 134

Transcript of Morrowind Scripting for Dummies 5

  • 8/16/2019 Morrowind Scripting for Dummies 5

    1/134

    Morrowind Scripting for

    Dummies(5th Edition)

    A manual for the TES Construction Set Scripting Language by

    GhanBuriGhan

    1

  • 8/16/2019 Morrowind Scripting for Dummies 5

    2/134

    Table of Contents

    Foreord to fifth Edition!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"

     Introduction...............................................................................................................................8

    #sing this guide!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$

    %hat is a script&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$

    %hat can scripts do&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'

    %hat scripts cant do!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'

     Scripting tutorial......................................................................................................................10

    Lets get going*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+

    The scripting indo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+

    %hat do e ant&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11

    %riting a script!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11

     ,aming a script -egin and End!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11

    .etecting an action by the player!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11%riting te/t and obtaining decisions from the player!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!10

    o local scripts are e/ecuted!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!12

    3our first bug!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!14

    utting a spell on the player!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!14

    General Information: Scripts, Commands and Syntax..........................................................20

    Types of scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0+

    Local scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0+

    6lobal scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0+

    Synta/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!01

    -eginning and ending scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!016eneral synta/ for functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!01

    6eneral synta/ Commas7 parantheses and spaces!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!01

    Tabulators!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!00

    8ariables!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!00

    .eclaring 9ariables!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!00

    :eferencing 9ariables in other local scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!02

    #sing 9ariables in functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!02

    ;athematical calculations!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!02

    Testing conditions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0<

    #se of if= elseif conditions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0<

    %hile conditions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!05Constructing -oolean operations in TES Script!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!05

     List of !S"script functions....................................................................................................2# 

    E/planation of the format!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0"

    Scripting NPC's: AI and Movement!"

    ;a>e an ,C al> to a ne location!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0"

    Chec>ing hether an ,C has performed his mo9ement!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0$

    :andom Actor mo9ement!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0'

    Acti9ating ?b@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2+

    Folloing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!21

    Chec>ing hich A pac>age is currently e/ecuted!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!20Forcing snea> mo9ement!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!20

    #e$t and Dia%ogue&&

    0

  • 8/16/2019 Morrowind Scripting for Dummies 5

    3/134

    -rief dialogue hoBto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!22

    The concept of ;% dialogue!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!22

    o dialogue or>s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2<

    A fe golden rules!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!25

    .ialogueBrelated functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!25

    .isplaying messages!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!25

    .isplaying 9ariables and te/t defines in a message bo/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!24

    Adding a dialogue topic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2"

    nitiating and ending dialogue!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2"

    ;ultiple choice as>ing Duestions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2$

    Adding to the @ournal and testing @ournal entries!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2$

    Special dialogueBonly functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2'

    action( )ace and )an*+,

    .etermining the Cs status!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!noc>outs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 8/16/2019 Morrowind Scripting for Dummies 5

    4/134

    :epairing ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5"

    EDuipping an tem eDuip and CS>ipEDuip!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5$

    lacing an item near the C!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5'

    Chec>ing acti9ation of an item and acti9ating it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5'

    Loc>ing and #nloc>ing doors or chests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4+

    Enabling and disabling ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4+.onGt sa9e changes to an ob@ect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!41

    ;o9ing and rotating ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!40

    ;o9ing along an ob@ects a/is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!40

    ;o9ing along the orld a/is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!40

    :otating ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!42

    ositioning an ob@ect in the orld or in an interior cell!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!42

    Cell#pdate!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4<

    Setting position or facing of an ob@ect for each a/is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4<

    :esetting an ob@ect to its original position!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!44

    Animating ?b@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!44

    .etermining location!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4".etermining the players Cell!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4"

    .etermining hen the C lea9es a cell!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4"

    .istance of one ob@ect to another!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4$

    .etermining an ob@ects position and facing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4'

    Line of Sight!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4'

    .etermine hether an Actor is detected by another Actor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+

    Triggers for Actors standing on an ob@ect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"1

    urting an actor standing on an ob@ect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"1

    Changing and testing S*i%%s( Attri-utes( AI and other Stats"!

    6et7 Set7 and ;odify stats!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"0Full list of 6etB7 SetB7 and ;odBHStatI type functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"2

    Attributes!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"2

    ealth7 ;agic>a7 Fatigue!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"2

    S>ills!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"2

    ;agic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"2

    ?ther!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<

    A Settings!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<

    :esurrecting a dead actor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"4

    P%a3er Contro%s".

    layer sleeping!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"4

    Enabling and disabling player control!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""

    .isable control functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""

    Enable control functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"$

    Chec> control status!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"$

    Force first or third person 9ie!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"'

    Functions for character generation menus!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"'

    1eather4,

    Changing eather!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$+

    Changing eather settings for a region!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$+

    .etermining current eather!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$+

    .etecting ind speed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$1

    Misce%%aneous functions and varia-%es45

    .etermining if player has menus open!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$1

  • 8/16/2019 Morrowind Scripting for Dummies 5

    5/134

    Fading the screen in and out!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$1

    Adding a location to the map!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$1

    .etecting if player is indoors or outdoors!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$0

    -rea>ing of script processing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$0

    Assigning random 9alues to 9ariables!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$2

    laying 9ideos!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$2Controlling global scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$2

    New functions that come with #)IB6NA74+

    Changes J fi/es to ;orroind scripting !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$<

    nde/ of ne Tribunal Script Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$<Enable eDuipment sharing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$5

    C Action functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$5

    Scale Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$4

    %ater Le9el Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$"

    Le9itation Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$'

    ?b@ect Creation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'+%orn J eDuipped ?b@ect nformation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'1

     ,C ;o9ement Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'2

    ?b@ect Collision Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'<

    Le9eled List Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'5

    ;iscellaneous Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'4

    SDuare root!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'4

    E/plosion!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'4

    .eleting a reference completely!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'4

    Combat :eadiness Functions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'$

    #ips and tric*s5,,

    Script ith style for safer scripting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1++

    Cleaning up your mod!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1++

    Limits of the Script Editor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+1

    ;a>ing Actors sitch beteen eapons!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+0

    Little helpers!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+2

    Testing for the presence of another ;od!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+2

    Safely starting global scriptsB a9oiding the main script!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+<

    Sa9ing C# time!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+<

    #se sound to detect e9ents!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+5

    Large battles!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+4

    Targeted scripts running KglobalK scripts tied to an ob@ect!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+4A guide to ma>ing ridable ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+"

    Selecting ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+"

    CreatingJ.eleting ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+$

    Falling off from ob@ects!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+'

    Collision detection!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+'

    Sa9egame issue!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1+'

    ;anneDuins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11+

    Cinematic seDuence!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!110

    #rou-%eshooting55&

    6eneral hints!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!112

    The Console!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!112#sing the Console to chec> 9ariables!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!112

    #sing the Console to Duic>ly test scripts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11<

    5

  • 8/16/2019 Morrowind Scripting for Dummies 5

    6/134

  • 8/16/2019 Morrowind Scripting for Dummies 5

    7/134

  • 8/16/2019 Morrowind Scripting for Dummies 5

    8/134

    Introduction

    Using this guide.

    f you are ne to scripting7 you should probably start by reading this introduction and

    especially do the tutorial! t is my best attempt at e/plainining scripts7 hat they do7 and ho

    to program one7 in simple terms!

    Secondly this is a manual7 a reference7 a handboo>! The bul> of this document is a

    documentation of the a9ailable functions! This part is not ritten for the beginner7 you are

    e/pected to >no the basics of scripting allready! ha9e hoe9er tried to pro9ide a lot more

    info7 e/planations and sample scripts than the original helpfile7 to ma>e it easier to use these

    functions correctly in your scripts! #se the inde/ at the end of the document to find info on a

    specific function7 or the table of contents to find functions related to a general area of interest!

    f you run into errors7 the Troubleshooting section may help you a bit! n the Appendi/ you

    find lists that may also come in handy as a reference!

    Thirdly7 as an ad9anced scripter you may also find the Tips and Tric>s section interesting that

    co9ers both basic ad9ice and ad9anced scripting techniDues!

    Finally a ord of ad9ice dont ta>e hats ritten here as gospel! The info in this guide

    represent the best of my >noledge and forum isdom7 but that doesnt mean that there arenGt

    mista>es and o9ersights7 etc! E!g! if rite that a function doesnt ta>e 9ariables as arguments

    it probabl" doesnt but if its important for your mod7 by all means try anyay! t may ha9e

    changed ith a patch or maybe simply nobody chec>ed before! So run a test7 and if you find

    something ne7 let me >no7 and ill add the info in a possible future update!

    What is a script? 

    Scripts are basically pieces of code ritten in a special scripting language ( ill call it TES

    script from here on)! These little KprogramsK ill run during the game and can perform certain

    things in the game7 lots of things actually Trigger e9ents7 control time and place7 ma>e things

    and creatures 9anish7 appear or mo9e7 gi9e messages to the player7 change stats7 e9en change

    the eather the possibilities are great!

    TES Script is a uniDue scripting language7 it is not used outside the TES Construction Set! As

    a scripting language it has certain limitations compared to a KrealK programming language7

    li>e7 e!g! CRR

    1! The scope of TES Script is limited donGt e/pect to be able to program anything that is

    not already in the game in one ay or another hich is not to say you can not

    achie9e ne and unusual things ith scripting* -ut you canGt use TES script to7 say7

     program a ord processor!

    0! TES Script is also not an S. (softare de9elopment >it) that lets you actually or>

    ith and change (parts of) the games source code! ThatGs hy you canGt use TES script

    to7 for e/ample7 add ne eatherBeffects! Those are hardcoded and you ould need to

    change the actual game !e/e to do that!

    2! tGs an interpreted language not a compiled one the code needs a separate program

    (in this case ;orroind) to run unli>e compiled code that could be run by itself7 li>e

    an !e/e application!

    $

  • 8/16/2019 Morrowind Scripting for Dummies 5

    9/134

    What can scripts do? 

    Scripts for ;orroind are a ay to ha9e the game dynamically react to hat the player does

    in the game orld! 3ou can use scripts to manage comple/ Duests! 3ou can use scripts to

    create custom items that perform actions beyond hat regular enchantments could! 3ou can

    use scripts to create traps! 3ou can use scripts to change ,C or creature beha9ior! :emember 

    the character creation in ;orroind& tGs basically controlled by a number of scripts! SeenFargoth snea> around to his stash in Seyda ,een& ThatGs a script directing his mo9es! Freed

    any sla9es& That also is handled by a script! So the short anser to the Duestion is a lot!

    What scripts can't do:

    The TES script language is limited in its capabilities there are only so many functions that

    you can use and sometimes the possible uses are not all that you may ish them to be! n fact

    some functions are buggy or plain bro>en! n many cases smart scripters can find

    or>arounds for apparent limitations7 but dont e/pect miracles! ;any things are hardcoded

    and can not or only indirectly be influenced by scripts!

    '

  • 8/16/2019 Morrowind Scripting for Dummies 5

    10/134

    Scripting tutorialf you are completely ne to scripting and programming in general7 the thought of using TES

    script might be a little daunting ha9e therefore ritten an e/tended tutorial that ill al>

    you through ma>ing your first script! ill also e/plain the main elements of the scripting

    language as e go! There ill be other e/planations on the ay7 but the >ey instructions ill

     be in -o%d print!

    Let's get going! 

    %e start by opening the script editor Start up the #8S Construction Set( open the

    Morrowindesm fi%e and then se%ect 8dit Scripts from the Gamep%a3 menu to open the

    scripting window

    The scripting window 

    3ou enter the script editor either by se%ecting Gamep%a3 9 8dit Scripts from the menu7 by

    clic>ing the edit script button (the pencil) in the tas>bar or by accessing it from an ?b@ect or ,C dialogue7 by clic>ing the button ith the ellipses = ne/t to the script field! The editor

    indo is pretty basic

    1+

  • 8/16/2019 Morrowind Scripting for Dummies 5

    11/134

    Lets ha9e a loo> at the buttons in the tas>bar7 from left to right &pen lets you select a script

    to edit! Sa'e error chec>s the current script and compiles it or gi9es out error messages note7

    hoe9er7 that the plugin and thus the script is not really sa9ed to dis> at this time! %hen

     programming large scripts freDuently use the sa9e command in the main TESCS indo after 

    you ha9e sa9ed the script here7 @ust in case the TESCS crashes!  (orard and #ackard

    arros @ump to the ne/t or pre9ious script7 respecti9ely (alphabetical order)! f you gi9e yourscripts a common tag7 that ill ma>e it easier to @ump beteen the different scripts of your

     pro@ect7 e!g! start e9ery script name ith AAQScriptname this ill put them right at the

     beginning of the list and >eep them neatly together! Compile all  recompiles all scripts (hats

    this good for& dont really >no)! Finally7 the delete button deletes a script and the last

    Karro donK button closes the script indo!

    The help menu gi9es Duic> access to the function and command pages of the helpfile (of

    moderate utility7 hence the creation of this manual*)

    3ou can copy and paste into the editor indo by using the indos standards ctrlBc for

    copy7 ctrlB/ for cut and ctrlB9 for paste!

    What do we want? -efore e really start riting our tutorial script e should decide hat e ant it to do! For

    this tutorial decided e are going to ma>e a )idd%e Chest: #he chest wi%% as* a ridd%e and

    on%3 the right answer wi%% open the chest If the p%a3er provides the wrong answer( a trap

    wi%% go off( hurting the p%a3er( and the chest can't -e opened

    ThatGs a fairly comple/ underta>ing7 but e ill ta>e it step by step!

    Writing a script 

    ?>7 once you9e got the Edit Script indo open7 c%ic* into the main part of the window 

    That is here you ill rite your script!

    Naming a script: Begin and End

    First of all e must gi9e our script a name e9ery script must start ith the declaration of this

    name! So p%ease t3pe:

    Begin my_first_script

    into the editor window! ,ote the underscores 3our name should be one ord! Also note that

    the script language is not case sensiti9e7 so begin could also be ritten ithout the capital

    letter! This name is the handle by hich the script ill be >non in the TESCS! Try hitting the

    sa9e button no you ill get an error message about Kyou need to end your script ith end

    scriptname!So7 for the editor to recogniOe the script e also need to indicate an end ne$t( write 

    End

    in a new %ine -e%ow the a-ove! As you see e can omit putting the name of the script in this

    line again7 @ust end  ill do! %hen you hit safe no7 you ill see the name appear in the title

     bar of the script editor7 indicating that the script has been accepted! This is the shortest script

     possible B and of course it doesnGt do anything at all!

    Detecting an action by the player 

     ,e/t7 e need a ay to determine hether the player tries to open the chest! n TES Script edistinguish beteen ?b@ects7 Functions and Commands

    11

  • 8/16/2019 Morrowind Scripting for Dummies 5

    12/134

  • 8/16/2019 Morrowind Scripting for Dummies 5

    13/134

    9ariables! ;ost of the problems that beginners encounter ith scripting for ;orroind ha9e

    their roots in misunderstanding ho the scripts are actually e/ecuted and ho scripts should

    accordingly be structured! So lets ha9e a loo> at this!

    ow local scripts are executed

    E9ery script that is attached to an ?b@ect or an ,C (local script) is e/ecuted e'er" frame the game displa"s on screen hile the cell ith the ob@ect is acti9e (indoors only the cell the ,C

    is currently in is acti9e7 outdoors the CGs cell and all ad@acent cells are acti9e)! So the

    complete script  (not @ust one line of it) is e/ecuted 1+B4+ times a second or hoe9er fast your

    computer runs the game* t is best to imagine e9ery local script rapped in a big HhileB

    loopI

    while (O&*ect is in active +ell)

    ,-o%r script code.

    endwhile

    This is the reason hy the folloing script spits out a continuous stream of messages (ifattached to an ?b@ect or ,C in the same cell as the player)! Try it7 if you ant

    This e/ample is relati9ely harmless7 but imagine hat happens if you ould use a line of code

    that adds an item to the players in9entory7 or places a monster ne/t to him7 etc!*

    For this reason7 H.o ?nceI constructions are 9ery essential and something you ill probablyuse a lot hile scripting for ;orroind! So7 lets go on ith our tutorial script e need to

    declare a 9ariable and use it to ma>e sure the message is only displayed once! Change the

    script to the fo%%owing:

    Begin my_first_script

    /hort controlvar

    If ( OnActivate == 1 )If ( controlvar == 0)

    essageBo! "#oiceless it cries$ wingless fl%tters$ toothless &ites$ mo%thlessm%tters' hat is it"$ "Bat"$ "Old woman"$ "ind"$ "raith"

    /et controlvar to 1

    endifendif

    End

    ;P%ease note that the MessageBo$ command shou%d -e in one %ine in the editorno that this is 9ariable that ill contain integers (hole positi9e or

    negati9e numbers)! A 9ariable is a KplaceholderK that can ta>e on different 9alues! The if  

    command e already >no7 the set  command is ne7 but simple enough it sets our 9ariable

    that had the 9alue + before (all 9ariables start out at Oero hen declared) to 1! This7 in

    connection ith the if ) control'ar ** + command pro9ides a doBonce condition the ne/tframe the script is e/ecuted after the 9ariable as set to 1 the if condition ill be false and the

    message bo/ ill not be displayed again!

    Begin essage_script

    essageBo! 2ho%sands of %seless essages3

    End essage_script

    12

  • 8/16/2019 Morrowind Scripting for Dummies 5

    14/134

     ,o our script is already capable of being run7 so lets test it

    • Save the script and c%ose the script editor window

    • Go to the #8S construction set( -2ect window( se%ect the container ta- and open

    >chest?sma%%?,5>

    • Change the ID of the chest to >tutoria%?chest>

    • In the script dropdown fie%d( se%ect m3?first?script

    • Save the o-2ect as a new o-2ect( save the mod( and @uit the construction set Start

    Morrowind and %oad a savegame

    • Now -ring down the conso%e ;usua%%3 the *e3( or whatever 3ou have to the %eft

    of the >5> on the main *e3-oard= and in the conso%e window( t3pe:  

    laceAtC tutorialQchest 17171

    and hit return

    Ta>e a step bac> (err7 let your player character step bac>7 that is*)P you should no ha9e a

    little chest sitting on the floor right in front of you! Clic>ing on it should bring up our

    message7 hich should loo> li>e this

    Clic>ing on those buttons ill @ust close the messagebo/ for the moment7 and clic>ing on the

    chest again7 nothing should happen either hich is good7 it means our doBonce condition

    or>s!

    *( %eave Morrowind and go -ac* to the editor( and %oad 3our p%ugin again

    %e no need to figure out hich anser the player selects7 and script appropriate reactions

    for right and rong ansers! The function to test the selected anser is

    K4etB%tton5ressedK! This function returns a number depending on hich of the buttons of a

    message bo/ has been clic>ed on ith the mouse! t ill return K+K for the first button (KbatK

    in our e/ample) and 17 07 2 etc! for the folloing buttons7 in the order you listed them in the

    messagebo/ function! %hile no anser has been selected7 the function ill return 17 so e

    ha9e to ta>e care of that7 too!The KActivateK function ill ma>e our chest open7 in fact acti9ate ill simply trigger the

    standard action that ould usually be performed hen you KuseK the selected ob@ect e!g!

    doors ould sing open7 ,Cs ould initiate dialogue etc!

    The folloing update to our script also demonstrates ho you can use a control 9ariable to

    force ;% to process functions one after the other7 although the complete script is processed

    e9ery frame of the game simply increment the control 9ariable and test it in a series of if

    elseif statements! This is a 9ery safe ay of scripting for ;% it may not alays be

    necessary7 but its safe!

    1

  • 8/16/2019 Morrowind Scripting for Dummies 5

    15/134

    P%ease edit the script to the fo%%owing:

    Begin my_first_script

    /hort controlvar/hort &%tton

    If ( OnActivate == 1 )If ( controlvar == 0)

    essageBo! "#oiceless it cries$ wingless fl%tters$ toothless &ites$ mo%thless m%tters'hat is it"$ "Bat"$ "Old woman"$ "ind"$ "raith"

    /et controlvar to 1elseif controlvar 6 1

    activateendifendif

    if (controlvar == 1)set &%tton to 4etB%tton5ressedif ( &%tton == 71 )

    ret%rnelseif ( &%tton == 8)

    essageBo! "2he answer was correct"

    Activateset controlvar to 8else

    essageBo! "2he answer was wrong"set controlvar to 71

    endifendif

    End

     

    Ta>e a loo> at the part that starts ith Kif )control'ar ** -K! %e ha9e set control9ar to 1 as

    soon as the chest got acti9ated! ,o e test for hich button is being pressed! %e do this by

    assigning the ne 9ariable KbuttonK a 9alue returned by .et#utton/ressed ! Since the script is

    still running7 e9en hile the game seemingly pauses to aait your decision7 e first test if no

     button has been selected yet return tells the game engine to stop processing the script for

    this frame!

    ?ur correct anser as KindK hich corresponds to button number to if button number

    to gets pressed7 e ill tell the player that he ga9e the right anser7 and Kacti9ateK ill open

    the chests in9entory in the usual ay!

    All other 9alues of button mean that the player has selected a rong anser7 so e can use the

    KelseK command here! n this case e tell the player hat a fool he as and the chest is not

    acti9ated!

     ,o loo> at the little addition at the top of the script

    If ( OnActivate == 1 )

    If ( controlvar == 0)essageBo! "#oiceless it cries$ wingless fl%tters$ toothless &ites$ mo%thless m%tters'

    hat is it"$ "Bat"$ "Old woman"$ "ind"$ "raith"/et controlvar to 1

    elseif controlvar 6= 1activate

    endifendif

    This means that7 hene9er the chest is acti9ated in the future7 it ill only open if control9ar is

    greater than 1! Chec> abo9e hen the player pro9ides the rong anser in the riddle7

    control9ar is set to 17 so he ill ne9er be able to open the chest! -ut if he >ne the right

    anser7 control'ar  is set to 07 and from no on the player can open the chest as often as he

    li>es! Sa9e and run your plugin7 and test as described abo9e!

    15

  • 8/16/2019 Morrowind Scripting for Dummies 5

    16/134

     !our first bug

     ,o7 you ill probably ha9e noticed that the script does almost but not Duite hat e

    anted! After clic>ing the correct anser7 the chests in9entory doesnGt open as intended! ,o7

    the logic abo9e seemed fine7 so hat is rong& 7et's tr3 the fo%%owing ;change the

    corresponding part of 3our script according to the fragment -e%ow=:

    if (controlvar == 1)set &%tton to 4etB%tton5ressedif ( &%tton == 71 )

    ret%rnelseif ( &%tton == 8 )

    essageBo! "2he answer was correct"set controlvar to 8

    elseessageBo! "2he answer was wrong"set controlvar to 71

    endifelseif ( controlvar == 8 )

    Activateendif

    See ho mo9ed the acti9ate command to the section that tests for control9ar VV 0& This pro9ides a cleaner seDuence of e9ents7 and as mentioned abo9e7 this can be 9ery important

    hen scripting for ;orroind alays try to a9oid doing too many things at once* 1e%%( run

    and test it 

    6reat7 no the in9entory opens as e anted7 but hat is this& The cursor is real slo7 and

    e cant close the in9entory* Loo> abo9e control'ar  as set to to7 and remains there7 e

    do not change it again therefore the game no gets continuous K Acti'ateK commands each

    time the script is processed (e9ery frame)* ThatGs hy e cant close the in9entory it gets

    reopened immediately! So change the fo%%owing part of the script:

    elseif ( controlvar == 8 )Activate

    /et controlvar to 9endif

    #est again no e9erything or>s the ay e anted! hope ha9e not confused you ith

    the abo9e e/cursion into the process of debugging7 but it is a 9ery important thing to >no

    about you ill constantly ha9e to rethin> your scripts and try different ays of doing it to be

    successful!

    %hat is still missing& The trap effect of course*

    "utting a spell on the player 

    ?ur chest ill put a curse on the player if he fails to anser the riddle!irst go to the spe%%ma*ing ta- in the editor( right c%ic* and se%ect >new> Give the spe%%

    the ID >rost?Curse>( name it >rost Curse> and ma*e it t3pe >curse> then give it a

    magnitude of eg 5/ It shou%d %oo* %i*e in the picture -e%ow

    14

  • 8/16/2019 Morrowind Scripting for Dummies 5

    17/134

     ,o7 e need to put this curse on the player! For this e use the AddSpell  function! After

    some time e ill remo9e the curse again using the 0emo'eSpell  function7 for this e need toma>e a timer! Edit your script again

    Begin my_first_script

    /hort controlvar/hort &%tton:loat timer

    If ( OnActivate == 1 )If ( controlvar == 0)

    essageBo! "#oiceless it cries$ wingless fl%tters$ toothless &ites$ mo%thless m%tters'hat is it"$ "Bat"$ "Old woman"$ "ind"$ "raith"

    /et controlvar to 1elseif controlvar 6 1

    activateendifendif

    if (controlvar == 1)set &%tton to 4etB%tton5ressedif ( &%tton == 71 )

    ret%rnelseif ( &%tton == 8)

    essageBo! "2he answer was correct"Activateset controlvar to 8

    elseessageBo! "2he answer was wrong"5layer 76 Add/pell$ ":rost_+%rse"set controlvar to 1

    Endifelseif ( controlvar == 8 )

    Activate/et controlvar to 9

    1"

  • 8/16/2019 Morrowind Scripting for Dummies 5

    18/134

    elseif ( controlvar == 71 )/et timer to ( timer < 4et/econds5assed )if timer 6 10

    5layer 76 emove/pell$ ":rost_+%rse"set controlvar to 78

    endifendif

    End 

    Lets go o9er this! layer BU AddSpell7 KFrostQCurseK puts the curse e created earlier on the player!

     ,ote ho e need to use Klayer BU K to ma>e sure the effect really targets the player!

    ?therise e ould curse the chest (hich is the default ob@ect7 because the script is attached

    to it)7 hich ouldnGt ma>e a lot of sense=

    This bit

    :loat timer/et timer to ( timer < 4et/econds5assed )

    if timer 6 10

    =that is ho you ma>e a timer in ;orroind! .etSeconds/assed  is a function that returnsthe time in seconds that has passed since the last frame! Since this is usually a fraction of a

    second (as the script gets called e9ery frame)7 it is only natural that e need a float 9ariable

    for this purpose a 9ariable that can store numbers ith decimals! So hen the timer has

     been running for 1+ seconds e remo9e the curse again7 and ma>e sure e do this only once5layer 76 emove/pell$ ":rost_+%rse"set controlvar to 8

    ?>7 sa9e and test your mod! %or>s fine no7 doesnGt it& %ell7 almost! Try the folloing let

    yourself be cursed7 and then open your in9entory! %ait! See ho the curse terminates after

    some time7 ithout hurting you& ?f course the script is still running7 but spell effects are only

    calculated hile in game7 not hile you are in the menu! %e donGt ant the player to get off

    the hoo> so easily7 so e need to put something in our script that stops it from processing

    hen e are in menu mode! Luc>ily there is the MenuMode function7 hich returns 1 hen

    you enter the menu! So e can put this at the start of our script

    If ( en%ode == 1 )et%rn

    Endif

    :emember7 return tells the game to stop processing the script for this frame! ?>7 no e ha9e

    our final or>ing script! Congratulations* f you ant7 e/periment a little more ith this

    script! ut the chest into a location in the game and loc> it! Then try unloc>ing it (>nloc? 

    function)ith the script in addition to acti9ating it! Try adding a sound7 hen the riddle is

    successfully sol9ed (e!g! 5lay/o%nd9@$ "s?illraise")! Try using the +ast function instead

    of K AddSpell K

    1$

  • 8/16/2019 Morrowind Scripting for Dummies 5

    19/134

    This is the final script

    Begin my_first_script

    /hort controlvar/hort &%tton:loat timer

    If ( en%ode == 1 )et%rn

    Endif

    If ( OnActivate == 1 )If ( controlvar == 0 )

    essageBo! "#oiceless it cries$ wingless fl%tters$ toothless &ites$ mo%thless m%tters'hat is it"$ "Bat"$ "Old woman"$ "ind"$ "raith"

    /et controlvar to 1elseif controlvar 6 1

    activateendifendif

    if ( controlvar == 1 )

    set &%tton to 4etB%tton5ressedif ( &%tton == 71 )ret%rn

    elseif ( &%tton == 8 )essageBo! "2he answer was correct"Activateset controlvar to 8

    elseessageBo! "2he answer was wrong"5layer 76 Add/pell$ ":rost_+%rse"set controlvar to 1

    Endifelseif ( controlvar == 8 )

    Activate/et controlvar to 9

    elseif ( controlvar == 71 )/et timer to ( timer < 4et/econds5assed )if timer 6 10

    5layer 76 emove/pell$ ":rost_+%rse"set controlvar to 78

    endifendif

    End

    1'

  • 8/16/2019 Morrowind Scripting for Dummies 5

    20/134

  • 8/16/2019 Morrowind Scripting for Dummies 5

    21/134

    Syntax 

    There are some uniDue features in TES script that should be e/plained before e go into more

    detail!

    Beginning and ending scriptsBegin /cript_I@EndEnd /cript_I@

    E9ery script must ha9e the -egin and End tags! The specified name ill also be the . you

    ill reference the script by (be it from other scripts or inside the TES CS ob@ect indos)! A

    script may start out ith comments7 but the first line of real code must be K-egin /////////K!

    #eneral syntax for functions:"O&*ect_I@" 76 :%nction$ ,parameters.

    This KarroK or Kfi/K designates hich ob@ect a function ill be performed on! The

    [email protected] is the uniDue . that is gi9en to each ob@ect in the editor (usually the first field in

    any ob@ect indo)! 3ou need this .7 not the ,ame* f you call a function ithout a

    designated [email protected] the function ill be performed on the default ob@ect7 hich is the ob@ect

    the script is attached to!

    This is not to say that there might not be another ob@ect referenced as a parameter

    [email protected] BU Function7 [email protected]

    Functions are not case sensiti9e7 but using the case sensiti9e form as suggested by -ethesda

    (e!g! 6etSpellEffects instead of getspelleffects) ma>es scripts easier to read7 so itGs

    recommended to >eep it that ay!

    #eneral syntax: %ommas$ parantheses and spaces

    TES Script is not too pic>y about synta/! Case mostly doesnGt matter7 commas can be left out7

    and spaces are mostly ignored! ,e9ertheless ould ad9ise adhering to the folloing

     principles

    • #se commas beteen parameters

    • f the . contains a space7 you must use Duotation mar>s K?b@ect .K better to a9oid

    spaces altogether ?b@ectQ.

    • 6et used to a%wa3s Lea9e a space after parantheses and operators7 sometimes it seems

    to cause problems if you dont if ( 9ariable VV 1 )7 not if (9ariableVV1)

    [email protected] BU Function7 ?b@ectQd07 not [email protected][email protected]

    %hile this doesnGt matter most of the time it generates eird and almost untraceable

    errors sometimes7 so you are much better off to get used to alays lea9ing a space!

    01

  • 8/16/2019 Morrowind Scripting for Dummies 5

    22/134

    'abulators

    For your on sa>e7 use tabs for ifBelseif constructs ma>es it much easier to >eep trac> of

    them7 so you donGt forget an endif at the end!

    If ( varia&le1 )If ( varia&le8 )

    ,do something.endif

    endif

    is better thanIf ( varia&le1 )If ( varia&le8 ),do something.endifendif

    Variabes

    Declaring (ariables

    There are three types of 9ariables in the TES script language short7 long and float! According

    to the manual these co9er the folloing data ranges

    Short B207"4$ to 207"4" (signed integer)

    Long B071

  • 8/16/2019 Morrowind Scripting for Dummies 5

    23/134

    )eferencing (ariables in other local scripts

    f a uniDue ob@ect has a local script running on it you can change 9ariables from outside the

    script in the folloing ay

    /et yO&*ect'varia&le to 100

    or /et yO&*ect'varia&le to local_varia&le

    This method changes a local 9ariable in the ob@ectGs script! The ob@ect must ha9e a script on it

    for this to be 9alid! ,ote The scripting system loo>s at the first ob@ect in the database7 thus

    you should only reference ob@ects that are uniDue (e/ist only once)!

     ,ote that the re9erse does not or>

    /et local_varia&le to yO&*ect'varia&le

    #se a global 9ariable to transfer information in this ay7 or set localQ9ariable from the other 

    script using the synta/ abo9e!

    if ( anothero&*ect'! 6 0 )

    apparently or>s!

    *sing (ariables in functions

    #nfortunately it is one of the limitations of TES script that only certain functions accept

    9ariables as parameters7 hich poses some definite limits! This is indicated in the list of

    functions belo! For e/ample the osition and ositionCell commands do not accept

    9ariables7 so teleporting or>s only to predefined locations!

    Note: For some functions here both a 6etBFunction and a SetBFunction e/ist7 a or>around

    can be constructed by using the hile function (see belo)!

    +athematical calculations

    3ou can use the standard operands in set commands (and probably other places7 but ne9er

    tried) to do calculations in scripts

    Addition R

    Subtraction B

    ;ultiplication W

    .i9ision J

    The synta/ is as follos

    /et res%lt_var to (var_a < var_&)

    nstead of 9ariables7 literal 9alues are also alloed! assume that standard mathematical rules

    are applied! 3ou can also use parantheses according to standard mathematical rules

    set ln to ( ln < ( ?10 H math_ln10 ) < ( ?8 H math_ln8 ) )

    A arning there appears to be an issue ith 9ery long additions (e!g! adding up more than 0+

    9ariables in one line of code) that causes a mod to crash the game upon loading! f this

    happens7 split the calculations to se9eral lines!

    02

  • 8/16/2019 Morrowind Scripting for Dummies 5

    24/134

    There isnt much in the ay of dedicated mathematical functions in ;% script! There is the

    :andom function and Tribunal added the 6etSDuare:oot function (see belo)! f you need

    more comple/ functions7 suggest donloading Soralis ;ath ;od (a9ailable from

    ;orroind Summit)! tGs a collection of scripts that allo you to do comple/ calculations!

    ere is a short e/cerpt from the readme to gi9e you an idea

    1This mod adds the abilit" to use 'arious math functions ithin Morroind2s scripts!

    Specificall", these are the scripts that are added:1 

     ,ame Chec>J.one nputs ?utputs Accuracy;athScripts ,JA ,JA ,JA ,JA

    ;athConstants ,JA ,JA ,JA ,JA

    SDuare:oot 1 mathQsDrt mathQresult7 mathQimag "

    SineScript 0 mathQangle mathQsin7 mathQcos7 mathQtan "

    ArcsineScript 2 mathQarc mathQsin7 mathQcos 4B"

     ,aturalLog < mathQlog mathQresult7 mathQimag

  • 8/16/2019 Morrowind Scripting for Dummies 5

    25/134

    3ou can also use else and elseif! Elseif tests for a separate condition hile else ill be

    e/ecuted if none of the pre9ious conditions are trueIf ( foo_var == 1 )

    ,do something.elseif ( foo_var == 8 )

    ,do something else.else

    ,do something completely different.endif

    n my e/perience it is safest to use elseif  instead of multiple separate if  statements if you test

    different states of one 9ariable!

    There is a ma/imum of the total if4elseif  conditions that can be processed in one script! am

    not sure but thin> itGs around 054 conditions!

    While conditionshile ( condition ); things to doEndhile

    The hile command differs from the if command in that it is repeated ithin one frame until

    the condition is fulfilled! This is best e/plained ith an e/ample/hort desiredAmnt

    /et/trength 0 while( 4et/trength L desiredAmnt ) ; non7literal val%e to match  mod/trength 1endwhile

    This ill set strength to the 9alue in 9ariable desiredAmnt after one frame! The folloing

    script hoe9er ould need an undetermined amount of frames to do this7 because the if

    condition is only called once each frame

    if(get/trength L desiredAmnt) ; non7literal val%e to match  mod/trength 1endif

    ?n the other hand the first e/ample can potentially cause KfreeOingK (if the 9alue ould be

    9ery high) hile the second ont!

    Note that this is a wor*around for some functions to the pro-%em of functions not

    accepting non%itera% va%ues ;varia-%es= as arguments

    %onstructing Boolean operations in 'ES Script

    #nfortunately there are no -oolean operators (A,.7 ?:7 ,?T7 X?:7 =) in the scriptinglanguage! Thus you need to construct these yourself using if= elseif structures!

    nstead of A,.if ( varia&le1 AD@ varia&le8 ); does not e!ist

    ,do something.endif

     you ha9e to useIf ( varia&le1 )

    If ( varia&le8 ),do something.

    endifendif

    05

  • 8/16/2019 Morrowind Scripting for Dummies 5

    26/134

    For ?: constructs

    you can use elseif constructions 

    if ( varia&le1 O varia&le8 ),do this.

    endif

    If ( varia&le1 ),do this.

    elseif ( varia&le8 ),do this.

    endif

    04

  • 8/16/2019 Morrowind Scripting for Dummies 5

    27/134

    &ist of 'ES-script functions

    Explanation of the format:

    First ill list the function and the arguments it ta>es

    +ode "string"$ var_en%m$ var_float$ ,optional. (ret%rns short)

    Arguments of the function KstringK indicates a literal string7 such as an ob@ect .! 8arQenum

    indicates a literal 9alue (no 9ariables ta>en) 9arQfloat indicates a 9ariable of the specified type

    (in this case float)! -rac>ets indicate optional parameters! (returns short) or (returns float)

    indicate that the function returns a 9alue and of hat type the 9alue is! ill use the

    designation (returns -ooleanJshort) to indicate a function that returns either 1 or + (a -oolean

    9ariable although its strictly spea>ing still a float)

    E/amples of usage follo in italics and are indented

    Code "ID", var_enum, var_float

    E/ample scripts are set in frames

    Begin script

    ,/cript f%nctions.

    End script

    Scripting N"%.s: /I and +o(ement

    a"e an #$% wa" to a new ocation

    Ai2ravel$ float_en%m_!$ float_en%m_y$ float_en%m_M$ ,reset.

    To ma>e an ,C al> beteen different defined places in the game orld you use the

    ATra9el function!

    The 9ariables /7 y7 O are orld coordinates! 3ou can determine these by mo9ing your camera

    to the desired endpoint of the mo9ement or by selecting a path grid point or an ob@ect nearby

    coordinates are displayed belo the ob@ect indo! The usage of the optional reset flag is

    un>non!

    %hen using this function in scripts it is important to pro9ide conditions here the A pac>ageis called only once! Consider the folloing ,C bound script

    0"

    Begin 2ravel

    Ai2ravel$ 19C$ 8N00$ 10

    End 2ravel

  • 8/16/2019 Morrowind Scripting for Dummies 5

    28/134

    The pre9ious script ill not or>7 as the script HfiresI continuously7 and the effect is that the

     ,C freeOes and ne9er performs the desired mo9ement!

    This should or>P the ,C ill ander to the designated coordinates as soon as his script

     becomes acti9e7 meaning as soon as his cell is loaded!

    %hec0ing whether an N"% has performed his mo(ement4etAI5ac?age@one (ret%rns BooleanGshort)

    if ( GetAIPackageDone == 1 )[do omet!ing

    endif 

    To chec> hether an ,C has arri9ed at his location you can use the .etAI/ackageDone 

    function! This function returns 1 for one frame hen the current A pac>age has finished!

    #se this to perform a chec> hether a mo9ement has been finished! The folloing script is an

    e/ample of ho to lin> se9eral AITra'el  commands ithin one script7 using a state 9ariable

    and an if4elseif  structure

    Begin 2ravelFoop

    short statefloat timer

    if ( men%mode == 1 ) ; if men% is open donPt processret%rn

    endif

    ;start wal?ingif ( state == 0 )

    if ( player 76 4et@istance QB_adros_darani L 000 )set state to

    endif

    ;HHHHHHHHHHHHHHHHHHH Qe &egins his tripelseif ( state == )

    /etQello 0 AITravel 71$ 71C0C$ N8 ;new co7ords point 1set state to 10

    elseif ( state == 10 )

    if ( GetAIPackageDone == 1 ) ;hePs reached point 1set state to 0

    endif

    elseif ( /tate == 0 )

     AITravel 7C1N$ 71CC$ N80 ; new co7ords point 8

    set /tate to 0

    elseif ( state == 0 )

    0$

    Begin 2ravel/hort do_once

    If (do_once==0)Ai2ravel$ 19C$ 8N00$ 10/et do_once to 1

    endif

    End 2ravel

  • 8/16/2019 Morrowind Scripting for Dummies 5

    29/134

    if ( GetAIPackageDone == 1 ) ;hePs reached the point 8set state to R0

    endif

    elseif ( state == R0 ) AITravel 71$ 71C0C$ N8 ;new co7ords point 1set state to N0

    elseif ( state == N0 )

    if ( GetAIPackageDone == 1 ) ;hePs reached point 1set state to 0

    endif

    elseif ( state == 0 ) AITravel 7RR0$ 71CR$ 100 ;new co7ords point 0set state to C0

    elseif ( state == C0 )if ( GetAIPackageDone == 1 ) ;hePs reached point 0

    set state to 0endif

    endif

    End 2ravelFoop

    6ood e/amples of scripting using AITra'el  are also found in the Hloo>outscriptI (Fargoth

    hiding his treasure) and the Char6en%al>,C script (The guard that al>s you through the

    ship at the beginning of the game)! ?r loo> at my KTra9eling ;erchantsK plugin for true

    ATra9el madness *

    f you plan on using this function e/tensi9ely you should be aare of the folloing problems

    %hen you lea9e a cell ith an actor that is @ust performing its ATra9el command7 or if you

    rest7 the script ill ne9er detect the .etAI/ackageDone signal7 meaning your ,C gets stuc>

    on its path once you return or finish sleeping! The folloing simple code can be used to get

    the script going again (this is for the abo9e script)

    ; HHHHHHHHHHHHHHH /talled /cript resc%e 7 recovers script after leaving a cell or restingIf ( 5layer 76 4et@istance$ QB_adros_darani L 000 )

    if (4et+%rrentAI5ac?age == 71) ; chec? for idlenessset timeo%t to ( timeo%t < 4et/econds5assed )if ( timeo%t 6= 9) ; wait some time'

    ; /hort instances of idleness always occ%rset state to (state 7 10) ; stall will occ%r at; AI5Ac?age@one 7 *%mp to "wander" again'set timeo%t to 0

    endifelse

    set timeo%t to 0endif

    endif

    &ando (ctor o)eent Aiander$ range_en%m$ d%ration_en%m$ time_en%m$ ,idle8.$ ,idle9.$ ,idleC.$ ,reset.

    "Actor_ID" #$ AI%ander, &1', &, , ,',,,1,,,

    This is the random mo9ement algorithm that most of the ,Cs in the game are using! The

     ,C tra9els along the A grid7 changes direction randomly7 and performs idle mo9ements in

     beteen!

    • angeJ determines the distance the Actor or creature ill roam from his origin!

    •@%ration probably the time (in hours) the mob ill perform the pac>age (before it isreset7 hich seems to happen if you lea9e or sleep7 not sure&)

    • time presumably determines the start time for the pac>age if it has a duration

    0'

  • 8/16/2019 Morrowind Scripting for Dummies 5

    30/134

    • ,idle8.$ ,idleC.J chances of idle mo9ements!

    The dles are

    dle0 Loo>ing around

    dle2 Loo>ing behind

    dle

  • 8/16/2019 Morrowind Scripting for Dummies 5

    31/134

    essageBo! "@one"AIander 90$ $ 0$ 0$80$0$0$10$90$0$0set doonce to 8

    endifendif

    end

    Begin 22_pic?maceshort doonceshort AI/tateif ( doonce == 0 )

    if ( 4et@istance$ 5layer L 00 )AIActivate 22_daedric_maceset doonce to 1

    endifelseif ( doonce == 1 )

    set AI/tate to 4et+%rrentAI5ac?ageessageBo! "5ac?age = Sg"$ AI/tateif ( 4etItem+o%nt$ 22_daedric_mace 6= 1 ); when D5+ has the mace in his inventory

    essageBo! "@one"

    AIander 18$ $ 0$ 0$80$0$0$10$90$0$0set doonce to 8

    endifendif

    end

    Begin 22_openloaddoorshort doonceshort AI/tate

    if ( doonce == 0 )if ( 4et@istance$ 5layer L 00 )

    AIActivate 22_doorset doonce to 1

    endifelseif ( doonce == 1 )

    set AI/tate to 4et+%rrentAI5ac?ageessageBo! "5ac?age = Sg"$ AI/tateif ( 4et5os$ y 6 8000 ); loaddor target was in same cell for this script';Other conditions li?e 4et5++ell co%ld &e %sed as well'

    essageBo! "@one"AIander 90$ $ 0$ 0$80$0$0$10$90$0$0set doonce to 8

    endifendif

    end

    ,oowing Ai:ollow$ "Actor I@"$ d%ration_f_en%m$ !_f_en%m$ y_f_en%m$ M_f_en%m$ ,reset.Ai:ollow+ell$ "Actor I@"$ "+ell I@"$ d%ration_f_en%m$ !__f_en%m$ y_f_en%m$ M_f_en%m$ ,reset.

    "*o+ID" #$ AIollo-, "*o+'ID", ,,,

    The KFolloK ABpac>ages ma>es an Actor closely follo another! 3ou can use this to ma>e

    an ,C or creature follo the player7 but you can also use it to ma>e ,Cs and creatures

    form a cara9an! The folloing e/cerpt from one of my on scripts shos the unconditional

    use of the functionelseif ( state == 80 )

    QB_g%ar_pac?_adros_ 76 AI:ollow$ QB_adros_darani$ 0$ 0$ 0$ 0AI2ravel 71$ 71C0C$ N8 ;new coords point 1set state to 90

    21

  • 8/16/2019 Morrowind Scripting for Dummies 5

    32/134

    since there is no duration or destination location gi9en7 the guar ill follo the ,C until

    another command is gi9en! As ith other ABcommands7 ma>e sure you set conditions so that

    each AFollo command is issued only once7 not each time the script is e/ecuted e9ery frame!

    The duration7 Cell. and /7 y7 O destination coordinates set conditions that once fulfilled ill

    terminate the Aac>age (hich you can test ith the 6etAac>age.one function as

    describe for ATra9el abo9e)! The AiFolloCell function allos you to set an interior cell asthe destination!

    The meaning of the optional reset option is currently un>non!

    AIEscort$ "Actor I@"$ d%ration$ !$ y$ M$ ,reset.AIEscort+ell$ "Actor I@"$ "+ell I@"$ d%ration$ !$ y$ M$ ,reset.

    To my >noledge this function performs e/actly li>e AFollo! f there is a difference ha9e

    yet to learn about it!

    %hec"ing which (- pac"age is currenty executed 

    For comple/ Actor scripting it might be 9aluable to >no hich A mode is currently acti9eand ma>e script actions dependant on it!

    4et+%rrentAI5ac?age (ret%rns short)

    If ( 4et+%rrentAI5ac?age == 8 ),do something.

    endif

    The returned 9alues are

     ,one B1

    %ander +

    Tra9el 1

    Escort 0Follo 2

    Acti9ate <

    ursue 5

    ,orcing snea" o)eent :orce/nea?+lear:orce/nea?4et:orce/nea? ( ret%rns BooleanGshort)

    The (orceSneak  command puts the actor in snea> mode7 all mo9ement ill be performed insnea>ing! Clear(orceSneak  terminates (orceSneak  mode! #nfortunately there does not seem

    to be a corresponding command to force running (added ith Tribunal)! .et(orceSneak  

    returns one if (orceSneak  mode is acti9e on the calling actor! Chec> the Loo>outScript script

    for an e/ample! eres a snippet

    elseif ( wal?state == 8 ):argoth76:orce/nea? ; enter snea? mode:argoth76Ai2ravel 711R'C$7N111'91$1N9'N8 ;goes to treeset wal?state to 9

    elseif ( wal?state == 9 )if ( :argoth764etAi5ac?age@one == 1 )

    ;:argoth76E%ip "torch_infinite_time_%ni%e"

    set wal?state to ;essageBo! "/QO>F@ BE A2 2EE"

    endif

    20

  • 8/16/2019 Morrowind Scripting for Dummies 5

    33/134

    elseif ( wal?state == )

    set timer to timer < 4et/econds5assed

    :argoth76+lear:orce/nea? ; terminate snea? mode:argoth76Aiander 0 0 0 0 0 0 0 0 0

    if ( timer 6 9 ):argoth76:orce/nea? ; reenter snea? mode:argoth76Ai2ravel 71110'C0$7N80N'1$199'R ;goes to wallset wal?state to

    endif

    'ext and Dialogue;any of the folloing functions are not only used in scripts7 but also in the result field of the

    dialogue editor indo! .ialogue is an art in itself that can not be fully co9ered here7 but

    ill gi9e a 9ery brief introduction!

    rief diaogue how/to

    'he concept of +W dialogue

    n ;orroind7 dialogue is organiOed in a database! This database is structured in the

    folloing ay

    #op %eve%:

    #he different >divisions> of dia%ogue are:

    Topics: The actual topic ords and responses for the dialogue indo in the game!

    .reetings: The te/t strings you are greeted ith hen you initiate dialogue ith an actor!

     /ersuasion: The ansers you get for successful or failed persuasion attempts!

     5ournal: The entries for your @ournal!6oices: The !mp2 sound files (and subtitles) that players KsayK hen you come near7 are hit7 are fleeing7 etc!

    Su- %eve% 5:

    Each of these top le9el di9isions has suble9els call topics for the Topics di9ision7 these are

    the actual K>eyordsK (topics) that actors ill ha9e something to say about! These are the

    ords that ill be highlighted (Khyperlin>edK) in inBgame te/t and listed in the right hand

     panel of the dialogue indo! For 5ournal  these are the different @ournals (usually one per

    Duest)! For 6oices the different categories of sound responses that are KtriggeredK by the

    appropriate inBgame conditions etc! For .reetings these are @ust general categories of

    greetings (diseased7 Duest offers7 standard and so on)!

    Su- %eve% !:

    For each topic there can be one or se9eral subBentries these are the actual responses! For

    Topic and .reetings these are the actual ansers of actors to the topic phrase! For 5ournal  

    these are the different entries describing the progress of a Duest!

    These entries represent a lin>ed list7 meaning that each entry contains (in9isible) info on

    hich is the ne/t response in line and hich is the pre9ious! (This leads to a common error

    message hen dialogue gets deleted or scrambled7 e!g! by cleaning a mod ith TESA;E7 or

     by loading se9eral mods that change the same topic! The game doesnt >no for sure any

    more hich entry comes after hich! This sometimes doesnGt matter7 but it can also mean that

    certain responses are cut off7 because the order isnGt right any more this depends on the

    conditions)!These entries come ith conditions that you can set in the dialogue editor indo! n the

    topic indo you ill find a list of general conditions on the left here you can define hich

    22

  • 8/16/2019 Morrowind Scripting for Dummies 5

    34/134

    actor (Actor .) or group of actors (:ace7 Class7 etc!) potentially >no this response! There

    are also to conditions for the C (C faction and ran>)! To the right you can set a ma/imum

    of 4 KfreeK conditions that can refer to the actor7 the C or other things li>e the state of global

    9ariables lots of options here7 you ill ha9e to see for yourself! Chec> for @ournal entries7

     player stats7 local or global 9ariables7 items in in9entory7 and many other functions7 some

    eDui9alent to script functions7 some uniDue to dialogue (see belo)!

    An important and initially confusing feature of the dialogue editor is the filter option (loer

    leftBhand corner)! %hen you select an actor . here7 you only see the topics that this actor can

     possibly >no (as described abo9e)! :emember that hen you create a new topic (maybe

    specifically for that ,C) it contains no responses! Thus the actor cannot K>noK it and thus

    the freshly created topic does not appear* Select the empty slot on the 9ery top to see all

    topics again7 ma>e a response for the ne topic that your actor can K>noK then you can

    turn the filter on again7 if you ish!

    ow dialogue wor0s

    To decide hether a dialogue topic is a9ailable during dialogue ith an ,C7 the gamechec>s

    1! %hether the ,C K>nosK the topic this is determined by the conditions set in the

    Kspea>er conditionsK field if the ,C can fulfill the conditions for @ust one of the

    responses for that topic7 he K>nosK it!

    0! %hether the layer >nos it! The C >nos a topic if it (the topic ord) either

    appeared pre9iously in a response from an ,C or if it as specifically added ith the

    AddTopic function!

    2! f both the C and the actor K>noK the topic it shos up in the topic list and gets

    highlighted in the te/t it can no be selected by the player and an appropriate

    response ill be gi9en!

    %hen the game has to select the correct response from the list of responses for that topic7 it

    does the folloing

    • t starts chec>ing from the top of the list7 hether the conditions for that response are

    met7 hich means a%% conditions that ha9e been defined for that response return KtrueK!

    • f not BU 6ame mo9es on to the ne/t item in the list and chec>s again!

    • f yes BU this entry is used and printed to the dialogue indo!

     

    Special rule for greetings if none of the items in the list are met7 mo9e on to the ne/t le9el 1

    item (e!g! if no greeting in K6reeting +K returns true7 start chec>ing K6reeting 1K!

    Special rule for ournal there is only one condition here7 the inde/ (called by To%rnal function)! t must be e/actly met!

    ?nce a response has been selected7 the game ill

    • ?utput the te/t string to the dialogue indo (or play the mp2 for 6oice responses)

    • E/ecute any Script commands in the :esults field (At the 9ery bottom)! 3ou can use

    all scripting functions here7 but no commands so no if conditions7 for e/ample! f

    you need something li>e that7 you must set up different responses using the condition

    fields and then use the to separate result fields!

    -e aare that the result field allos you to e/change information ith scripts (e!g! by setting9ariables or adding @ournal entries) and that scripts can 9ice 9ersa influence dialogue as ell7

     by setting conditions that can be tested (e!g! you can chec> for local or global 9ariables in the

    2

  • 8/16/2019 Morrowind Scripting for Dummies 5

    35/134

    spea>er conditions of dialogue)! The simplest script that influences dialogue is the nolore

    script7 hich is @ust used as a flag to >eep actors from using standard dialogue!

    / few golden rules:

    • The most specific responses should be on top of the list7 the Kcatch allK ansers

    should be loest* :emember the first one that returns true is the one that gets pic>ed!So you cant ha9e a response for e9eryone in 8i9ec abo9e one for a specific ,C in

    8i9ec!

    • f you ant an ,C to be able to tal> ith the C about something special7 you must

    introduce the topic ord7 e!g! in a greeting or in a Klatest rumorsK response!

    Alternati9ely7 you can use a script ith the AddTopic function!

    • Topic7 6reeting7 ournal are actually all in the same database thatGs hy @ournal

    topics use a format li>e A1Qdreams! f it ere @ust KdreamsK than the @ournal entry to

    KdreamsK could come up as a dialogue response to the ord KdreamsK!

    0iaogue/reated functions

    Displaying messagesessageBo!$ essage3$ ,var1.$ ,var8.$ ,&%tton13.$ ,&%tton83.

    The Message#ox command lets you gi9e out information to the player! ,ormally these appear 

    as a small bo/ ith the te/t on the bottom of the screen that stays there for a fe seconds or

    until the player has clic>ed a button if the message bo/ has buttons! f a dialogue indo is

    open7 Message#ox ill output to the dialogue indo* Message#ox has se9eral different

    modes of operation! The simplest one is @ust gi9ing out an onscreen message that appears on

    the bottom of the screen for a fe seconds7 as in the folloing script that gi9es out a message

    hen the item itGs attached to is eDuipped

    Begin informplayer/hort On5+E%ip

    if ( en%ode == 1 )ret%rn

    endif

    if (On5+E%ip ==1 )essageBo!$ 2he sword vi&rates in yo%r hand3/et On5+E%ip to 0

    Endif

    End informplayer

    The second mode of operation ma>es the message stay on the screen until the player presses a

     button

    essageBo!$ >lyah lifts her hands and spea?s the form%la' -o% will now &e transported to/heogorad3$ o?3

    n the third mode of operation you can use the messagebo/ to demand a decision from the

     player 9ia a message bo/ ith buttons and the .et#utton/ressed  function

    4etB%tton5ressed (ret%rns short)

    ressed button if a message bo/ ith buttons is used7 starting at +)! %ill return 1 until button

    is pressed!

    Samp%e Script:

    25

  • 8/16/2019 Morrowind Scripting for Dummies 5

    36/134

    Begin choices

    /hort &%tton/hort stat%s/hort On5+E%ip ;declare as varia&le otherwise there will &e errors

    if ( On5+E%ip ==1 )essageBo!$ 2he sword vi&rates in yo%r hand' @o yo% want to e%ip it3$ yes3$ no3/et On5+E%ip to 0 ;display the essage Bo! only once/et stat%s to 1

    EndifIf ( stat%s == 1); wait for player decision

    /et &%tton to 4etB%tton5ressedIf ( &%tton == 71 ); no &%tton selected yetJ do nothing

    ret%rnElseif ( &%tton == 0 ); contin%e normally

    /et stat%s to 0 ; reset for ne!t timeElseif ( &%tton == 1 )

    5layer 76 drop$ "power_sword" ; ma?es the player drop the item/et stat%s to 0

    EndifEndif

    End

    Displaying (ariables and text defines in a message box

    To display 9ariables in a message bo/ you need to use a synta/ describing the format of the

    number to be displayed! ATTE,T?, there is a lot of rong info in the original helpfile on

    this*

    essageBo! "-o% have S'0f days left"$ days_left

    The symbol indicates the 9ariable! The number after the dot determines the number of

    digits displayed! KfK signifies a float 9ariable! The helpfile lists se9eral types (f for float7 . for

    short or long and S for string 9ariables)7 of these could only get f to or>! oe9er g and6 or> fine for short and long 9ariables (than>s ,iyt ?l)! 3ou can use things li>e !2g7

     but the digit designation ill simply be ignored! The designators are not really specific to the

    9ariable type7 !2f ill also display a short or long 9ariable!

    String 9ariables are mentioned in the helpfile but are to my >noledge not implemented7 you

    can hoe9er use dialogue te/t defines in message bo/es but do ,?T use for te/t defines  

    n scripts its Yinstead (than>s :agnarQ6.)

    #e$t defines:

    YC,ame The players name!

    YCClass The players class!

    YC:ace The players race!

    YC:an> The players ran> in the spea>ers faction!

    Y,e/tC:an> The players ne/t ran> in the spea>ers faction!

    YCell The cell the player is currently in!

    Y6lobal Any global 9ariable 9alue! Floats display as 1!17 such as Y6amehour! ,ote you

    can also display a 6lobal 9ariable normally7 using the abo9e synta/ such as !1f7 hich

    ould yield the same result!

    Y,ame The spea>ers name!

    Y:ace The spea>ers race!YClass The spea>ers class!

    YFaction The spea>ers faction! f they ha9e no faction7 it ill be blan>!

    24

  • 8/16/2019 Morrowind Scripting for Dummies 5

    37/134

    Y:an> The spea>ers ran>!

    Note: These last listed ones ill not or> Duite as they do in dialogue7 as the defines default

    to the Cs 9alues by default7 not to the calling actor! So Y,ame and YC,ame ill both

    display the Cs name! 3ou can hoe9er use YActor!,ame! ?n the other hand7 if you >no

    ho the actor is already7 then using the te/t define is only semiBuseful= sa9es you someloo>ing up7 guess!

    8$amp%e Script: Stupid sample script demonstrating all possible synta/Begin test1

    short var_1long var_8float var_9; 4ameQo%r is a glo&al float varia&le

    set var_1 to 1set var_8 to 8set var_9 to 9

    essageBo! "U5+Dame$ yo% have Sg head$ S4 hands$ and S'f gold' One co%ld say the ho%r isgetting late in Ucell' ItPs the U4ameQo%r ho%r or more e!actly the S'8f ho%rK"$ var_1$ var_8$var_9$ 4ameQo%r

    End

    /dding a dialogue topicAdd2opic$ "2opic"

    ?nce you ha9e set up a dialogue topic in the TESCS7 you may find that you still canGt tal>

    about it ith the ,C you ha9e gi9en the dialogue to7 because for the game you dont >no

    that particular topic yet! There are to ays to change that condition either you introduce thetopic in another con9ersation topic (e!g! a custom greeting) or you gi9e it to the player 9ia

    script7 hich ma>es sense hen itGs an ob9ious topic the player ould as> about ithout

     being brought to it by con9ersation (e!g! if you see and ,C standing under a aterfall7 you

    might ant to as> him about Karent you getting et&K e9en if the ,C doesnGt bring up the

    topic!

    To do that7 @ust attach a small script to the ,C

    3ou must already ha9e the topic ith this topic . set up before you ma>e this script7

    otherise the script compiler ill complain!

    3ou can not remo9e a topic 9ia script7 you can hoe9er set a condition that refers to a local

    9ariable of the script as a spea>er condition in the .ialogue editor7 hich can be used to

    achie9e the same effect!

    Initiating and ending dialogue:orce4reeting

    Force6reeting can be used to ma>e actors initiate dialogue! %hen (orce.reeting  is called the

    dialogue indo ill open7 and the actor ill use a greeting according to his dialogue

    Begin Add/pecial@ialog%e

    ;add possi&ility to as? a&o%t travel AddTopic$ "arenPt yo% getting wet"

    End Add/pecial@ialog%e

    2"

  • 8/16/2019 Morrowind Scripting for Dummies 5

    38/134

    settings! Therefore7 if you ant a special greeting by the actor7 you ha9e to pro9ide it 9ia the

    dialogue indo in the TES CS! t does not matter here the ,C is7 this function ill

    alays or>7 so its usually best used in connection ith a .etDistance or .et/CCell  

    condition

    8$amp%e Script: this script shos a nice set of condition being chec>ed before initiating the

     (orce.reeting  command

    Begin &alyn/cript

    float timershort doOnce

    if ( 4etTo%rnalInde! "@A_ephala" L 0 )et%rn

    endifif ( 4etTo%rnalInde! @A_ephala 6= R0 )

    et%rnendif/et timer to ( timer < 4et/econds5assed )if ( timer L )

    et%rn

    endif

    /et timer to 0

    if ( doOnce == 0 )if ( 4et@istance 5layer L= 108 )

    if ( player764et@istance "hlaal%_loaddoor_ 08_&alyn" L=8R )if ( 4etFO/ 5layer == 1 )

    ForceGreeting

    To%rnal @A_ephala set doOnce to 71

    endifendif

    endifendif

    End

    4ood&ye

    .oodb"e forces the end of dialogue! After calling this function (usually this function is used

    in the result section of a dialogue topic7 not in scripts) the C can only choose the goodbye

    option and thus closes the dialogue indo!

    +ultiple choice 1 as0ing 2uestions+hoice$ choice 13$ choice1_en%m ,"choice 8"$ choice8_en%m$ .+hoice "yes"$ 1$ "Do$ certainly notK"$ 8

    This is used in dialogue result fields to as> a decision of the player or can be called @ust to

    KcontinueK a longer speech! After the C ma>es his choice7 the same topic ill be chec>ed

    again7 and you can pro9ide the correct response by using function J choice J V J choiceQenum

    in the spea>er conditions of the dialogue indo! ,ot meant for scripts as far as >no!

    Some more info from :iia> 7nlike message#ox this one can be stacked! #" this I mean "ou

    could ha'e 8 choice calls in the same result box for a max of -+ choices or 9 Choice calls for

    a max of - choices etc!!! I don2t kno the stack limit for this, but I2m prett" sure there is one!

    )I think it2s limited to choices per call!

    /dding to the 3ournal and testing 3ournal entriesTo%rnal$ "To%rnal_I@"$ Inde!_en%m

    To%rnal$ 4_B+/hrooms+om&at$ 10

    2$

  • 8/16/2019 Morrowind Scripting for Dummies 5

    39/134

    This adds a @ournal entry to your inBgame @ournal7 the @ournal entry must ha9e pre9iously been

    set up in the dialogue editor! nde/ references hich part of a @ournal topic is added! -eare

    of using simple names for @ournal topics7 adhere to -ethsoftGs to letter standard (see abo9e

    e/ample) otherise the @ournal entry might sho up as a regular con9ersation response7 @ust

    li>e any other7 if the topic title shos up in a con9ersation*

    /etTo%rnalInde! "To%rnal_I@" inde!_en%m

    ha9e not used the function (nor ha9e -ethesda) and am not sure here it is different from

     5ournal  function! According to the helpfile KSets the ournal to that inde/! Can mo9e up or

    donK! This means probably that you can set the @ournal inde/ to a certain 9alue ithout

    triggering a @ournal entry so could this maybe be used to ma>e Duest be gi9en o9er and o9er

    again7 li>e in .aggerfall7 by resetting the @ournal to +&

    +learInfoActor

    This is a function that is used in the results section of a dialogue topic using this function

    ill stop the topic from appearing in the Cs @ournal (under KTopicsK)! #seful to a9oidcluttering the topic section ith useless information!

    4etTo%rnalInde!$ "To%rnalI@" (ret%rns short)

    If (Get.ournalInde/, *G_0C!roomCom+at == 1)

    This function returns the inde/ of the highest (or the last&) @ournal entry for that @ournal topic

    that the player has recei9ed! This is 9ery con9enient for >eeping trac> of Duest ad9ancement7

    and to ha9e a script react according to hat parts of the Duest ha9e already been performed!

    Samp%e Script: ere is a short script demonstrating the use of both functions from the game

    Begin attac?_slave

    short nolore

    If ( 4et@ead+o%nt "#orar Qelas" 6 0 )ret%rn

    endif

    if ( GetJournalIndex "#_/lave%le" L 108 ); if 5+ has not yet reached a certain pointIf ( 4et@istance$ "a&inna" L 18 )

    a&inna76Aiander 0 0 0 0 0 0 0/tart+om&at$ "a&inna"Journal "#_/lave%le"$ 108 ; add *o%rnal entry

    endifendif

    End

    Special dialogue-only functions

    Among the functions a9ailable for defining dialogue conditions in the dialogue editor there

    are a fe that do not ha9e a direct eDui9alent in scripting functions! -y using dialogue (e!g!

    using Force6reeting7 9oiceBdialogue or strategically placed Duest ,Cs) and the dialogue

    result field7 you can still ma>e use of these functions for scripting purposes7 e!g! by setting a

    global 9ariable in the result field! E/amples of such functions are

     /C Sex )dialogue

    This is + if the player is male and 1 if the player is female!

    2'

  • 8/16/2019 Morrowind Scripting for Dummies 5

    40/134

    Talked to /C )dialogue

    This is 1 if the spea>er has e9er tal>ed to the player and + otherise! 3ou can use this to ha9e

    someone say something the first time you spea> ith them or for our scripting purposes to

    mar> this person as K>nonK by the player!

     0ank 0e;uirement )dialogueThis chec>s to see if you KDualifyK for the ne/t ran> in the spea>ers faction!

    This returns + if you do not ha9e enough Faction :eputation and do not meet the s>ill

    reDuirements!

    This returns 1 if you meet the s>ill reDuirements7 but do not ha9e the Faction :eputation!

    This returns 0 if you ha9e the Faction :eputation7 but do not meet the s>ill reDuirements!

    This returns 2 if you Dualify!

     /C Clothing Modifier )dialogue

    This is the total 9alue of all the clothing and armor the player is earing! The 9alue of your

    eDuipment changes the disposition of people in the game!

     (riend a member of your group (li>e a folloer)

    The return 9alues are

    + V ne9er been hit

    1 V hit by pc 1st time

    0 V hit by pc 0nd time

    2 V hit by pc 2rd time

    < V hit by pc

  • 8/16/2019 Morrowind Scripting for Dummies 5

    41/134

    :eturns 1 if C is in the faction of the calling ob@ect (,C)!

    5+E!pelled ,"factionI@". (ret%rns BooleanGshort)

    :eturns 1 if C has been e/pelled once from calling ob@ect (,C) Faction7 or a faction can be

    defined to get a specific one! For an e/ample script loo> belo7 CClearE/pelled function!

    4etace$ aceI@3 (ret%rns BooleanGshort)Pla2er#$Get3ace "Dark 4lf"

    :eturns 1 if the ob@ect is of :ace.!

    Samp%e Script: This is a global script -ethesda uses to set a 9ariable that can be used to

    determine the Cs race in dialogue&egin ace+hec?

    ;glo&al script that gets r%n once to chec? the 5+Ps race$ so it can &e %sed in dialog%e

    if ( 5layer76GetRace "Argonian" == 1 )

    set 5+ace to 1elseif ( 5layer76GetRace "Breton" == 1 )

    set 5+ace to 8elseif ( 5layer76GetRace "@ar? Elf" == 1 )

    set 5+ace to 9elseif ( 5layer76GetRace "Qigh Elf" == 1 )

    set 5+ace to elseif ( 5layer76GetRace "Imperial" == 1 )

    set 5+ace to elseif ( 5layer76GetRace "Vha*iit" == 1 )

    set 5+ace to Relseif ( 5layer76GetRace "Dord" == 1 )

    set 5+ace to Nelseif ( 5layer76GetRace "Orc" == 1 )

    set 5+ace to elseif ( 5layer76GetRace "edg%ard" == 1 )

    set 5+ace to Celseif ( 5layer76GetRace "ood Elf" == 1 )set 5+ace to 10

    endif

    /top/cript ace+hec?

    end

    odifying faction standing and reaction

    5+Toin:action ,":actionI@".

    ;a>es the C a member of the specified faction! Faction. is optional if it is not added it illuse the faction of the ,C ho called the function

    Foweran?aisean?

    :aises or loers the ob@ectGs ran> in its current faction! n the original game7 this as only

    used in dialogue!

    5+Foweran?5+aisean?

    :aises or loers the C 1 ran> in the ,Cs faction! f C is not part of the faction7 it ill setthe ran> to 1

  • 8/16/2019 Morrowind Scripting for Dummies 5

    42/134

    5+E!pell ,":actionI@".

    E/pels C from ,Cs faction!

    5++learE!pelled ,":actionI@".

    Clears currently e/pelled flag!

    8$amp%e script:

    A script by -ethesda7 hich clears the layers e/pelled status after some timeBegin e!pelled4

    ;this is *%st a model;it is s%pposed to &e on an item in each of the ages 4%ilds'

    short my@ayshort temp

    if ( PCExpelled  "ages 4%ild" == 0 )ret%rn

    endif

    if ( E!pages4%ild == 0 )/et E!pages4%ild to 1

    endif

    if ( my@ay == 0 )/et my@ay to @ay

    endif

    if ( my@ay == @ay )ret%rn

    endif

    if ( @ay 6 my@ay )/et temp to ( @ay 7 my@ay )

    else

    /et temp to ( my@ay 7 @ay )endif

    /et my@ay to @ay

    /et temp to ( temp < 8 )

    /et E!pages4%ild to ( E!pages4%ild < temp )

    if ( E!pages4%ild 6 90 )/et E!pages4%ild to 0PCClearExpelled  "ages 4%ild"ret%rn

    endif

    End

    od5+:acep$ var_en%m$ ,":actionI@"./et5+:acep$ var_en%m$ ,":actionI@".

    *odPCac3e5, &, "Im5erial 6egion"*odPCac3e5, &, "7em5le"

    ;odifies or defines the reaction modifier for members of the specified faction (toards the

    C)!

    od:actioneaction$ "factionI@1"$ "factionI@8"$ var_en%m/et:actioneaction$ "factionI@1"$ "factionI@8"$ var_en%m

    ;odifies or defines the reaction of one faction toards members of another faction!

  • 8/16/2019 Morrowind Scripting for Dummies 5

    43/134

    8$amp%e This is part of the ;oonAndStar script! This part first ma>es the C part of the

    faction K,ere9arineK and then sets to factions to react particularly to this change;faction reaction and *o%rnal st%ffTo%rnal "A8_R_Incarnate" 0player76modep%tation PCJoinFaction$ Derevarine

    if ( 4et5+an?$ edoran 6= 0 ) odFactionReaction$ "edoran"$ "Derevarine"$

    endif

    if ( 4et5+an?$ 2emple 6= 0 ) odFactionReaction$ "2emple"$ "Derevarine"$

    endif

    %ombat

    -nitiating and ending cobat /tart+om&at$ "ActorI@"

    /top+om&at

    "Actor_I@1" 76 /tart+om&at$ "ActorI@8""Actor_I@1" 76 /top+om&at

    StartCombat and StopCombat are used to set an actor into combat mode or bac> into normal

    mode! Start combat ill ma>e the calling actor attac> the actor supplied as the argument!

    %hile StopCombat seems to be KsafeK to use Ke9ery frameK7 you should supply a do once

    condition of some sort hen issuing the StartCombat command7 otherise the actor might not

    do anything! ,e9ertheless continuous StopCombat is 9ery dangerous to use7 because it ma>es

    the ,C completely helpless it ill not retaliate hen attac>ed (hich hoe9er allos you

    to create a real pacifist=)!

    ?nce in combat mode the A settings of the actor apply normally7 e!g! if the actor has a highflee setting7 he ill flee despite the StartCombat command! For this reason7 you ill often see

    that the Fight rating is also changed hen initiating combat in many scriptsIf (4et@ead+o%nt$ "y :riend" 6 0 )

    !tartCo"at$ 5layer!etFight$ 100

    endif

    0etecting (ttac" On5+Qite (is local short varia&le)

    /hort On5+QiteIf (On5+Qitme == 1)