Jump to content
ArchayonLegionAdmin

Sliding Door Script - Auto Close Timer

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...