A B C D E F G I J K L M N O R S T U V W

Crystalline’s door script for non root prims and meshes.  Some modifications were made by Brayla Sana after she learned some scripting. Works both in SL and Opensim.

//FREE SCRIPTS - TESTED AND WORKING ON KITELY

//  If you paid for this script, you were ripped off.
//  You may use in your creations.
//  You may not sell it as a script or in a script collection.

/* Crystaline's door script v1.1

   License: This script may be modified and copied. If you modify it,
            please add a comment below in the modifications section
            explaining the modification along with your name.
            
            You may not resell or distribute this script except when it
            is included as part of a product you have created.

   Use:     This door script is intended for use on linked non-root prims -
            anotherwards, doors that are attached to something (such as a
            door frame or wall) and are not the root prim of the link set.
            All customizable values will be read in from a notecard.

   Modifications:
       If you modify this script from the original, please add your name
       and a comment explaining the modification to this section.

        Modified by Brayla Sana:
        
        * I added physics changes to the open doors, 
          so now open doors do not block you.   
        * I created 3 versions, one for each axis.

*/

// The name of the notecard that contains the door settings
string NotecardName = "Door Settings";

// ------------------------------------------------------------------------------------
// Default values for settings that are read from the notecard. These will be
// overwritten by things in the notecard.
// ------------------------------------------------------------------------------------

// The amount to rotate the door in degrees
float   DoorRotation;

// The number of seconds before auto-closing the door, or 0 to disable
float   AutoCloseTime;

// The set to link this door with. All doors that are linked to this one and share
// the same DoorSet will open and close together. Can be any valid integer, setting
// it to -1 will disable linking with other doors
integer DoorSet;

// The sound to play when the door opens. This can be a UUID or the name of a
// sound in the prim's inventory. Set to empty string to disable.
string  OpenSound;

// The sound to play when the door closes. This can be a UUID or the name of a
// sound in the prim's inventory. Set to empty string to disable.
string  CloseSound;

// The volume to play the door opening sound at from 0.0 to 1.0
float   OpenVolume;

// The volume to play the door closing sound at from 0.0 to 1.0
float   CloseVolume;

// ------------------------------------------------------------------------------------




// Script implementation

// Whether the door is currently open
integer DoorOpen = 0;

// The original position and rotation of the door
vector   OriginalPosition;
rotation OriginalRotation;

// The amount of rotation to apply when opening the door, derived from DoorRotation
rotation RotationOffset;

// The key of the last notecard that was read
key NotecardKey;

// The notecard line currently being read
integer CurrentLine;

// The key to use for dataserver queries
key QueryKey;

// Toggles the open state of the door (opens or closes it)
ToggleDoor()
{
    if (DoorOpen)
    {
        CloseDoor();
    }
    else
    {
        OpenDoor();
    }
}

// Opens the door
OpenDoor()
{
    DoorOpen = 1;
    llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, 1]);  //Makes the door "Phantom" when open
    llSetTimerEvent(AutoCloseTime);
    OriginalPosition = llGetLocalPos();
    OriginalRotation = llGetLocalRot();
    if (OpenSound != "") llTriggerSound(OpenSound, OpenVolume);
    llSetLocalRot(RotationOffset * OriginalRotation);
}

// Closes the door
CloseDoor()
{
    DoorOpen = 0;
    llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, 2]);  //Makes the door "Solid" when closed
    llSetTimerEvent(0.0);
    if (CloseSound != "") llTriggerSound(CloseSound, CloseVolume);
    llSetLocalRot(OriginalRotation);
    llSetPos(OriginalPosition);
}

// Read the script setup from the notecard if needed
ReadSetup()
{
    key ncKey = llGetInventoryKey(NotecardName);
    if (ncKey != NotecardKey)
    {
        // If the key is not the same as last time, it means either the
        // notecard has changed, or we just have not read it yet
        NotecardKey = ncKey;
        CurrentLine = 0;
        llSetText("* Loading *", <1.0, 0.0, 0.0>, 1.0);
        QueryKey = llGetNotecardLine(NotecardName, CurrentLine);
    }
}

// Sets all values to their defaults
SetDefaults()
{
    DoorRotation = 90;
    AutoCloseTime = 15;
    DoorSet = -1;
    OpenSound = "";
    CloseSound = "";
    OpenVolume = 1.0;
    CloseVolume = 1.0;
}

// Perform any setup needed after the notecard has been read
PerformSetup()
{
//  Default is X axis.  replace with commented line for Y or Z axis.
    RotationOffset = llEuler2Rot(<DoorRotation * DEG_TO_RAD, 0, 0>);    //  rotates on X axis
//    RotationOffset = llEuler2Rot(<0, DoorRotation * DEG_TO_RAD, 0>);  //  rotates on Y axis
//    RotationOffset = llEuler2Rot(<0, 0, DoorRotation * DEG_TO_RAD>);  //  rotates on Z axis

    llSetText("", <1.0, 1.0, 1.0>, 1.0);
}

