Used the idea from Pratyeka's sliding door script and use Description field to hold the open/close data.
This seems to work while linked and across resets but could use some testing. I know it's not "good" code but I'm not a good coder.
Try this and improve it for all.
|
//June 2008
//Macca Rox's version
//---/---/---/------------------------------------------//_______________________>>
vector DIST = <0,-0.3,0.0>; //set movement amount and direction. Use a minus for reverse
float SLEEP = 0.2; //set time between movements
//float VOLUME = 0.8; // sound volume, 1.0 loudest, 0.0 to disable sound
//key SOUND_OPEN = "";
//key SOUND_CLOSE = "";
vector Pos;//Get the prims position
//---/---/---/------------------------------------------//_______________________>>
open()
{
//llTriggerSound(SOUND_OPEN, VOLUME);
Pos = llGetPos();
llSetPos(llGetLocalPos() + DIST); //Add or remove these pairs for more or less steps
llSleep(SLEEP);
llSetPos(llGetLocalPos() + DIST);
llSleep(SLEEP);
llSetPos(llGetLocalPos() + DIST);
llSleep(SLEEP);
llSetPos(llGetLocalPos() + DIST);
//llWhisper(0,"Opened");
llSetObjectDesc("1"); //Sets object Description for open position
}
close()
{
//llTriggerSound(SOUND_CLOSE, VOLUME);
Pos = llGetPos();
llSetPos(llGetLocalPos() - DIST);
llSleep(SLEEP);
llSetPos(llGetLocalPos() - DIST);
llSleep(SLEEP);
llSetPos(llGetLocalPos() - DIST);
llSleep(SLEEP);
llSetPos(llGetLocalPos() - DIST);
//llWhisper(0,"Closed");
llSetObjectDesc("0");//Sets object Description for close position
}
//---/---/---/------------------------------------------//_______________________>>
default
{
state_entry()
{
if(llGetObjectDesc()=="") llSetObjectDesc("0"); // if any, initialize Object's Description as storage variable
}
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if(change & CHANGED_OWNER) //Check for a new owner
llResetScript();
}
touch_start(integer total_number)
{
if(llGetObjectDesc()=="0")
{
open();
}
else if(llGetObjectDesc()=="1")
{
close();
}
}
}
|