Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Automatic Door close

Mia Jackson
Second Life Resident
Join date: 25 Oct 2004
Posts: 86
03-28-2006 11:59
I am trying to figure out how to add an automatic door close function to a door script that I have. Any help would be greatly appreciated. :) Here is the script below:

CODE

default
{
on_rez(integer rez)
{
llResetScript();
}

state_entry()
{
llListen(0,"",llGetOwner(),"lock");
}

touch_start(integer total_number)
{
llTriggerSound("Door open", 0.5);
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state open;
}

listen(integer channel, string name, key id, string message)
{
if (message == "lock")
{
state locked;
}
else if (message == "")
{
}
}
}

state open
{
state_entry()
{
}

touch_start(integer total_number)
{
llTriggerSound("Door close", 0.5);
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state default;
}
}

state locked
{
state_entry()
{
llSay(0, "Door Locked.");
llListen(0,"",llGetOwner(),"unlock");
}

touch_start(integer total_number)
{
llSay(0, "Sorry "+llDetectedName(0)+" this door is locked.");;
}

listen(integer channel, string name, key id, string message)
{
if (message == "unlock")
{
llSay(0, "Door Unlocked.");
state default;
}
else if (message == "")
{
}
}
}
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
03-28-2006 12:08
This should work, I think. I haven't tried cleaning up anything else in the script, just added a close on a timer.

CODE
closeDoor()
{
llTriggerSound("Door close", 0.5);
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
}

default
{
on_rez(integer rez)
{
llResetScript();
}

state_entry()
{
llListen(0,"",llGetOwner(),"lock");
}

touch_start(integer total_number)
{
llTriggerSound("Door open", 0.5);
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state open;
}

listen(integer channel, string name, key id, string message)
{
if (message == "lock")
{
state locked;
}
else if (message == "")
{
}
}
}

state open
{
state_entry()
{
llSetTimerEvent(30); // Or however long you want the door to stay open for
}

touch_start(integer total_number)
{
closeDoor();
state default;
}

timer()
{
llSetTimerEvent(0);
closeDoor();
state default;
}
}

state locked
{
state_entry()
{
llSay(0, "Door Locked.");
llListen(0,"",llGetOwner(),"unlock");
}

touch_start(integer total_number)
{
llSay(0, "Sorry "+llDetectedName(0)+" this door is locked.");;
}

listen(integer channel, string name, key id, string message)
{
if (message == "unlock")
{
llSay(0, "Door Unlocked.");
state default;
}
else if (message == "")
{
}
}
}
Feynt Mistral
Registered User
Join date: 24 Sep 2005
Posts: 551
03-28-2006 12:10
For a sense of balance and readability, you should also move the door open rotations to its own function as well.
_____________________
I dream of a better tomorrow in SL!
You should too. Visit, vote, voice opinions.
Support CSG! Tell LL how much it would mean to subtract one prim from another!
Prim Animation! Stop by and say something about it, show your support!
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
03-28-2006 12:52
From: someone
For a sense of balance and readability


:) :)

I agree.