Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making a door listen to chat commands

Lunar Tripsa
Registered User
Join date: 2 Feb 2007
Posts: 38
10-02-2008 11:34
I'm trying to make a door listen to chat commands on channel 910, but I've never worked with states in this manner, so I have no idea how to edit this script to make it listen to 910. I'd also like it to not respond to touch. Using a ingle command to make it move I think would work better so it doesn't get stuck in the wrong position. So if I called Melon it would open then If I called Melon again it would close.

I think this script is by Hank Ramos and if so thanks very much!

integer doorSteps = 4;
integer reversed = FALSE;

rotateDoor(integer Open)
{
rotation rot = llGetRot();
rotation delta;
integer x;

if (reversed) {Open = !Open;};

if (Open)
{
delta = llEuler2Rot(<0, 0, PI/(doorSteps * 2)>;);
}
else
{
delta = llEuler2Rot(<0, 0, -PI/(doorSteps * 2)>;);
}

for (x = 0; x < doorSteps; x++)
{
rot = delta * rot;
llSetRot(rot);
llSleep(0.03125/doorSteps);
}
}

default
{
state_entry()
{
state closed;
}
}

state closed
{

touch_start(integer total_number)
{
//llTriggerSound("dooropen", 0.5);
rotateDoor(TRUE);
state open;
}
}

state open
{
touch_start(integer num)
{
rotateDoor(FALSE);
// llTriggerSound("doorslam", 0.5);
state closed;
}
}
Kornscope Komachi
Transitional human
Join date: 30 Aug 2006
Posts: 1,041
10-02-2008 17:59
You don't have any Listen Event in any state.
To send chat to the door, the door must "Listen" first.
You will need to put the Listen Event into each state that needs to hear messages. Be aware that changing states also removes listens.

http://wiki.secondlife.com/wiki/Listen

Hope I've helped somebody.
_____________________
SCOPE Homes, Bangu
-----------------------------------------------------------------
Lunar Tripsa
Registered User
Join date: 2 Feb 2007
Posts: 38
10-02-2008 18:45
Thanks so much for your response. i did try adding listens, but wasn't able to get anything that worked, but in the end after showing the project to a friend she loved it the way it as atm, for a reason I gadn't thought of, so we are going with that. :) Thanks again though!
bobbyb30 Swashbuckler
Registered User
Join date: 8 Sep 2008
Posts: 46
10-03-2008 18:04
Here should be a working script...


// www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano)
//Written by Bobbyb30 Swashbuckler [Bobbyb30 Zohari](C) 2009
//Created: October 3, 2008
//Distributable under the Creative Commons Atrribution license
//http://creativecommons.org/licenses/by/3.0/
//NOT OPTIMIZED
integer doorSteps = 4;
integer reversed = FALSE;
rotateDoor(integer Open)
{
rotation rot = llGetRot();
rotation delta;
integer x;
if (reversed) {Open = !Open;};
if (Open)
{
delta = llEuler2Rot(<0, 0, PI/(doorSteps * 2)>;);
}
else
{
delta = llEuler2Rot(<0, 0, -PI/(doorSteps * 2)>;);
}
for (x = 0; x < doorSteps; x++)
{
rot = delta * rot;
llSetRot(rot);
llSleep(0.03125/doorSteps);
}
}
integer statein;//if 1-closed,if 0-open
integer listenhandle;
default
{
state_entry()
{
integer statein = 1;
rotateDoor(statein);//start closed
listenhandle = llListen(910,"",llGetOwner(),"open";);
}
touch_start(integer total_number)
{
if(statein)//to open
{
statein = 0;
rotateDoor(statein);
llListenRemove(listenhandle);
llListen(910,"",llGetOwner(),"close";);
}
else//to open
{
statein = 1;
rotateDoor(statein);
llListenRemove(listenhandle);
llListen(910,"",llGetOwner(),"open";);
}
}
listen(integer ch, string name, key id, string msg)
{
if(msg == "open";)
{
statein = 1;
rotateDoor(statein);
llListenRemove(listenhandle);
llListen(910,"",llGetOwner(),"close";);
}
else//to open
{
statein = 1;
rotateDoor(statein);
llListenRemove(listenhandle);
llListen(910,"",llGetOwner(),"open";);
}
}
}
_____________________
Large supporter and contributer of LSL Editor available at lsleditor.org