Page 1 of 1
Scripting - Basics and Help
Posted: Sat Mar 13, 2010 12:18 pm
by Caz
It seems we have a fair few modders on here, but not all of them can script. If you have been wanting to write your own, but you're one of the people who are just overwhelmed by the complexity or you just haven't found a good guide to give you a head start, then you may find this thread helpful. Or if you've started scripting, but it just isn't working like it should and you need some help, feel free to ask here.
I shall begin by explaining the first few steps to writing your own script.
(Note: In each line, anything that is written behind a ; will be ignored by the game, it is just a note by the author, to help himself think, or in this case to explain to others. You may find it useful when writing yourself.)
Each script needs a beginning and an end. It should look like this:
Code: Select all
begin my_first_script ; my_first_script being the unique name of your new script
end
This script will of course do nothing at all. In between those two lines though you add the rest of the script, for which you mostly use so called "if statements". A pretty common variable is OnActivate: 0 means not activated, and 1 means activated. Just like you close your script with an "end", each if statement must be closed with and "endif"
Here a simple example which will make the item you attach it to cast a spell on you when activated:
Code: Select all
begin my_first_script
If ( OnActivate == 1) ; as explained above, this checks if the item is activated or not, and if it is it will continue to execute the following line
Cast, "fireball", Player ; telling it to cast a fireball spell at you
Endif ; closing the if statement
end
Fancy, isn't it?

That will have to do for now, more is to follow soon. Feel free to ask any questions you may have or add your own tips and comments.
Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 1:13 pm
by Hunter22
Okay a little question to get it going, is it a similar procedure with all scripting (i.e. oblivion) or does it change?
Im a bit of a beginner even when comes to modding to be honest, but im starting to pick up the basics

Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 2:28 pm
by Imperfect
Thanks Caz. Modding isnt as hard as it seemed when it first began. The only things I havent figured out so far, to my knowledge, are Journal entries and scripting.
Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 4:08 pm
by Andere
Thanks for your new thread. I'm sure it'll help many.
I know I haven't done any of my homework = manuals or anything, but I take the boldness to ask, is this done with The Elder Scrolls Construction Set? Or is it done with any text editor, and saved in some special file type?
Looking forward to participate in this great game.

Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 6:28 pm
by Imperfect
@Andere, as far as I know its only in the script editor in the construction kit.
@anyone, Idk if this is done through script or if I am missing something. I need Helseth's death to trigger 2 things: a spawning of an NPC in the throne room, and a jorunal entry
the entry is noted as "TR_Helseth_Dead" at Index 20
If someone could post the script I need to trigger that Journal entry I would really appreciate it.
And the spawning... I have no idea how to do that, but I know thats through scripting. If someone could post the formula for that, it would be awesome.
Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 6:57 pm
by Caz
@Hunter22: It's different, I've only tried scripting in Oblivion once and I had to use the CS wiki to help. The basic idea is the same though, if you understand one you should be able to understand the other
@Andere: You write the scripts in the CS itself and attach them to whatever you want. When I'm writing longer ones though I compose them in a normal editor and copy it over, I just find it easier to work with if it's going to take some time.
I have given your script some more thought, I think it should be possible with OnActivate and GetSecondsPassed. I am not yet entirely sure what it would look like though.
@Imperfect: This is not tested, but try something like this:
Code: Select all
begin death_script
if (OnDeath == 1)
Journal, "TR_Helseth_Dead", 20
PlaceItemCell, ObjectID, CellID, X, Y, Z, ZRot ; here you'll need to add the NPC ID, the cell ID and the coordinates yourself
endif
end
Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 8:42 pm
by Imperfect
Thanks Caz, I will test that next time I am in the CS.
Re: Scripting - Basics and Help
Posted: Sat Mar 13, 2010 9:46 pm
by Imperfect
Alright Caz, got another one for you.
I need 3 characters: Sotha_sil_living1, vivec_god2, and almalexia_battle2 to disappear whenever I leave the Heart chamber, and I need them to never come back.
Any ideas?
Re: Scripting - Basics and Help
Posted: Sun Mar 14, 2010 3:07 pm
by Caz
Attach a script to something - the door, perhaps? - using the command
"disable". You may want to use several if statements at once to make sure it happens at the right time (not before the death).
Do not attach it to the characters themselves, apparently that causes crashes. Have a go at writing it yourself

