Difference between revisions of "Light switch tutorial"

2,023 bytes added ,  10:35, 15 April 2010
no edit summary
imported>Puf the majic dragon
(Created a tutorial for creating a light switch)
 
imported>Darkness X
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Many users have requested information on setting up a light switch in the game. This tutorial explains in detail with screenshots how to set up a generic light switch which can easily be replicated throughout your mod with only one simple script.
Many users have requested information on setting up a light switch in the game. This tutorial explains in detail with screenshots how to set up a generic light switch which can easily be replicated throughout your mod with only one simple script.
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}


== Create Your Switch ==
== Create Your Switch ==
First you will need to create a new [[activator]] world object which will act as your switch. This can be any object you desire such as a Welkynd stone or a new mesh of your design. This tutorial uses a .nif file with only a dome shaped collision object and editor marker, which appears as an invisible object in game which the player can still interact with. Once you have created the new activator, attach the following script to it:
First you will need to create a new [[activator]] world object which will act as your switch. This can be any object you desire such as a Welkynd stone or a new mesh of your design. This tutorial uses a .nif file with only a dome shaped collision object and [[Editor Marker]], which appears as an invisible object in game which the player can still interact with. This file can be downloaded from TESNexus [http://www.tesnexus.com/downloads/file.php?id=22549 here]
 
<pre>
If you create your own mesh, keep in mind that certain settings on the collision node in NifSkope need to be changed in order to keep the object from falling due to gravity or moving when it is bumped. In short, the "Layer" on the bhkRigidBody needs to be OL_STATIC, the "Collision Response" needs to be "RESPONSE_SIMPLE_CONTACT", and the "Motion System" needs to be "MO_SYS_FIXED". Other properties may also need to be set inside this node as well, so it is best to compare your settings to the properties of an unedited Bethesda mesh.
</pre>
<pre>
If your activator has no visible mesh, make sure to add an editor marker to the mesh so you can see it when you place it in the render window.
</pre>
 
Once you have created the new activator, attach the following script to it:


<pre>
<pre>
Line 48: Line 58:


[[Image:Lighttutflamerender.jpg|thumb|right|A flame placed as a light source activated by the switch]]
[[Image:Lighttutflamerender.jpg|thumb|right|A flame placed as a light source activated by the switch]]
<pre>
Rather than duplicating your activator, you can place only one activator and then place an xmarker or any other object of your choice (even one of your lights). Parent your activator to the xmarker and modify the activator script to only enable/disable its parent. In the next section, you will need to parent all of your lights to the xmarker rather than the switch. There is no real advantage to either method, it's up to your personal preference.
</pre>
== Placing Your Lights ==
== Placing Your Lights ==


The next step is to place your light sources in the render window and arrange them how you want them to appear in game. For example, placing a flame over a brazier:
The next step is to place your light sources in the render window and arrange them how you want them to appear in game. For example, placing a flame over a brazier (see screenshot).


[[Image:Lighttutflame.jpg|thumb|right|Properties of a light source]]
[[Image:Lighttutflame.jpg|thumb|right|Properties of a light source]]
You then must edit each light source and parent it to one of your switches:
You then must edit each light source and parent it to one of your switches, as shown in the screenshot.


If you want to have candles or chandeliers or other visible objects as your light source, you can simulate the candle in the off and on states by placing the "off" version of the candle (usually listed under World Objects > Statics > Lights in the Object Window of the CS) and parenting it to the Off switch, then place the "Fake" version of the same candle (usually found in the same place as the off version) and parent it to the "On" switch. Then place an ordinary light (represented by the light bulb) somewhere nearby.
If you want to have candles or chandeliers or other visible objects as your light source, you can simulate the candle in the off and on states by placing the "off" version of the candle (usually listed under World Objects > Statics > Lights in the Object Window of the CS) and parenting it to the Off switch, then place the "Fake" version of the same candle (usually found in the same place as the off version) and parent it to the "On" switch. Then place an ordinary light (represented by the light bulb) somewhere nearby.
Line 59: Line 73:
<pre>
<pre>
You can place a "light" version of the candle, found under World Objects > Light > Lights in the Object Window, however the more lights you place in a cell, the lower your framerate will be. It is best to place several "fake" candles and then only one real light to improve performance.  
You can place a "light" version of the candle, found under World Objects > Light > Lights in the Object Window, however the more lights you place in a cell, the lower your framerate will be. It is best to place several "fake" candles and then only one real light to improve performance.  
</pre>
<pre>
There is a bug in the lighting system when using objects as light sources that sometimes causes the lighting to not update properly after the object has been disabled. Again, using the "Fake" version of a light source combined with a regular "light bulb" light will work around this issue.
</pre>
</pre>


== How It Works ==
== How It Works ==
When you enter the game and approach the switch, the lights will be off. By activating the switch, which will be the "off" switch, it disables itself which automatically enables the "On" switch. The "On" switch can be activated repeating the process in reverse. Now by parenting all of your light sources to either switch, they will be enabled or disabled (turned on or off) according to which switch is enabled or disabled. Any number of light sources or other objects can be added to the switch simply by parenting them to the switches or daisy-chaining them together without ever editing the script. Also, you can select the switches and light sources in the render window and duplicate them (ctrl+d) and move the copies anywhere you wish and the copied lights will work with the copied switch without any additional editing.
When you enter the game and approach the switch, the lights will be off. By activating the switch, which will be the "off" switch, it disables itself which automatically enables the "On" switch. The "On" switch can be activated repeating the process in reverse. Now by parenting all of your light sources to either switch, they will be enabled or disabled (turned on or off) according to which switch is enabled or disabled. Any number of light sources or other objects can be added to the switch simply by parenting them to the switches or daisy-chaining them together without ever editing the script. Also, you can select the switches and light sources in the render window and duplicate them (ctrl+d) and move the copies anywhere you wish and the copied lights will work with the copied switch without any additional editing. Finally, you can set up multiple sets of switches to activate the same lights, for example a set of switches on each end of a long hallway, simply by parenting the second set of switches to the first "Off" switch.
 
[[Image:Lighttutgame1.jpg|thumb|left|The switch turned off in game]]
[[Image:Lighttutgame2.jpg|thumb|left|The switch turned on in game]]




[[Category:Getting Started]]
[[Category:World Objects]]
[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Scripting_Tutorials]]
Anonymous user