Here’s a little tutorial for ya! Lets build a club lighting system with a menu so you can change color, intensity, radius, falloff, glow, transparency, etc, etc, with just a few open source scripts.
Let’s start with a cup of coffee, and putting on some nice music….:-)
1. Download the next zip file.
2. Un-pack the zip file to a convenient place on your PC.
You will find 4 scripts and a texture in it.:
- Light System Spin script.txt : This script makes objects (lights) spin.
- Light System Spin control.txt : Turn the spin script on and off.
- Light System script-light.txt : This is the actual light script.
- Light System script-switch.txt : With this script, you can control the light script. You can change colors, light on/off, light radius, etc.
- a texture named ‘Beam.png’
3. Now create 4 new scripts in your inventory, and name them as above. Open each script on your PC with a text editor (Notepad, notepad ++) and copy&paste each script in to the ones in your inventory.
Oddy tip#873226: Create a new folder inside your Scripts folder, name it Light Scripts, and put all your light/lamp/glow etc scripts in there. I have a couple of folders in my scripts folder, named Texture scripts (for all scripts that handle textures), Sound scripts (For that ambient sound script), Door scripts, NPC scripts, etc.
4. Upload the beam.png texture.
I’m NOT going to show you how to build the most awesome light equipment there is to build, this is a mini-tutorial after all.
So rezz a simple cylinder, color it black, and set shine to ‘high’. This is the ‘Lamp’.
Hold down the SHIFT key on your keyboard, and drag the cylinder a bit upwards. A new black cylinder should appear. This will be a light beam! \o/ YAY!!
Now you have to change some things on this new prim.
– X=2.0, Y=2, and Z=20.0 meters.
– Hollow = 95 (or 99 if your viewer supports it.)
– Taper X=-0.750 Y=-0.750
and flip the texture on the vertical plane.
Now align the lamp prim and lightbeam prim so it looks like something in the picture.
With the light beam selected, hold down the SHIFT-key, and select the black lamp prim.
Hit CTRL-L to link the light beam and lamp prims together.
Rezz 2 other cylinders. These prims will be the buttons to control the lamp.
This is a very basic lighting set, you can go creative with the prims. Be sure that, when you link things up, always select the prim you want use a the center of the spinning motion last.
Also, do not link the buttons to the lamp.
Adding the scripts:
First we will add the scripts to the buttons.
Choose one of the button prims that you want to use for starting or stopping the light. Rename it to “Spin Button” or something much cooler.
Open the content tab of this prim and drag the “Light System Spin control script from your inventory to the content tab.
Open the script and look for the following lines (first two lines actually)
string title = “Spin Light 1″; // Title
integer channel = -100; // Main channel
The string title is what will be shown above the button. You can change this to your liking.
Integer channel is the channel (-100 in this case) on which the button communicates with the light beam. Change this to an unique channel. Remember this channel as you need to change the channel in the “Light System Spin script”.
Save the script.
Edit the other button. Rename it to “Light Button”. (or something cooler)
Add the “Light System script-switch” script to it. Open the script.
This time the lines you can (and should edit) are:
integer switchChannel = -101; // switch channel
You will find this line somewhere around line 68.
Again, change the channel to an unique channel number. In this case -101.
The next line you can edit, is a bit further down the script: Line 242
llSetText(“Light ring”, <1.0, 1.0, 1.0>, 1.0);
You can change the Light Ring part to something more useful.
Save the script.
Phew! We have done a lot work already. I’m not sure, but I think making these things in RL is less work! Let’s take a brake and do the harlem shake!
Ok, that was fun, but now back to the scripts.
Here is a little story about the channels we are using. In the spin button, we are using an unique channel, in my case -100. This means that every light that has the spin script in it, with the same unique channel (-100 in this case) will listen to the spin button. Lets say that I have 10 lamps with the spin script on channel -100, all the 10 lamps will start or stop spinning with the touch on the button. Same goes for the light script that listens to another unique channel (-101 in my case).
You can create multiple sets of lights using more buttons with new channels (-102, -18781, etc.)
(tip: make a notecard with names and channels for all your lights. In this case it would look something like this: name- Prim Button 1, Channel: -100, name- Prim Button 2, Channel -102, name- Light Button 1, Channel -101, name- Prim Button 2, CHannel -103, etc.)
Cool story he?
Anyway, back to the scripts!
let’s add the 2 main scripts now.
First select the light beam.
Open the edit window and tick the “Edit Linked” box.
Select the light beam prim, and open the content tab.
Drag the “Light System script-light” from your inventory to the content tab of the light beam.
Open the script and look for (around line number 48):
integer switchChannel = -104; // switch channel
Change the switchChannel number to the channel you choose in the “Light System script-switch” script. (in my case -101, remember the notecard?)
Save the script.
And the last thing we need to do is to add the “Light System Spin script”.
Should be easy by now!
If your edit window is still open, un-tick the “Edit Linked” box. If your edit window is closed, right-click on the light beam, and open the edit window.
Drag the “Light System Spin script” from your inventory to the content tab, and open it.
There are 2 things you can change (at the beginning of the script):
integer channel = -105; // Main channel
float speed = 2.5; // Rotation Speed
The channel is the same channel you used in the prim button script (NOTECARD!! In my case -100)
Float speed is the speed of the rotation, play with this. The higher the number, the faster it spins.
Save the script.
And we are ready to test this stuff! Touch the “Light button”. You should see a menu. Play with it!
Touch the spin button, check if you light is spinning!