Jump to content

Sliding Door Script - Auto Close Timer


ArchayonLegionAdmin
 Share

You are about to reply to a thread that has been inactive for 651 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hey everyone, quick question regarding a script I've been using for the past few weeks...

 

I have this script, with an access list, used to slide a "hidden" wall segment open, allowing listed users access to a hidden area... The problem is, a lot of users FORGET to close the wall. I'm not very good at scripting, and I've only come this far with help. How can I add a timer event into the following script, without breaking it? ---

 

// Movement
vector      OFFSET = <-2.0, 0.5, 0.0>;
float       OPENTIME = 0.5;
float       CLOSETIME = 0.5;

// Variables
 
vector      vPosition;
rotation    rRot;
float       omega=0.0;
vector      vTargetPos;
integer     bOpen = FALSE;
integer     bMoving = FALSE;

// Access List

list accesslist = ["name1", "name2"];
 
// Script 
 
MoveDoor()
{    
    if(!bOpen)
    {   
        bOpen = TRUE;                
        rRot = llGetRot();
        vPosition = llGetPos();
 
        omega=OPENTIME/llVecDist(<0,0,0>,OFFSET);
        vTargetPos = vPosition+OFFSET*rRot;
 
        llSetTimerEvent(OPENTIME);        
    }else
    {        
        bOpen = FALSE;
 
        omega=CLOSETIME/llVecDist(<0,0,0>,OFFSET);
        vTargetPos = vPosition;
 
        llSetTimerEvent(CLOSETIME);
    }
 
    bMoving = TRUE;
    llSetStatus(STATUS_PHANTOM, TRUE);
    llSetStatus(STATUS_PHYSICS, TRUE);
    llMoveToTarget(vTargetPos,omega);
}
 
 
default
{            
    state_entry()
    {   
        rRot = llGetRot();
        vPosition = llGetPos();
    }    
 
    touch_start(integer num_detected)
    {
        string name = llKey2Name(llDetectedKey(0));
        if (~llListFindList(accesslist,[name]))
        {
            MoveDoor();
        }
    } 
 
    timer()
    {
        bMoving = FALSE;
        llSetTimerEvent(0.0);
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetStatus(STATUS_PHANTOM, FALSE);         
        llSetPrimitiveParams([ PRIM_POSITION, vTargetPos, PRIM_ROTATION, rRot ]);        
    }

 

Any help would be appreciated, thank you in advance.

Link to comment
Share on other sites

Create a string variable called timerAction, initialise it to "".

When a user touches the door, set timerAction to "touched", and also set timerEvent to 0.0 .

Inside the timer event, check the value of timerAction and if it is "touched" then go to the existing code you have in the event. ( Put braces around this code to form a block of code)

Alter this code block so that after you have changed position of the door, you check bOpen to see where the door is.

If it is closed, set timerAction to "" but do nothing else, all finished.

If it is open, set  timerAction to be "autoclose", and set timerEvent to something like 5.0 seconds.

Now add an else if check to the timer event so that after checking if timerAction is not "touched", you test for it being "autoclose" , which will lead to a second code block

If "autoclose", alter timerAction to be "touched", call MoveDoor, and the door will close, this time when the timer is called it will use the code to close the door, stop the timer, and reset the string to "".

A user touching the door to close it before the autoclose timer will change timerAction to touched and also stop any pending autoclose timer by setting the timer event to 0.0, and then the routine to move the door does the rest.

 

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 651 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...