Jump to content

DOWNLOAD MODS

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

LEARN MODDING

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

JOIN THE ALLIANCE

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

Class #1 - The Basics of Oblivion Scripts


WillieSea
 Share

Recommended Posts

 

 

The Basics of Oblivion Scripts

Class One

 

 

This topic will cover the basic elements of a script.

 

There are plenty of tutorials that explain other topics about scripts. Since I don't want to just make a copy of that, I will dig right into the guts of the language itself. I will also try to dispense with chatter from me and just provide details. You will find I use numbered lists a lot to point out important facts.

 

A good link to an external scripting tutorial can be found here: --> WIKI Tutorial: My Second Script

 

Abbreviations:

CS - Construction Set

CTD - Crash To Desktop

scn - ScriptName

mod - A file that modifies the original game content. You will create a 'mod' in this class.

 

 

The term Block

I use the term 'Block' to specify a section of code that goes together.

 

For example, a sandwich has two pieces of bread to hold in the contents of the sandwich, be it peanut butter and jam, or tuna fish. The two pieces of bread would be a block. They are both needed on both sides of the goodies in the middle.

 

This analogy holds true for some script commands as well. For example, the Begin/End blocks of code. Or the If/EndIf blocks of code. The If/Endif block of code can also be a multi-layer sandwich with the use of the Else and ElseIf commands. The important thing to remember here is blocks of code are used to 'contain' commands to perform.

 

The script window can be opened by clicking on the 'Pencil' icon on the toolbar at the top of the CS window. Its the icon that is the furthest to the right.

 

gallery_85_79_69427.jpg

 

Now, lets get started.

 

 

 

 

Chapter One - Main Script Naming Block

 

 

All scripts contain some very basic elements. The most important is the "ScriptName" or "scn" for short. Both do the exact same thing. This command will NAME the script. For example:

 

 

 
scn MyFirstScript

This will create a usable script that other objects can use. It will be saved in the available scripts list as "MyFirstScript". ;) Smarty Says: - Never use a numeric character as the first name of your script. It will work as a script name, but its good to NOT be in the habit of using numerics. They CAN and WILL cause you headaches when used on certain objects. Activity Blocks for the "Begin" block For our first script, we will use an Activity Block that runs when the player clicks on an object. It is the onactivate block. But first, you must open the Script Edit window by clicking the Pencil Icon once. On the Script Edit window, choose the toolbar 'Script' and select 'New...' to open an edit window. click inside the window once to activate the cursor. You can now start typing your script into the new script window. gallery_85_79_2755.jpg Now, type this in:

 
scn MyFirstScript

begin onactivate

	MessageBox "Hello!"

end

 

 

:smarty: Smarty Says: - Use the 'Tab' key to indent your script correctly. Notice that my block code lines up. (Begin/End) The code inside this sandwich is indented for clarity purposes. This can help you find mistakes in your own code if you only have half the sandwich made.

 

This script, when attached to an object, and clicked on by the player, will open a pop-up window that says "Hello!" with an OK button.

 

Its time to save the script. Press the black and white Floppy Disk icon on the toolbar, or click on the toolbar >Script >Save.

 

gallery_85_79_18740.jpg

 

:smarty: Smarty Says: - You should never, under any circumstances, click the '>Recompile All' option. It will make your mod very large, and make it incompatible with many other mods. What it does is re-create every script in the game and mark them as changed.

 

 

 

 

 

Chapter Three - Attaching the Script

 

 

You cannot just attach the script to any object. The object must have a collision attached to it in order for it to be activatable. But I will not go further into that subject, as it really does not apply to this forum.

 

For this example, the script we created and saved in the previous chapter will be attached to an Ayleid Press Block.

 

gallery_85_79_92976.jpg

 

You must expand the Object window until you find the >Activator folder. Click on it and the window will fill with all the activators that are available. Click in the list on any object and type on your keyboard, quckly,

ARSW

and you will be brought to the correct object we will attach our script to, "ARSwitch01".

 

Double-click on the ARSwitch01 object. This will open a pop-up window with the BASE STATS of that object.

 

gallery_85_79_23364.jpg

 

Now, change the ID to "MySwitch01", give it a new name if you wish, and click the arrow of the drop down list box and scroll to find the script you created above. (Its called "MyFirstScript".)

 

Click the OK button and another popup window will appear.

 

gallery_85_79_14116.jpg

 

This asks if you want to create a new object from the old object. You only get this if you gave the original base object a new ID name. Click the YES button.

 

The windows will close and your new item will be in the >Activator folder. Click in the list of items and type

MYS

and your new object called "MySwitch01" will be highlighted.

 

You have successfully attached your script to the new switch object. Now you can place it in the game and try it out.

 

 

 

 

 

Chapter Four - Adding the new object to the game

 

 

Its time to add the switch to your game and try it out.

 

First, you must pick a location that you can find in the game world. In the CS, look for the 'Cell View' window:

 

gallery_85_79_29608.jpg

 

For this example, lets place the switch inside the Imperial City Arcane University Lobby.

 

1. Make sure your 'Worldspace' is set to 'Interior'.

2. Click on any cell name in the window, and type

ICARCANE

and the AU Lobby will be selected.

3. Double-click the Lobby cell and it will load the lobby into your 'Render Window'.

 

