Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Simple but fun "door" scripts

Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
09-16-2006 14:06
These are very basic scripts to anyone with scripting skills, but since at least one person liked the “Phantom Alpha Door or Wall” that ArchTx posted I thought I would throw these out. They are “door” type scripts that work in different ways.

I made these one day just screwing around with llSetPrimativeParam commands and didn't think much of it at the time. But I suppose they might be useful to those that can't write scripts but know how to use ones that are already created. Anyway, here they are for what they are worth. :)


The first one will open a hole in a cube on command. To use it you rez a cube and them make it hollow so you can see where the opening will be. Then position it so that the opening is facing the direction you want, such as a tunnel through a wall or maybe a trap door through a floor/ceiling . Once you have it set, set the hollow back to zero and put this script in it. The owner can give it commands on channel 10. A simple open and close command is what I have put in, but you can change the activation words to whatever you like. On command the hole will open or close to give you the effect of a secret door. This script is set to work with a cube right now, but could easily be adapted to different prim shapes.

CODE
 
default
{
state_entry()
{
llOwnerSay("ready");
llListen(10,"","","");
}

listen( integer channel, string name, key id, string message )
{
key owner = llGetOwner();
if(message == "open" & id == owner | message == "open" & name == "switch")
{
llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]);
llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, 16, <0.0, 1.0, 0.0>, 0.95, <0.0, 0.0, 0.0>, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>]);
}
if( message == "close" & id == owner | message == "close" & name == "switch" )
{
llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, 16, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>]);
llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]);
}
}
}




The second script will make the cube shrink down and vanish on command, giving you the effect of the door shrinking to nothing. Just plonk in into a cube and position it where you like. It works on the same channel and is set to the same activation words, both of which you can change of course. You can make variations on this as well, such as one I did where I played with the Alpha settings in the PRIM_COLOR line to make it partially trans and then added a PRIM_POINT_LIGHT, TRUE, to the close part to make it glow to give the effect of a force field barrier (and of course a PRIM_POINT_LIGHT, FALSE line to the open part to make it not glow when open/off).

CODE
 
default
{
state_entry()
{

llOwnerSay("ready");
llListen(10,"","","");
}

listen( integer channel, string name, key id, string message )
{
key owner = llGetOwner();
if(message == "close" & id == owner | message == "close" & name == "switch")
{
// llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); // uncomment out this line for force field effect
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1, 0, 0>, 1.00]); // change the 1.00 to 0.75 for the force field effect.
llSetPrimitiveParams([PRIM_SIZE, <4, 4, 0.1>]); // change this vector to whatever size you want the door to be when closed.
//llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 0, 0>, 1.0, 10.0, 0.75]); // uncomment out this line for force field effect
llSetPrimitiveParams([PRIM_PHANTOM, FALSE]);
//llSay(0,"Access now restricted"); // uncomment out this line for force field effect
}
if(message == "open" & id == owner | message == "open" & name == "switch")
{

llSetPrimitiveParams([PRIM_SIZE, <0.01, 0.01, 0.01>]);
//llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 0, 0>, 1.0, 10.0, 0.75]); // uncomment out this line for force field effect
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1, 1, 1>, 0.0]);
//llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); // uncomment out this line for force field effect
llSetPrimitiveParams([PRIM_PHANTOM, TRUE]);
//llSay(0,"You may enter"); //// uncomment out this line for force field effect
}
}
}



Here is a simple script you can put in a prim to act as a switch for the doors, so that persons other than the owner can use them:

CODE
 default
{
state_entry()
{
llSay(0, "switch ready");
llSetObjectName("switch");// the object must be named "switch" for the door to listen to it, this renames it automatically for you.
}

touch_start(integer total_number)
{
llShout(10, "open"); // change "open" to "close" for the switch that will close the door
}
}



Edit 17Sept06 - I tightened up the listen functions to make them more efficient because I saw this in the wiki:

From: LSL Wiki
To listen on a single channel, for both chat from the owner and from an object with a certain name, (or any other combination of logic) the best option is to use a single llListen function and an if-else in the listen event.
_____________________
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
09-16-2006 14:38
/15/2e/137947/1.html
_____________________
i've got nothing. ;)
Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
Other thoughts
09-20-2006 10:42
The script doesn't have to make a round hole in the prim the script is in. If you want you can change the shape of the hole using the llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, 16, ect... line.

The 16 in that line is what tells it to make a round hole. If you wanted it to be a square hole just change the 16 to a 32. Here is a list of the shape of hole and the numbers used to get it:

PRIM_HOLE_DEFAULT = 0 = default (matches the prim type: square for box, circle for cylinder, etc.)
PRIM_HOLE_SQUARE = 32 = square
PRIM_HOLE_CIRCLE = 16 = circle
PRIM_HOLE_TRIANGLE = 48 = triangle

This is cut and pasted from the Wiki. Here is the URL for the page on llSetPrimativeParams :

http://www.lslwiki.com/lslwiki/wakka.php?wakka=llSetPrimitiveParams

I am pretty sure that instead of using the number you can just type the PRIM_HOLE_SQUARE or PRIM_HOLE_CIRCLE in it's place and it will work, but the numbers are easier.

So as you can see, you can use this script to shape any prim into pretty much anything you want, so have fun and experiment!
_____________________
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
09-21-2006 09:29
Thanks Vares, examples like this are a huge help to people who are just learning scripting, such as myself.

For instance I did not know that you could set a script to listen to a specific named object. That could be useful.
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
River Ely
Fabulist and working hard
Join date: 12 Sep 2006
Posts: 32
Thanks Varez
09-21-2006 15:15
I agree wholeheartedly with these comments, "examples like this are a huge help to people who are just learning scripting, such as myself".

I am a php user and enjoy using MySql. Simple, quality, descriptive, easy to reproduce examples are the way to go, I have learned so much reading the Forums here.

Kaela
AKA
River

Editd to remove typos's...
Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
09-24-2006 12:27
That is basically how I learned myself. I am entirely self taught on LSL. I started by just playing with the freebie scripts you can find in world and in these forums. Then I found the LSL Wiki and that was a huge help. I also have a couple of good friends in world that are programmers in rl for a living (Hi Newgy!) and they really helped me out a lot too. If I was confused by the wiki or something I read here they were always ready to help me understand it. If you really want to learn LSL then I recommend you find a mentor in world to help you with those tricky little things that people don't think about explaining until they come up (and those times when the wiki just isn't quite clear enough for you).

I definitely found the example scripts in the wiki and the ones posted here to be very, very helpful in learning LSL. When I was new I always thought it would be fun to have a script that could be used for secret doors and such, but could never find one. So that's why I decided to post mine.

Interestingly enough my script was inspired by a script posted here, Ceera's Iris opening door script. I was playing with it one day but it wasn't doing quite what I wanted. So looking at her script I was inspired to write mine. I made mine voice activated so you can have control over who can use it with the switch, but you can convert mine to touch activated by melding my script with Ceera's. I guess I might have to post a few of the other scripts I have written as learning aids for myself, since they might help others as well.

One of my favorite things to do in my spare time is to read the wiki. I will go to the main menu and then bring up the page that lists all the Functions available. Then I just scan through the list until something sounds interesting and then read all about that particular funciton. After I've read all about it and looked at the samples I will log in and play with the sample scripts until I am satisfied I understand that particular function. Not only do I learn a lot doing that, but I get some fun ideas for things to make/script.

By the way, there are still tons of other uses for my scripts than just doors. Either would make a nice wall or floor safe to hide things in. Say you have one of those radios on you land that changes the music when you touch it but you don't want just anyone messing with it. Well, put either of my scripts in a prim on the floor or wall. Then open it and position the radio inside the wall. When closed the radio will be hidden from view but you can access it very easily by just giving the open command. Sure you could do this without the scripts and just move your camera into the wall in order to click the radio, but that can be a real pain sometimes because the camera can do some weird things when going into prims. With these scripts you can hide it and still access it very easily.

I am a bit of trickster and love to prank my friends in world. So I put the script that makes the prims shrink down and vanish into the floor of my sky platform. So now I can stand on the one safe spot and then make the floor vanish, dropping my friends to their doom. :D