Re: Scripting - Basics and Help
Posted: Sun Mar 14, 2010 3:33 pm
by Andere
Thanks Caz and Imperfect.
I downloaded some tutorials, and plan to start with "something" once I get my fingers off the game itself. I took part in a mod project for the game Freelancer, and it simply killed my playing - it went to "all work, no fun", and I'm not going to let that happen again.
Came to think, it would be wise to install a modding version of the game, in another partition? I have Windows XP Professional SP3, all updates, in partition C; then I have two other partitions, K and L. If I install MW in either K or L, will it have any consequences for the mod ( I hopefully manage to make

)?
And, should I install everything up to Bloodmoon, plus MCP? Plus perhaps... what? In order to try to secure the compatibility, from the very start?
Please understand me, I suffer from the occupational disease of photographers, pedantry. Every dot and reflection has to be where I want them to be.
Finally, is the program Morrowind Script Editor v. 1.2 useable and reliable? I haven't tried it, no - no, but my earlier experiences with modding have shown, what you write is what you get, but various tools that make it all easier, aren't necessarily that reliable.
A lot of text once again, but I trust it will have an outcome.

Like a Finnish proverb says,
It's good to live in Hope, said the tapeworm.
Thanks again m8s.
Re: Scripting - Basics and Help
Posted: Sun Mar 14, 2010 8:08 pm
by Imperfect
Alright. I know what you mean Andere, thats what this mod is turning into. I am working out a few small kinks. All thats left to do is fix Barenziah, who seems to not realize when her son is dead, and set those guys to disappear when I need them too.
Re: Scripting - Basics and Help
Posted: Wed Mar 17, 2010 4:34 am
by Imperfect
Caz wrote:
@Imperfect: This is not tested, but try something like this:
Code: Select all
begin death_script
if (OnDeath == 1)
Journal, "TR_Helseth_Dead", 20
PlaceItemCell, ObjectID, CellID, X, Y, Z, ZRot ; here you'll need to add the NPC ID, the cell ID and the coordinates yourself
endif
end
I forgot to mention, that script worked perfectly, but I cant figure out the scripting for the door. Once I do that, I will upload the mod for everyone.
Re: Scripting - Basics and Help
Posted: Wed Mar 17, 2010 1:21 pm
by Caz
Perhaps I should explain for everyone how we use multiple if statements at once. Basically, if two things are to be checked at the same time, you insert one inside the other, like so:
Code: Select all
if (something)
if (something)
command
endif
endif
So your script, Imperfect, might look something like this:
Code: Select all
begin door_script
if ( OnActivate == 1) ; when the door is opened
if ( GetJournalIndex, C3_DestroyDagoth >= 20 ) ; if you have a certain journal entry for this quest, here meaning after dagoth ur is killed
Sotha_sil_living1 -> disable
vivec_god2 -> disable
almalexia_battle2 -> disable ; all characters should disappear
endif
endif
end
Probably needs some tweaking... may need to add a GetDisabled line too.
And short note for everyone: you may know this already, but I'll put it down here for the record. When using if statements, you can use the following:
== : equal to
!= : not equal to
< : less than
> : greater than
<= : less than or equal to
>= : greater than or equal to
Re: Scripting - Basics and Help
Posted: Wed Mar 17, 2010 3:15 pm
by Imperfect
I will use that. Coding for this is different than stuff I am used to, like html
I preffer the virtual part of the construction set, that I can see what I am doing.

Re: Scripting - Basics and Help
Posted: Fri Mar 26, 2010 1:21 pm
by Caz
@Imperfect: how is that mod of yours going? Did the script work?
The virtual part is nicer to work with, but once you get the hang of scripting you can have much more fun in the game