After its done loading the cell, you should see a screen like this:

 

gallery_85_79_40008.jpg

 

1. Click once on the lobby in the bottom left.

2. Press the 'T' key to get a top down view of the object you clicked on.

 

:smarty: Smarty Says: - Do NOT click on it and move it around. Be very careful when you click on things to make sure you do not accidentally move them.

 

gallery_85_79_56960.jpg

 

Now, click on the counter to highlight it, and press the 'C' key. This will center the view at a better angle so you can see the counter better.

 

gallery_85_79_108406.jpg

 

Now, shift the view to the front of the counter. To do this, press the 'Left Shift' key, and move the mouse to the 'Left'. When the mouse pointer reaches the left side of the screen, release the shift key and move the pointer to the right side of the screen, Repeat the step above to continue moving the view to the front of the counter.

 

gallery_85_79_14737.jpg

 

Now, in the object list, click on the new switch you just created. With the mouse button depressed over the new switch, drag it onto the Render Window and release the mouse button. The switch will appear in the render window.

 

gallery_85_79_16450.jpg

 

Now it needs to be positioned better in the cell. Place the mouse pointer over the new switch in the render window. The cursor should turn into a four way arrow. These are the commands for moving the new switch. (or any object in the Render window.)

 

1. Select the object(s) you wish to move.

2. Click on the object and keep the mouse button depressed.

2a. Move the mouse UP to move the object away from the camera.

2b. Move the mouse DOWN to move the object closer to the camera.

2c. Move the mouse LEFT or RIGHT to move the object in those directions in relation to the camera.

2d. Height: Press the 'Z' key and move the mouse up or down. (Z as in Zoo, where animals are in cages.)

 

You can press the 'F' key to make the object Fall to the floor. Be very careful with the 'F' key. If there is no floor to fall to, your CS will CTD.

 

Move the new switch to the floor in front of the counter.

 

gallery_85_79_35287.jpg

 

1. Now, save your mod.

2. You can now exit the CS and start Oblivion.

3. On the Oblivion loader screen, Click the 'Data Files' button, and select your mod from the list.

4. Now load Oblivion, and your switch should appear in the Arcane University Lobby exactly where you placed it.

5. Go to the Imperial City AU Lobby and click on your switch.

 

There is the Switch!

 

gallery_85_79_1080.jpg

 

And here is proof that the script RAN when you click on it...

 

gallery_85_79_58322.jpg

 

Congratulations! You have just made your first script and successfully attached it to an object in the game! :blink:

:clap::clap::clap:

 

Are you ready for more?

There will be more posts with more classes real soon!

 

If you have a question about any of the concepts in the above class, post in this thread.

If you have general script questions, please post in the "General Script Questions" thread.

Chapter Two - Activity Blocks

What do you want the script to do? This is where you determine how the script will be activated by the player or the game. Here is a link to a great list of all of the Activity Blocks you can use in a script: -->

Link to comment
Share on other sites

I was going to go into more advanced scripting topics, but The Rider asked that I make a very, very basic class first.

It was a good suggestion, as its better to build a solid foundation of granite than to build on sandstone.

REPLIES:

- I am glad it was useful. Once you get the basics of creating and attaching a script, you can advance to the more complex scripts.

- I taught myself scripting as well. Classes would have been very helpful, even a forum had I known about them.

Are there any suggestions for the next class?

Some of my ideas:

1. Conditions using IF / ELSE / ELSEIF / ENDIF

2. How to use the different "Begin" blocks of code.

3. Useful commands and how to use them. (discuss some of the uses for popular commands)

These would be 'building' classes. That means they build your knowledge of the scripting language. More useful than simply giveing you a script and saying this is how you script a door to open with a switch. (etc.)

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 8 months later...

I agree with the person who said that the Wiki stuff is just over the top. That's no slam at the people who write the Wiki tutorials, because often the tutorials (when you can find them) are great. I think the trouble is just the Wiki site format, which doesn't really make sense to a lot of people, and sometimes doesn't seem to have logical links. I mean.... I want to read a "Getting started" section that tells me how to get started modding -- not how to install Oblivion and load someone else's mods, for goodness sake!

The step-by-step example you gave here was a lot more concrete, and a lot easier to follow, than many of the examples I've been buried in before.

And in my opinion, it's never bad to assume the reader is coming in cold with little to no prior knowledge. I'd rather be "talked down to" than have someone assume I know something I don't!

Thanks a bunch, this one single class helped me with about 4 problems.

  • Thanks 1
Link to comment
Share on other sites

  • 6 months later...
  • 4 weeks later...

Great job beanie! :):trophy:

A new location and a new effect!

How about you change your script to this, instead?

scn MyFirstScript
begin onactivate
PlaySound AMBRCityBell
Message "Ring!"
end[/code] Another choice for the sound might be:
[code]PlaySound AMBBellTower

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 4 months later...

Though I have modded before, with allot more complex scripts, I just found these classes and decided that I have the time, so I will start from the very bottom up, relearning the entire language. So (because I developed a way to have oblivion easily playable as either vanilla or highly modded with wyre bash) I started with vanilla oblivion and am starting to take your classes. You are doing the oblivion world a service, educating the next generation of scripters!

Link to comment
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

 Share

×
×
  • Create New...