// Parse a line from the notecard and store anything we need from it
ParseLine(string line)
{
    if (llStringTrim(line, STRING_TRIM) == "")
    {
        // Skip empty lines
        return;
    }
    if (llGetSubString(llStringTrim(line, STRING_TRIM_HEAD), 0, 0) == "#")
    {
        // Lines whose first non-whitepace character is a # are comments
        return;
    }
    list splitLine = llParseString2List(line, ["="], [""]);
    if (llGetListLength(splitLine) != 2)
    {
        llOwnerSay("Skipping line " + (string)CurrentLine + " in setup notecard because it could not be parsed:\n" + line);
        return;
    }
    
    // It appears we have a variable to set on this line, so let's try it
    string varName = llStringTrim(llList2String(splitLine, 0), STRING_TRIM);
    string varValue = llStringTrim(llList2String(splitLine, 1), STRING_TRIM);
    if (varName == "DoorRotation")
    {
        DoorRotation = (float)varValue;
    }
    else if (varName =="AutoCloseTime")
    {
        AutoCloseTime = (float)varValue;
    }
    else if (varName =="DoorSet")
    {
        DoorSet = (integer)varValue;
    }
    else if (varName =="OpenSound")
    {
        OpenSound = varValue;
    }
    else if (varName =="CloseSound")
    {
        CloseSound = varValue;
    }
    else if (varName =="OpenVolume")
    {
        OpenVolume = (float)varValue;
    }
    else if (varName =="CloseVolume")
    {
        CloseVolume = (float)varValue;
    }
}

default
{
    state_entry()
    {
        // Perform setup once to ensure good defaults in case there
        // is a problem reading the notecard
        SetDefaults();
        PerformSetup();
        
        // Read the notecard to setup the script
        NotecardKey = NULL_KEY;
        ReadSetup();
    }
    
    on_rez(integer param)
    {
        llResetScript();
    }
    
    touch_start(integer total_number)
    {
        if (DoorSet == -1)
        {
            // We are not part of a set, so just toggle ourself
            ToggleDoor();
        }
        else
        {
            // We are part of a set that opens/closes together, send a toggle
            // message. We will also get the message ourself.
            llMessageLinked(LINK_SET, DoorSet, "ToggleDoor", NULL_KEY);
        }
    }
    
    moving_end()
    {
        // If someone moves the door, assume that it is closed and is in its
        // new closed position. This event is not dependable and probably will
        // not fire most of the time, but we don't really care in this case.
        if(DoorOpen)
        {
            DoorOpen = 0;
            llSetTimerEvent(0.0);
        }
    }
    
    timer()
    {
        CloseDoor();
    }
    
    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == DoorSet && str == "ToggleDoor")
        {
            ToggleDoor();
        }
    }
    
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY) 
        {
            SetDefaults();
            ReadSetup();
        }
    }
    
    dataserver(key query_id, string data)
    {
        if (query_id == QueryKey)
        {
            if (data == EOF)
            {
                llOwnerSay("Door Ready");
                PerformSetup();
            }
            else
            {
                ParseLine(data);
                ++CurrentLine;
                QueryKey = llGetNotecardLine(NotecardName, CurrentLine);
            }
        }
    }
}

Settings Notecard:

# These settings will be read and used by the door script to configure its options. Just modify the
# settings and save them. Any empty lines or lines with a # at the beginning will be ignored by the
# script. If you put a # in front of a setting (or remove a setting), it will revert to its default value.

# I recommend making a backup of this notecard (or the object containing it) before you modify it,
# in case something gets messed up.

# The amount to rotate the door when it opens (in degrees, 0 - 360)
DoorRotation = 90

# The number of seconds before auto-closing the door, or 0 to disable
AutoCloseTime = 15

# The set to link this door with. All doors that are linked to this one and share
# the same DoorSet will open and close together. Can be any valid integer, setting
# it to -1 will disable linking with other doors.
DoorSet = -1

# The sound to play when the door opens. This can be a UUID or the name of a
# sound in the prim's inventory. Set to empty string to disable.
OpenSound = 

# The sound to play when the door closes. This can be a UUID or the name of a
# sound in the prim's inventory. Set to empty string to disable.
CloseSound = 

# The volume to play the door opening sound at from 0.0 to 1.0
OpenVolume = 1.0

# The volume to play the door closing sound at from 0.0 to 1.0
CloseVolume = 1.0