Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

something about doors...

Iraefer Revnik
Registered User
Join date: 3 Dec 2007
Posts: 10
04-20-2008 03:05
I create a house and a sliding door with some script i found in here...
i have afew questions i can not understand can u help me about it...

1- When i am trying to link the doors i have trubles door moves with the linked object togather. How can i solve it?
2- I take the all house and doors togather to my inventory with unliked houses then i put them to a different place door moves 2-3 times coretly but then goes to its old place where i create and give coordinates. How can i solve it?

Can u help me with this 2 questions... I put my script above that i use inside door
Thank you...

key owner;
// Will be used to retrieve owner's key.

integer iChan = 1000;
// Channel door will listen on if other doors are touched;
// also the channel this door will broadcast on.

integer iSteps = 8;
// How many steps the door will open in, used to provide the
// illusion of sliding. Fewer steps means it opens faster,
// but more steps will make it "slide" smoother.

vector vOffset = <0.0, 0.50, 0.0>;
// Indicates how far the door will move with each step.
// Multiply by iSteps to calculate the total distance the
// door will move.

vector vBase;
// Used to "un-stick" the door if something blocks it.
// Not sure if this is needed since 0.5.1, objects don't
// seem to block the door any more. Leaving it in just
// in case, though. I think attempting to edit the door
// while it's moving may make it stick. This will solve
// that problem as well.

float fOpenTime = 7.5;
// How long the door stays open

string sSKeyword = "open1";
// Keyword door broadcasts when it's touched, to make
// other doors open. You can chain these to make multiple
// doors open when any one is touched.
// NEVER make sSKeyword and sRKeyword the same, or you may
// get some doors stuck in an infinite loop, continuously
// re-triggering each other.

string sRKeyword = "open2";
// Keyword door listens for from other doors. Will open
// when it "hears" this keyword.
// Again, NEVER make sSKeyword and sRKeyword the same.

integer bMove = FALSE;
// Is the door moving?

integer bLock = FALSE;
// Is the door locked?

integer bVerbose = FALSE;
// Confirm when owner locks/unlocks the door.


float volume = 1.0; // 0.0 is off, 1.0 is loudest

key open_sound = "cb340647-9680-dd5e-49c0-86edfa01b3ac";
key close_sound = "e7ff1054-003d-d134-66be-207573f2b535";


//*********************************************
// open() -- the meat and taters of the code,
// makes the door actually move.
//*********************************************
open()
{
bMove = TRUE;
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
llSleep(fOpenTime);
basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
if (llGetPos() != vBase) {
llSetTimerEvent(5);
} else {
bMove = FALSE;
}
}

default
{
//************************************************** *
// state_entry() -- set up our global variables and
// initialize the listen events.
//************************************************** *
state_entry()
{
vBase = llGetPos();
owner = llGetOwner();
llListen(0,"",owner,"";);
llListen(iChan,"",NULL_KEY,sRKeyword);
}

//************************************************** *
// listen() -- listen for other doors opening, and
// if owner wants to lock/unlock doors.
//************************************************** *
listen(integer chan, string name, key id, string msg)
{
if (chan == iChan && msg == sRKeyword) {
if (!bMove && !bLock) open();
if (bLock && bVerbose) llSay(0,"Locked!";);
}
if (chan == 0 && id == owner && msg == "lock";) {
bLock = TRUE;
if (bVerbose) llWhisper(0,"Locked!";);
}
if (chan == 0 && id == owner && msg == "unlock";) {
bLock = FALSE;
if (bVerbose) llWhisper(0,"Unlocked!";);
}
}

//********************************************
// touch_start() -- what to do when someone
// touches the door.
//********************************************
touch_start(integer count)
{
if (bLock) {
llSay(0,"Locked!";);
} else {
if (!bMove) {
llSay(0,"Front door open.";);
llTriggerSound(open_sound, volume);// Trigger the sound of the door opening
llWhisper(iChan,sSKeyword);
open();
llTriggerSound(close_sound, volume);// Trigger the sound of the door opening
}
}
}

//************************************************** **
// timer() -- this is only used to un-stick the door
// (see vBase definition above).
//************************************************** **
timer()
{
llSetPos(vBase);
if(llGetPos() == vBase) {
llSetTimerEvent(0);
bMove = FALSE;
}
}
}
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
04-20-2008 05:59
It looks to me like the vBase might not get reset, you might want to add another chat command like 'Set' causing it to set vBase to the current result of llGetPos() when it is in position initially.

To me it looks like 5 seconds after the door is used, it will go to vBase which is not really known if you have been moving the door around.

Also in the listen() and touch events, you could use bMove to prevent the user from initiating another door move while it is in progress, it looks to me like if they click it a second time it will start a new open() and move from where it currently is, since it sets basePos to the current llGetPos() and moves from there. You might want to replace basePos with vBase to ensure it is always working from the same reference point.
Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
04-21-2008 01:35
In regards to the door moving ... you need to simply reset the script when you rez the house. The vBase is calculated when the script is initialized ... and remains so even when taken into inventory.

And as to the link issue ... I am pretty sure you cannot have the door linked to the house. All the door scripts I use require that the door be unlinked.