Skip to content

Freebie: Everybody needs doors.

March 30, 2011

I recently learned that some of the students in JokaydiaGrid are having trouble with scripted doors.  Some of the freely available scripts out there are a little confusing, so I decided to dust off and clean up the Radegast-friendly door that I use and make it available to everyone.  A text-client friendly door renames itself according to whether it is open or closed, so people using Radegast or a similar client can see what’s happening with it. (Using messages in local chat is just spammy.)

You can grab a free copy from The Mad Scientist’s Workshop in Callahania, or you can make your own from the instructions and script below.

To make your own, create a “Box” prim, and set the dimensions to

X: 3.000

Y: 0.100

Z: 3.000

Box Prim and Edit Screen

Now, look at the lowest item in the right hand column of the Build/Edit tool.  “Slice Begin and End”.  We’ll use that.  (Some use Path Cut, and that is what I used for the freebie in the Workshop.  Either will work, but Slice is slightly easier.)

Set the “B” (for Beginning) value of Slice to 0.500

The door, with slice B set to 0.5

Why do we do this?  Well, a door rotates from the edge, where the hinge is.  Prims rotate from the center of the prim.   Using the Path Cut or Slice feature, we pare away enough of the prim that the center is at the edge.

Next, add the script (which you will find at the end of this post), and take your new door into your inventory. Rez out a new copy, and let’s set it up!

Whenever you rez out the door, it is going to wipe the description and rename itself to “Door (not set up yet)”.  It will also say to the owner:

Door (not set up yet): This door has not been set up yet. To start, set the door up how you want it when it is closed, and say “closed” in local chat.  Then I’ll prompt you for the next step.

For now, let’s just use the example above.  Leaving it just like it is, I say

Talvin Muircastle: closed

and it replies:

Door (not set up yet): Good! Now, rotate the door to the position you want it in when it is open, and say “open” in local chat when you are ready.

So, we rotate the door around like so:

Door rotated into "open" position.and I say

Talvin Muircastle: open

The door stores the two rotation values in the object description (LSL scripts can only make permanent records of things by using workarounds like this).  The door closes itself.

The door, ready to be textured.Door (closed): Your door is now ready for use.

Now you can click on the door to open it!

If you are comfortable editing the settings inside the script, you can change the names for open and closed (but please remember those who must rely on text-based clients!), and you can set the amount of time it will remain open before closing itself automatically.  You can also disable auto-close entirely.  If you add a sound file to the door and reset the script, it will play that file when opening or closing.  And, as with all my freebies, the script is open-sourced under the Creative Commons license: feel free to experiment. However, the line just after “//END SETTINGS” is not a joke. 🙂

Here’s the script:

//Copyright 2011 by Talvin Muircastle @ JokaydiaGrid.  Licensed under the Creative Commons 3.0 Attribute/Share-Alike License.
//What that means: you can use it, and you don't owe me a penny for it.  BUT, you can't lie and say you created it: I did!  And if you make changes to it, you gotta share them just like I am sharing this with you. 

//SETTINGS
float time=20.0; //How long in seconds the door will stay open. This is a "float", which means it needs a decimal point. Set 0.0 to disable this.
string open="Door (open)"; //The name of the door when it is open.  We rename it so people who use text clients like Radegast can tell if the door is open or not.
string close="Door (closed)"; //Just like for open.
float volume=1.0; //The volume of the door sound when you use the door.  From 0.0 to 1.0 (lowest to loudest).  Ignore this if you aren't using a sound.
//END SETTINGS

//YOU REALLY DON'T WANT TO MESS WITH ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING.  TALVIN GIVES THIS SCRIPT AWAY FOR FREE.  FOR FIXING THINGS WHEN PEOPLE IGNORE THIS LINE, HE CHARGES BY THE HOUR.

integer setup=FALSE;
rotation orot;
rotation crot;
string sound="";
integer l;
integer o=FALSE;
list rots;

op()
{
    if (sound !="")
    {
        llPlaySound(sound, volume);
    };
    llSetRot(orot);
    o=TRUE;
    llSetObjectName(open);
    if (time != 0.0)
    {
        llSetTimerEvent(time);
    };
}

cl()
{
    if (sound !="")
    {
        llPlaySound(sound, volume);
    };
    llSetRot(crot);
    o=FALSE;
    llSetObjectName(close);
    llSetTimerEvent(0);
}

default
{
    on_rez(integer start)
    {
        llSetObjectDesc("");
        llResetScript();
    }
    
    state_entry()
    {
        string test=llGetObjectDesc();
        if (test=="")
        {
            llSetObjectName("Door (not set up yet)");
            llOwnerSay("This door has not been set up yet. To start, set the door up how you want it when it is closed, and say \"closed\" in local chat.  Then I'll prompt you for the next step.");
            l=llListen(0, "", llGetOwner(), "closed");
            
        }
        else
        {
            setup=TRUE;
            rots=llCSV2List(test);
            crot=llList2Rot(rots,0);
            orot=llList2Rot(rots,1);
        };
        integer s=llGetInventoryNumber(INVENTORY_SOUND);
        if (s)
        {
            sound=llGetInventoryName(INVENTORY_SOUND, 0);
        };
    }
    
    touch_start(integer n)
    {
        if (setup)
        {
            if (o)
            {
                cl();
            }
            else
            {
                op();
            };
        }
        else
        {
            llSay(0, "The owner has not set up this door yet!");
        };
    }
    
    listen(integer chan, string name, key id, string msg)
    {
        if (msg=="closed")
        {
            llListenRemove(l);
            rots=rots + llGetRot();
            llOwnerSay("Good! Now, rotate the door to the position you want it in when it is open, and say \"open\" in local chat when you are ready.");
            l=llListen(0, "", llGetOwner(), "open");
        }
        else
        {
            llListenRemove(l);
            rots=rots + llGetRot();
            llSetObjectDesc(llList2CSV(rots));
            setup=TRUE;
            crot=llList2Rot(rots,0);
            orot=llList2Rot(rots,1);
            cl();
            llOwnerSay("Your door is now ready for use.");
            llResetScript();
        };
    }
    
    timer()
    {
        cl();
    }
}
Advertisements
One Comment leave one →
  1. thnidu permalink
    March 31, 2011 11:25 pm

    That is *neat*!.

    DOOR KIT. ASSEMBLY REQUIRED. ONCE YOU DO THE FIRST COUPLE OF STEPS, THE DOOR WILL TELL YOU WHAT TO DO NEXT.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: