Shortnote

This is a quick door script that activates on touch, it uses the description field to set the open and closed states of the door. For example, the following text in the door's description:

closed=<0, 0, 45>&open=<0, 0, 135>

will set the closed and open degrees. The door must be changed so that its median axis is placed on the margin of the door.

Code

///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueGet(string var, string kvp) {
    list dVars = llParseString2List(kvp, ["&"], []);
    do {
        list data = llParseString2List(llList2String(dVars, 0), ["="], []);
        string k = llList2String(data, 0);
        if(k != var) jump continue;
        return llList2String(data, 1);
@continue;
        dVars = llDeleteSubList(dVars, 0, 0);
    } while(llGetListLength(dVars));
    return "";
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
///////////////////////////////////////////////////////////////////////////
vector wasStringToVector(string in) {
    list v = llParseString2List(in, ["<", ",", ">"], []);
    return <llList2Float(v, 0), llList2Float(v, 1), llList2Float(v, 2)>;
}
 
default
{
    state_entry() {
        vector open = wasStringToVector(wasKeyValueGet("open", llGetObjectDesc()));
        vector closed = wasStringToVector(wasKeyValueGet("closed", llGetObjectDesc()));
        if(llVecDist(llRot2Euler(llGetRot())*RAD_TO_DEG-open, llRot2Euler(llGetRot())*RAD_TO_DEG-closed) < 45) {
           state closed;
        }
        state open;
    }
}
 
state open {
    state_entry() {
        llSetTimerEvent(5);
        llSetRot(llEuler2Rot(wasStringToVector(wasKeyValueGet("open", llGetObjectDesc()))*DEG_TO_RAD));
    }
    touch_start(integer num) {
        state closed;
    }
    timer() {
        state closed;
    }
}
 
state closed {
    state_entry() {
 
        llSetRot(llEuler2Rot(wasStringToVector(wasKeyValueGet("closed", llGetObjectDesc()))*DEG_TO_RAD));
    }
    touch_start(integer num) {
        state open;
    }
}