Double Glass Sliding Door

Written by Kitsune
//********************************************************
//This Script was pulled out for you by YadNi Monde from the SL FORUMS at http://forums.secondlife.com/forumdisplay.php?f=15, it is intended to stay FREE by it s author(s) and all the comments here in ORANGE must NOT be deleted. They include notes on how to use it and no help will be provided either by YadNi Monde or it s Author(s). IF YOU DO NOT AGREE WITH THIS JUST DONT USE!!!
//********************************************************








//1 prim double sliding glass door was made by Seagel Neville as public domain, Nov 2006
//
//Hello there,
//
//This is 1 prim double sliding glass door.
//Just put this script into a prim.
//You can open it by touching or bumping.
//For security, it is locked when you keep touching for a while. Just the owner can open it. It toggles.
//After being rezzed, you can modify scale, color, and alpha. I don't recommend you post a texture on it because it has complicated faces.


integer pitch = 5;
float TimeInterval = 3.0;
integer TouchFlag;
integer Holding;
integer SecureFlag;

Open()
{
    TouchFlag = TRUE;
    llTriggerSound("de7ac1a3-f31b-e1a4-5a21-5b9907921bf1", 1.0);
    integer i;
    for(i = 0; i < pitch + 1; i++)
    {
        llSetPrimitiveParams([PRIM_TYPE, 0, 0, <0.000000, 1.000000, 0.000000>,
        0.949000, <0.000000, 0.000000, 0.000000>, <(float)i/pitch, 1.000000, 0.000000>,
        <0.000000, 0.000000, 0.000000>]);   
    }
    llSetTimerEvent(TimeInterval);
}

Close()
{
    llSetTimerEvent(0);
    TouchFlag = FALSE;
    llTriggerSound("44f32d82-8604-1f29-37c9-a35baec646ee", 1.0);
    integer i;
    for(i = pitch - 1; i >= 0 ; i--)
    {
        llSetPrimitiveParams([PRIM_TYPE, 0, 0, <0.000000, 1.000000, 0.000000>,
        0.949000, <0.000000, 0.000000, 0.000000>, <(float)i/pitch, 1.000000, 0.000000>,
        <0.000000, 0.000000, 0.000000>]);
    }
}

TouchOpen()
{
    if(TouchFlag == FALSE)
    {
        Open();
    }
    else
    {
        Close();
    }
}

CollideOpen()
{
    if(TouchFlag == FALSE)
    {
        Open();
    }
    else
    {
        llSetTimerEvent(TimeInterval);
    }
}

Init()
{
    llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_GLASS, PRIM_SIZE, <2.0, 2.7, 0.01>,
    PRIM_TYPE, 0, 0, <0.0, 1.0, 0.0>, 0.949, <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>,
    PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_ROTATION, <0.7, 0, 0, 0.7>,
    PRIM_COLOR, ALL_SIDES, <0.0, 0.0, 0.5>, 0.5, PRIM_POSITION, llGetPos() + (<0, 0, 1.1> * llGetRot()),
    PRIM_TEXTURE, ALL_SIDES, "5748decc-f629-461c-9a36-a35a221fe21f",
    <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
}

default
{
    state_entry()
    {
        Init();
    }
    changed(integer change)
    {
        if(change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    touch(integer total_number)
    {
        if(llDetectedKey(0) == llGetOwner())
        {
            Holding++;
            if(Holding == 50)
            {
                if(SecureFlag == FALSE)
                {
                    llOwnerSay("Secured mode has been ON");
                    SecureFlag = TRUE;
                }
                else
                {
                    llOwnerSay("Secured mode has been OFF");
                    SecureFlag = FALSE;
                }
            }
        }
    }
    touch_end(integer total_number)
    {
        Holding = 0;
        if(SecureFlag == FALSE)
        {
            TouchOpen();
        }
        else
        {
            if(llDetectedKey(0) == llGetOwner())
            {
                TouchOpen();
            }
            else
            {
                llWhisper(0, "Sorry, this door is beeing locked.");
            }
        }
    }
    collision_start(integer num_detected)
    {
        if(SecureFlag == FALSE)
        {
            CollideOpen();
        }
        else
        {
            if(llDetectedKey(0) == llGetOwner())
            {
                CollideOpen();
            }
            else
            {
                llWhisper(0, "Sorry, this door is beeing locked.");
                llSleep(5.0);
            }
        }
    }
    timer()
    {
        Close();
    }
}