This wasn't just a way to prank my friends though, it was a learning experience as well. I had to put a copy of the script in each prim of the floor, six in this case, and I didn't want six different listen commands lagging things up. So I used this as a way to learn how to do linked messages. Only the script in the root prim listens to me, the others all listen to the script in the root prim. See if you can convert it too. :) Linked messages
_____________________
LeVey Palou
Registered User
Join date: 31 Aug 2006
Posts: 131
open door touch commands?
10-06-2006 13:15
I am script stupid so I will ask, is it possible to make the door open/close on touch rather than chat command? i would like to put a button on the "inside of dwelling", where it would be used to keep people out. hopefully its me on the inside activating the button....lol


any thoughts on this anyone?

ty
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
10-06-2006 22:18
The thought had just crossed my mind, since I love playing with textures and alpha masks lately, I've been wanting to try anything with the llSetTextureAnim command..

There could be some pretty kewl doors made that simply animate opening up and turning phantom, then animate closing and turning solid.

I could imagine the wide variety of doors that would be possible with this. Though I still have to figgure out that one little cavette to the llSetTextureAnim command..

er.. scratch that, i could have sworn that thing read that only one animation could be run per sim, but it no reads per prim. so, Kewl. I could have some fun with that.
Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
10-09-2006 18:11
From: LeVey Palou
I am script stupid so I will ask, is it possible to make the door open/close on touch rather than chat command? i would like to put a button on the "inside of dwelling", where it would be used to keep people out. hopefully its me on the inside activating the button....lol


any thoughts on this anyone?

ty


If I understand what you are saying here, you can do that with the scipts as they are presented in the OP. The third script is for a switch that you can use. Basically when you touch the switch it just says the command for you on the correct channel. As it's written now, anyone can use it. But it would be easy to throw in an IF/ELSE function to make it so only the owner can use it.

However, this script can easily be turned into a touch activated only script. In fact, I have already done that for some "magic chests" that I made, one for each of the types of "doors" above. (And one with a traditional rotating lid.) I was too lazy to write the touch activated parts though, so what I did was just blend my scripts with Ceera's Iris Opening Door script. (I regularly cut and paste my old scripts together to make new ones, it's so much easier!)

I simply took Ceera's script and replaces the llSetPrimitiveParams in both the touch start states with the llSetPrimitiveParams stuff from my script. As long as you put the llSetPrimitiveParams to open the door in the right state in Ceera's script (and the closing stuff in the other state) it works perfectly.

I'm not going to post the script since I don't really have Ceera's permission to change her script and distribute it publically, but you should be able to do the changes on your own for your own private use.
_____________________
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-10-2006 06:58
From: Vares Solvang
One of my favorite things to do in my spare time is to read the wiki.


V, GET OUT MORE!!!!!!!! (Waves at V)

From: LeVey Palou
I am script stupid so I will ask, is it possible to make the door open/close on touch rather than chat command? i would like to put a button on the "inside of dwelling", where it would be used to keep people out. hopefully its me on the inside activating the button....lol


any thoughts on this anyone?


Lost of variations and implementations of this are already available.

The following is a very simple door script that incorporates a lock.
I think it used the deluxe door script by Ezhar Fairlight as a start point.

CODE

list names = ["your name here"];

default
{
state_entry()
{
llSay(0, "Auto Door 1.0");
state open;
}
}

state open
{

touch_start(integer total_number)
{
string name = llToLower(llDetectedName(0));
integer iIndex = llListFindList(names, [ name ]);
if(iIndex >= 0)
{
llTriggerSound("Door", 0.5);

rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,(-PI/4)>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state closed;
}
else
{
llTriggerSound("bell", 0.7);
llWhisper(0,"sorry " + name + ", but this door is locked!");
}
}
}

state closed
{
state_entry()
{
llSleep(20.0);
llTriggerSound("Door", 0.5);

rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,(PI/4)>);
rot = delta * rot;
llSetRot(rot);

llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state open;
}
}


As it stands it requires sounds called "Door" and "Bell" or it will generate script errors.