That's why I'm teaching myself.
@Andere: I think I finally got the hang of the timer scripts. Attach this to any doors you want to have close automatically:
Code: Select all
begin automatic_door
short Open
float TimePassed ;this is declaring local variables, to be explained later
If ( Menumode == 1)
return
endif
set TimePassed to ( TimePassed + GetSecondsPassed ) ;setting the timer
if ( OnActivate == 1 ) ;if activated
if ( Open == 0 ) ;if it's not open already
Activate ;open door
set Open to 1 ;tells script that door is open
set TimePassed to 0 ;reset timer to 0
endif
endif
if ( Open == 1) ;the timer will only count if the door is open
if ( TimePassed > 5 ) ;counts to 5 secs, change to whatever time you need
activate ;close door again
set Open to 0 ;tells script that door is closed, timer will not count
endif
endif
end
Let me know if there is something you don't understand or if it doesn't work properly. I tested it though and it should be ok.
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 12:01 pm
by Andere
Hi Caz.
Thanks for your reminder PM, it got me working.
I tested the script, and it seems to work just fine. I'm a bit confused about two things, quite general by nature.
I have this tutorial Morrowind Scripting for Dummies. In their first example of writing a script, they create a Riddle Chest.
When I follow their instructions, everything goes well until the saving part. They don't mention saving an .esp file, but that's the only way I get the doors to function - if I don't save an .esp, and activate it in the game's Data Files, nothing happens, and the following time I open TES CS, there's no sign of the script - it has completely vanished.
Am I doing something wrong while saving?
They also ask to rename the object. My object is in_r_s_door_01, at Maar Gan Outpost. I renamed it to in_r_s_door_01b, but loading a game I got a warning, something like "can not find object in_r_s_door_01b". Of course, I know nothing about the principles of renaming...
But like I said, with an .esp it works.
Thanks and cheers.
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 1:46 pm
by Caz
When modding you cannot modify the game directly, only create your own mod files, and they must be activated before starting the game. This is actually useful because take for example my case, when making a mod I somehow managed to shift a large part of the countryside without noticing. Sure, I had to delete my mod, but better that than reinstalling the whole game because you messed it up, aye? And this other time suddenly all the houses in Pelagiad disappeared (leaving only the doors), although my mod had nothing to do with that area... strange things have happened

So, a new .esp file for each mod. If you're making huge mods, it might be better to make several esps for it in case something goes seriously wrong (like mentioned above) and you won't need to start over.
Renaming objects. Well this is only for when you are creating new objects: entering a new one will make a new one, while leaving it unedited will write over the old one. In the case of your doors, you'd want to just add the script to as many doors in game as possible, without creating new ones, because in the visual part of the CS you can see that it would still be the original doors without scripts. You could always replace them all with your own doors, but thats just a load of unnecessary work.
Also, I wouldn't try adding the script to doors that take you to a different cell (into a building, for example). They are always "closed", so I don't know what would happen if you added that script to it. I can only think of one way to tell these kinds of doors apart: in the visual part of the CS, the normal doors look like doors from both sides, whereas the "teleporting" ones look like a door on one side, but on the other side it's practically invisible, as no texture has been added to the other side. Perhaps there's a different way to tell them apart without having to drag them all over and looking at them, but I can't think of one right now.
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 2:31 pm
by Andere
Very informative, Caz, thank you.
As far as I really understood it correctly, it seems like a pretty wise move to have to make a new .esp every time.
Another game I modded had the "Pelagiad syndrome": it was a space game with solar systems, planets and stuff, and when you did something... without success... the whole blasted system disappeared.

