Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sliding Door Script

Rose Munson
Registered User
Join date: 8 Aug 2008
Posts: 3
12-06-2008 11:19
I have been searching for a script for sliding doors that would work in any house if the house is moved or rotated. The scripts I find are either positioned with xyz or east/west sort of thing this is fine and works well. But if you rotate your house the sliding doors go another way. So I basically looking for help if there is a script that works if you rotate the house. This is the script I have used any help in tweaking would be appreciated. thank you.

//How far in meters to travel in each direction. Two or all three can be used for angled movement
//NOTE: when linked, this is relative to the root prim
//Positive = move north, negative = move south
float NorthSouth = 0.5;
//Positive = move east, negative = move west
float EastWest = -0.0;
//Positive = move up, negative = move down
float UpDown = 0.0;

//The amount in seconds to stay open, set to 0 to not autoclose
//-- delete next line if not using autoclose
float Timer = 0.0;

//-- begin sound section: delete to 'end sound section' if not using sounds

//Sound to play on open, either a UUID or a name in the door contents
// in quotation marks. if a name, it must be exact.
string OpenSound = "";

//Volume to play open sound, 0.0 is same as no sound, 1.0 is max
//-- setting this to 0.0 turns off open sounds
float OpenVol = 0.0;

//Sound to play on close, either a UUID or a name in the door contents
// in quotation marks. if a name, it must be exact.
string CloseSound = "";

//Volume to play close sound, 0.0 is same as no sound, 1.0 is max
//-- setting this to 0.0 turns off close sounds
float CloseVol = 0.0;

//-- end sound section

//misc variables
vector Offset;
integer Open;

//-- begin sound trigger: delete to 'end sound trigger' if not using sounds

//-- included to trap errors triggering sounds which delay the script firing
fTriggerSound(string sound, float volume)
//Written by Strife Onizuka
//-- tweaked by Void Singer
{
if (volume){
//-- makes sure sound is valid before playing
if ((key)sound);
else if (INVENTORY_SOUND == llGetInventoryType( sound ) );
else{
return;
}
llTriggerSound(sound, volume);
}
}
//-- end sound trigger

fTriggerSlide(){
//-- begin sound trip: delete to 'end sound trip' if not using sounds
if (Open)
{
fTriggerSound( CloseSound, CloseVol );
}else
{
fTriggerSound( OpenSound, OpenVol );
}
//-- end sound trip

llSetPos( llGetLocalPos() + Offset );
//-- reverse offset so next time it goes the opposite direction
Offset = -Offset;
//-- reverse open state tracking
Open = !Open;

//-- delete next line if not using autoclose
llSetTimerEvent( Timer * Open); //-- if closed timer is turned off
}

default
{
state_entry()
{
Offset = <EastWest, NorthSouth, UpDown>;
}

touch_start( integer vIntNull )
{
//-- safer to ignore simultaneaous touches in doors,
//-- so we dont bother processing more than the first
fTriggerSlide();
}

//-- removed on rez reset because it could reverse the open logic and break the offset.

//-- begin timer: delete to 'end timer' end if not using autoclose
timer()
{
//-- test if it's open so queued timer events don't accidently fire movement code
if (Open)
{
fTriggerSlide();
}
}
//-- end timer
}[/php]

edit:
if only using movement, no autoclose, no sounds all you need is
CODE

//Sliding Door v4
//Works when linked
//by Kayla Stonecutter
//-- tweaked heavily by Void Singer Mar 10, 2008

//How far in meters to travel in each direction. Two or all three can be used for angled movement
//NOTE: when linked, this is relative to the root prim
//Positive = move north, negative = move south
float NorthSouth = 0.5;
//Positive = move east, negative = move west
float EastWest = -0.0;
//Positive = move up, negative = move down
float UpDown = 0.0;

//misc variables
vector Offset;

default
{
state_entry()
{
Offset = <EastWest, NorthSouth, UpDown>;
}

touch_start( integer vIntNull )
{
llSetPos( llGetLocalPos() + Offset );
//-- reverse offset so next time it goes the opposite direction
Offset = -Offset;
}
}
Johnathon Seetan
Registered User
Join date: 18 Sep 2008
Posts: 11
the last part of your code......
12-17-2008 20:41
Hi Rose.... I am looking for a sliding door script too..... BUT I am a total noobie when it comes to scripting... in RL I know all about web design and coding behind there... so I am not a complete novice......
I look at the end bit..... JUST the sliding door... no sounds or anything.. and this suits me..... BUT .... and I know you will probably laugh at this.... duh.... but bear with me please!!!

The
CODE
 ....... 
do they have to be in the code when you put this code in the script notecard?

I know this is easy for you guys..... BUT though it is obvious... I noticed a few people left it out... also... it is NOT at the bottom of your script and not at the top.... can you help please....

Thanks!!!!
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
12-17-2008 21:27
From: Johnathon Seetan


The
CODE
 ....... 
do they have to be in the code when you put this code in the script notecard?


The PHP is an attempt to get the code to format correctly for display in this forum, not part of LSL.
There is a way of formatting code correctly for the forum, but I haven't figured out how.
ab
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
12-18-2008 03:28
Rose,

I too wasn't happy with the way current sliding door scripts worked. Most had to be reset or reset themselves when moved because of the position and rotation change. The way I got around it was to make a script that records movements, then plays them back, no matter what the position or rotation of the door prim. Most door scripts use the "link me to a hinge" method, which is used for a reference. That's fine I suppose. I wanted to be able to make a single prim and move it in relation to itself, not any other prim. With the help of Hewee I was able to get the calculations right. This particular script was written to store three positions, then move from open to close when touched. It works like it should no matter the position or rotation. Keep in mind this script is a starting point and was written specifically to test the concept. If the script happens to be reset the settings are lost, so it's best to put them in a notecard. If you need help with it let me know and I can always come to you in-world and show you how it works. (NOTE: I've since revised this into a more advanced door script for myself that stores unlimited movements and has notecard backup.)

From: someone

integer toggle;
integer acquire=1;
rotation initial_rot;
vector initial_pos;
integer move_count=0;

vector pos1;
vector pos2;
vector pos3;
rotation rot1;
rotation rot2;
rotation rot3;
rotation rel1;
rotation rel2;
rotation rel3;
vector off1;
vector off2;
vector off3;


store()
{
move_count = move_count + 1;
if (move_count == 1)
{
pos1 = llGetPos();
rot1 = llGetRot();
rel1 = llGetRot()/initial_rot;
off1 = (llGetPos()-initial_pos)/initial_rot;

} else if (move_count == 2)
{
pos2 = llGetPos();
rot2 = llGetRot();
rel2 = llGetRot()/rot1;
off2 = (llGetPos()-pos1)/rot1;

} else if (move_count == 3)
{
pos3 = llGetPos();
rot3 = llGetRot();
rel3 = llGetRot()/rot2;
off3 = (llGetPos()-pos2)/rot2;

}

llOwnerSay("Stored "+(string)move_count+" of 3";);
acquire++;
}

default
{
state_entry()
{
initial_rot = llGetRot();
initial_pos = llGetPos();
toggle = FALSE;
llOwnerSay("Initial position/rotation stored. Please move your object and touch to store each position/rotation. Three will be stored, then when touched the animation will move forward. When touched again it will move backward.";);
}

touch_start(integer touches)
{
if (acquire == 1)
{
store();
return;
} else if (acquire == 2)
{
store();
return;
} else if (acquire == 3)
{
store();
acquire++;
}

if (acquire == 4)
{
llOwnerSay("Storage complete. Moved to original position. Touch prim to animate forward. Touch again to animate backward.";);
llSetPos(initial_pos);
llSetRot(initial_rot);
acquire++;
return;

} else if (acquire == 5)
{
if (toggle == FALSE)
{
//Animate forward
rotation temp_rot = llGetRot();
llSetPrimitiveParams([ PRIM_POSITION, llGetPos()+off1*temp_rot,PRIM_ROTATION,rel1*temp_r ot]);
llSleep(.2);

temp_rot = llGetRot();
llSetPrimitiveParams([ PRIM_POSITION, llGetPos()+off2*temp_rot ,PRIM_ROTATION,rel2*temp_rot]);
llSleep(.2);

temp_rot = llGetRot();
llSetPrimitiveParams([ PRIM_POSITION, llGetPos()+off3*temp_rot ,PRIM_ROTATION,rel3*temp_rot]);

toggle = TRUE;
return;
}
else if (toggle == TRUE)
{
// Reverse the animation
rotation temp_rot = (ZERO_ROTATION/rel3)*llGetRot();
llSetPrimitiveParams([ PRIM_POSITION, llGetPos()-off3*temp_rot,PRIM_ROTATION, temp_rot]);
llSleep(.2);

temp_rot = (ZERO_ROTATION/rel2)*llGetRot();
llSetPrimitiveParams([ PRIM_POSITION, llGetPos()-off2*temp_rot,PRIM_ROTATION, temp_rot]);
llSleep(.2);

temp_rot = (ZERO_ROTATION/rel1)*llGetRot();
llSetPrimitiveParams([ PRIM_POSITION, llGetPos()-off1*temp_rot ,PRIM_ROTATION,temp_rot]);

toggle = FALSE;
}
}
}
}