Sliding Door

integer PFuncCallArgs = 56;


integer isOpen = FALSE;
string open_sound = "sliding door";
string close_sound = "sliding door";

integer autoCloseTime = 30; // seconds (-1 for no auto-close)

float steps = 4; // no. of steps for open movement (1 for smoothest/fastest)

vector scale;
vector position;
float y;


open()
{
    if (isOpen) return;

    if (autoCloseTime > 0)
        llSetTimerEvent(autoCloseTime);
    
    if (open_sound != "")
        llPlaySound(open_sound,0.5);

    position=position+<0,y,0>;
    llSetPos(position);    
    isOpen = TRUE;
}


close()
{
    llSetTimerEvent(0);
    
    if (!isOpen) return;

    position=position-<0,y,0>;
    llSetPos(position);

    if (close_sound != "")
        llPlaySound(close_sound,0.5);
        
    isOpen = FALSE;
}



callRemoteFuncP(string funcName, list args)
{
    list extArgs = [funcName] + args;
    string extArgStr = llDumpList2String(extArgs, "-=-");
    llMessageLinked( LINK_THIS, PFuncCallArgs, extArgStr, "" );
}



handleFuncCall(string funcName, list args)
{
    if (funcName=="open" || (funcName=="opendoor"))
        open();
    else if (funcName=="close" || (funcName=="closedoor"))
        close();
}






default
{
    state_entry()
    {
        scale=llGetScale();
        position=llGetPos();
        y=scale.y;        
    }

    timer()
    {
        close();
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        if ((num == PFuncCallArgs)) {
            
            list fullArgs = llParseStringKeepNulls( str, ["-=-"], [] );
            str="";
            string funcName = llList2String(fullArgs,0);
            
            list args = llList2List(fullArgs, 1, -1);
            fullArgs = [];

            handleFuncCall(funcName, args);
        }
    }
    

    touch_start(integer total_number)
    {
        key agentKey = llDetectedKey(0);
        string agentName = llDetectedName(0);
        
        if (!isOpen)
            callRemoteFuncP("checkauth",[agentKey,agentName,"open"]);
        else
            callRemoteFuncP("checkauth",[agentKey,agentName,"close"]);
    }
}