My script so far:
// circular sliding door script
// SETTINGS
float TIMER = 10.0; // seconds before closing door
// set to 0 to disable automatic closing
vector gPos; // door position (objects move a tiny amount away
// from their position each time they are rotated,
// thus we need to workaround this by resetting
// the position after rotating)
door(integer open)
{
if (open) {
vector eul = <0,0,20>; //degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot(eul); //convert to quaternion
llSetRot(quat); //rotate the object
}
else { // close
vector eul = <0,0,-20>; //degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot(eul); //convert to quaternion
llSetRot(quat); //rotate the object
}
}
default // first time startup
{
state_entry()
{
llSetPos(llGetPos());
llSetObjectName("Sliding Door"
;llSetObjectDesc("with circular sliding action"
;gPos = llGetPos(); // remember where we're supposed to be
llSay(0, "door is initialized"
;door(TRUE);
state closed;
}
}
state closed { // door is closed
on_rez(integer start_param) {
gPos = llGetPos();
}
state_entry() {
door(FALSE);
}
touch_start(integer total_number) {
state open;
}
moving_end() { // done moving me around, store new position
gPos = llGetPos();
}
}
state open { // door is open
on_rez(integer start_param) {
gPos = llGetPos();
state closed;
}
state_entry() {
llSetTimerEvent(TIMER);
llSetPos(gPos); // rotation drift workaround
door(TRUE);
}
touch_start(integer num) {
state closed;
}
timer() { // auto-close
state closed;
}
moving_start() { // close when being moved
state closed;
}
state_exit() {
llSetTimerEvent(0);
}
}