In Morrowind, and my case right now, it would mean Maar Gan would disappear... what a fancy thought, though not desirable..
Caz wrote:Renaming objects. Well this is only for when you are creating new objects: entering a new one will make a new one, while leaving it unedited will write over the old one.
This is certainly a stupid question but: What would be a typical case of making a new object?
Caz wrote:Also, I wouldn't try adding the script to doors that take you to a different cell (into a building, for example). They are always "closed", so I don't know what would happen if you added that script to it.
Well, in my case that's not even needed. Those doors are already automatic i.e., you actually just slip through them.
Thanks pal, Your advices are highly appreciated.
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 3:24 pm
by Caz
Andere wrote:Caz wrote:Renaming objects. Well this is only for when you are creating new objects: entering a new one will make a new one, while leaving it unedited will write over the old one.
This is certainly a stupid question but: What would be a typical case of making a new object?
Hmm... for example, I want to make a ring with a certain spell on it. I could right click and press "new", then find the textures etc by myself. Or, the way I prefer doing it: I take one that already exists, make the changes and save as a new object, leaving all already existing objects with the old ID untouched, and my now magic ring a new, separate item.
Caz wrote:Also, I wouldn't try adding the script to doors that take you to a different cell (into a building, for example). They are always "closed", so I don't know what would happen if you added that script to it.
Well, in my case that's not even needed. Those doors are already automatic i.e., you actually just slip through them.[/quote]
Precisely. But I do wonder what would happen if the script is attached to one of those... maybe you'd get taken back to where you were before?

Or maybe nothing at all. I may try that out some time...
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 4:27 pm
by Andere
Alright... trying to get somewhat deeper into the world of scripts, are those empty spaces essential?
Like when you write
If ( Menumode == 1)
return
endif
you have three empty spaces in front of "return".
They won't show in this message, but they show in a text editor, and the Script Edit of TES CS. There are three blanks in front of "r" of return.
Are they essential? If they are, I guess it's a matter of experience to get them right? "What a beautiful world", eh?
??? I mean, usually (?) empty spaces don't mean anything, and if you want to excerpt something it's by a ;.
I'm really getting interested in this. How I'm going to make my "Caldera Ebony Mine War", I don't know, but my toes get warm...
Cheers,
Andere
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 6:14 pm
by Codex
The three spaces is actually one hit on the tab key

It's only purpose is to make the script easier to read; to see which "endif" belongs to which "if".
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 6:28 pm
by Dogmantra
Just a note from a bit of an amateur scripter (did a bit of Flash programming):
DEFINITELY USE WHITE SPACE
If you come back to a script after a while, it can be really confusing to work out which stuff is triggered when and when whatever ends and oh my this "for" command actually ends here and not here and frig that changes everything.
Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 6:40 pm
by Caz
Correct, as they said it's just easier to read if you use tabs.

Re: Scripting - Basics and Help
Posted: Thu Apr 01, 2010 7:45 pm
by Andere
Ok, thanks friends.
I'll try to figure it out - without blowing the whole game up!
Ho-Ho, said Sancta Clause!
Re: Scripting - Basics and Help
Posted: Tue Apr 06, 2010 2:30 pm
by Caz
Ok as promised, an explanation about variables.
There are two different types of variables, local and global ones. Here I shall explain local ones, the different types and how to define and set them.
Local variables belong only to whatever the script is attached to (global variables work on every script and can be set in the CS menu). You can name them whatever you want, provided it begins with a letter (you should also avoid using most characters too, as it can cause problems). All local variables must be declared (preferably) at the beginning of the script, like this:
By default they are 0 until set to something else, using the "set" command, as such:
Code: Select all
set Open to 1
set TimePassed to ( TimePassed + GetSecondsPassed )
There are three different kinds, depending on the numbers that it can take on: short, long and float.
- Short variables are values from -32768 to 32767
- Long variables are values from -2,147,483,648 to 2,147,483,647
- Float variables are 3.4e +/- 38 (7 digits)
Examples:
- Short: in the door script (see above) the variable for the door being open would only take on two numbers, 0 or 1 (closed and open), therefore I only need a short variable.
- Long: similar to short, I believe, but can take on higher values
- Float: also in the door script, the time can take on decimal numbers, so it is a float variable
Questions?
