Jump to content

Help with scripting a door


AnthonyMann
 Share

Recommended Posts

I have a door system that came with my rental box system. It works just fine, with the exception that everyone leaves their doors open because there is no automatic closing timer event. The script, because it integrates the rental system and such is too complex for my very basic scripting level. What and most importantly where-- would I have to insert to make the doors close after about 10 seconds and not screw up the functionality of the rental tie-in?

Here is the script--

string owner="";
integer rented = 0;
integer open=FALSE;
integer waitingforping = FALSE;
key candidate = "";
key listeningunit = NULL_KEY;
list additionaltenants=[];
default
{
    state_entry()
    {
        llListen(77777, "", "", "");
    }
    listen(integer channel, string name, key id, string message)
    {
        if (llGetOwnerKey(id)==llGetOwner() && id != llGetOwner())
        {
            list tmp = llParseString2List(message,["|"],[]);
            list tmp2 = llParseString2List(message,["@"],[]);
            if (llList2String(tmp2,0)=="ADDTNTS")
            {
                if (id == listeningunit)
                {
                    tmp2 = llParseString2List(llList2String(tmp2,1),["#"],[]);
                    additionaltenants=[];    
                    integer x;
                    for(x=0; x<llGetListLength(tmp2); x=x+2)
                    {
                        additionaltenants+=[llList2Key(tmp2, x)];   
                    }
                }   
            }
            if (llList2String(tmp,0)=="REXTR")
            {
                if (waitingforping)
                {
                    waitingforping = FALSE;
                    candidate = id;
                    llParticleSystem([7, 6.0, 1, <1,1,1>, 3, <0,0,1>, 2, 1.0, 4, 0.5, 5, <0.07, 0.07, 0.1>, 6, <0.1,0.1,0.1>, 13, 0.01, 15, 2, 16, 0.1, 17, 3.0, 18, 3.0, 8, <0,0,-0.4>, 22, 0.0, 23, PI, 21, <0,0,1>, 19, 0.0, 0, PSYS_PART_EMISSIVE_MASK | PSYS_PART_FOLLOW_SRC_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK | PSYS_PART_TARGET_POS_MASK | PSYS_PART_TARGET_LINEAR_MASK, 9, PSYS_SRC_PATTERN_DROP, 20, id, 12, "chain"]);
                    llDialog(llGetOwner(),"Please watch the particles emitting from the door. Are they going to the correct unit?",["YES","NO"],77777);
                }
                else if (id == listeningunit)
                {
                    key user = llList2Key(tmp,2);
                    if (user != NULL_KEY)
                    {
                        owner = user;
                        rented = 1;
                    }    
                    else
                    {
                        additionaltenants=[];
                        owner = llGetOwner();
                        rented = 0;    
                    }
                }   
            }
        }
        else if (id == llGetOwner() && candidate != "")
        {
            llParticleSystem([]);
            if (message == "YES")
            {
               owner = llGetOwner();
               llRegionSay(-77777, "CLAPI"+(string)candidate+"-Reset|"+(string)owner+"|0");    
               listeningunit = candidate;
            }
            candidate = "";
        }  
    }
    on_rez(integer j)
    {
        llResetScript();    
    }
    touch_start(integer j)
    {
        for(j--; j>-1; j--)
        {
            if (llDetectedKey(j)==llGetOwner() && owner == "")
            {
                waitingforping = TRUE;
                llDialog(llGetOwner(), "Please touch the rental unit that you want to link to this door.",["OK"],-1);
            }
            else
            {
                integer found = llListFindList(additionaltenants,[llDetectedKey(j)]);
                if (llDetectedKey(j)!=owner && llDetectedKey(j) != llGetOwner() && found==-1 && rented)
                {
                    llPlaySound("f6ffb2dc-b880-ef60-e958-541d1493f813", 1.0);
                    llInstantMessage(llDetectedKey(j),"You have no permission to use this door.");   
                }
                else
                {
                    open=!open;
                    if (open)
                    {
                        llPlaySound("8f438543-a18a-236f-9e97-629f18d852c7", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() / test);
                    }
                    else
                    {
                        llPlaySound("cf33a3f9-6b15-351d-af15-b71e1b0e36bb", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() * test);
                    }
                }
            }
        }
    }
}
string owner="";
integer rented = 0;
integer open=FALSE;
integer waitingforping = FALSE;
key candidate = "";
key listeningunit = NULL_KEY;
list additionaltenants=[];
default
{
    state_entry()
    {
        llListen(77777, "", "", "");
    }
    listen(integer channel, string name, key id, string message)
    {
        if (llGetOwnerKey(id)==llGetOwner() && id != llGetOwner())
        {
            list tmp = llParseString2List(message,["|"],[]);
            list tmp2 = llParseString2List(message,["@"],[]);
            if (llList2String(tmp2,0)=="ADDTNTS")
            {
                if (id == listeningunit)
                {
                    tmp2 = llParseString2List(llList2String(tmp2,1),["#"],[]);
                    additionaltenants=[];    
                    integer x;
                    for(x=0; x<llGetListLength(tmp2); x=x+2)
                    {
                        additionaltenants+=[llList2Key(tmp2, x)];   
                    }
                }   
            }
            if (llList2String(tmp,0)=="REXTR")
            {
                if (waitingforping)
                {
                    waitingforping = FALSE;
                    candidate = id;
                    llParticleSystem([7, 6.0, 1, <1,1,1>, 3, <0,0,1>, 2, 1.0, 4, 0.5, 5, <0.07, 0.07, 0.1>, 6, <0.1,0.1,0.1>, 13, 0.01, 15, 2, 16, 0.1, 17, 3.0, 18, 3.0, 8, <0,0,-0.4>, 22, 0.0, 23, PI, 21, <0,0,1>, 19, 0.0, 0, PSYS_PART_EMISSIVE_MASK | PSYS_PART_FOLLOW_SRC_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK | PSYS_PART_TARGET_POS_MASK | PSYS_PART_TARGET_LINEAR_MASK, 9, PSYS_SRC_PATTERN_DROP, 20, id, 12, "chain"]);
                    llDialog(llGetOwner(),"Please watch the particles emitting from the door. Are they going to the correct unit?",["YES","NO"],77777);
                }
                else if (id == listeningunit)
                {
                    key user = llList2Key(tmp,2);
                    if (user != NULL_KEY)
                    {
                        owner = user;
                        rented = 1;
                    }    
                    else
                    {
                        additionaltenants=[];
                        owner = llGetOwner();
                        rented = 0;    
                    }
                }   
            }
        }
        else if (id == llGetOwner() && candidate != "")
        {
            llParticleSystem([]);
            if (message == "YES")
            {
               owner = llGetOwner();
               llRegionSay(-77777, "CLAPI"+(string)candidate+"-Reset|"+(string)owner+"|0");    
               listeningunit = candidate;
            }
            candidate = "";
        }  
    }
    on_rez(integer j)
    {
        llResetScript();    
    }
    touch_start(integer j)
    {
        for(j--; j>-1; j--)
        {
            if (llDetectedKey(j)==llGetOwner() && owner == "")
            {
                waitingforping = TRUE;
                llDialog(llGetOwner(), "Please touch the rental unit that you want to link to this door.",["OK"],-1);
            }
            else
            {
                integer found = llListFindList(additionaltenants,[llDetectedKey(j)]);
                if (llDetectedKey(j)!=owner && llDetectedKey(j) != llGetOwner() && found==-1 && rented)
                {
                    llPlaySound("f6ffb2dc-b880-ef60-e958-541d1493f813", 1.0);
                    llInstantMessage(llDetectedKey(j),"You have no permission to use this door.");   
                }
                else
                {
                    open=!open;
                    if (open)
                    {
                        llPlaySound("8f438543-a18a-236f-9e97-629f18d852c7", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() / test);
                    }
                    else
                    {
                        llPlaySound("cf33a3f9-6b15-351d-af15-b71e1b0e36bb", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() * test);
                    }
                }
            }
        }
    }
}


 

Link to comment
Share on other sites

You've pasted two copies of your script here.  Be sure that your object only has one copy or it will get messed up.  :smileywink:

You should be able to add a timer event easily enough.  Your touch_start event includes two if tests -- one that plays a sound and opens the door if open == FALSE and the other that plays a different sound and closes it if open == TRUE.  So, what you'll want to do is copy the bit of code that closes the door into a new timer event so that the timer does exactly the same thing that the touch_start event does when the door is supposed to close.  Then you need a command to llSetTimerEvent(10.0); , which needs to go in the part of the touch_start event that opens the door.  Finally, your new timer event needs two closing commands:

open = FALSE;  // To make sure that the door opens properly next time

llSetTimerEvent(0.0);   // To shut off the timer so it doesn't try to close the door again.

  • Like 1
Link to comment
Share on other sites

Thank you for answering. I've studied your answer and I think I understand what you mean, but the execution is still way above my skill level.

I think this is the opening event and the timer command goes in here.....

  open=!open;
                    if (open)
                    {
                        llPlaySound("8f438543-a18a-236f-9e97-629f18d852c7"

, 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() / test);
                    }

 

and then the next group, after the 'else' , is the closing event.

Not sure where to put the closeing/reset statements...

 

Could you dumb it down for me a little? :D

 

Thanks for your help!

Link to comment
Share on other sites

How does this look? I think this should start the timer event and close the door after 10 seconds, the reset the timer and closed state, and the the old part at the end would close the door if it was clicked before the 10 seconds expires. Would it be better to just delete the old closing event?

                else
                {
                    open=!open;
                    if (open)
                    {
                        llPlaySound("8f438543-a18a-236f-9e97-629f18d852c7", 0.7);
                        llSetTimerEvent(10.0)
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() / test);
                    }

        timer()

          {

                llPlaySound("cf33a3f9-6b15-351d-af15-b71e1b0e36bb", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() * test);

         open = FALSE;  // To make sure that the door opens properly next time

       llSetTimerEvent(0.0);   // To shut off the timer so it doesn't try to close the door again.


                 }


                    else
                    {
                        llPlaySound("cf33a3f9-6b15-351d-af15-b71e1b0e36bb", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() * test);
                    }
                }

It is lined up in Word, sort of sloppy here. I hope you can read it okay.

Thanks for all your help, I know it can be tiresome to coax someone through things like this.

Link to comment
Share on other sites

It looks like it ought to work.  The way to find out, of course, is to try it.  Chances are pretty good that you screwed up on something, but that happens to all scripters.  It's hard to type any script with more than about ten lines without making some dumb mistake.  That's how you learn humility.

BTW, sorry not to respond more quickly.  I am out of town for the holidays and lucky to be able to get on line once a day.

Link to comment
Share on other sites

Trying to debug it now. When I compiled it it gave me a syntax error that I can't figure out. The position given in the syntax error is right before the word "timer".  Do I need to set a counter or something? Or is it a bracket thing?

 

 

           llPlaySound("8f438543-a18a-236f-9e97-629f18d852c7", 0.7);
                        llSetTimerEvent(10.0);
                        //This stuff makes sure it works well as part of a linkset too
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() / test);
                    }
                    timer()
                    {
                         llPlaySound("cf33a3f9-6b15-351d-af15-b71e1b0e36bb", 0.7);
                        
                        //This stuff makes sure it works well as part of a linkset too
                        
                        vector axis=<0.0,0.0,1.0>;
                        axis=axis*llGetLocalRot();
                        rotation test=llAxisAngle2Rot(axis, 1.570796);
                        llSetLocalRot(llGetLocalRot() * test);
                        open = FALSE;  // To make sure that the door opens properly next time
                         llSetTimerEvent(0.0);   // To shut off the timer so it doesn't try to close the door again.

                     }


Link to comment
Share on other sites

It's amost certainly a "bracket thing."  I can't see any more than what you showed here, but my guess is that you're missing the closed backet at the end of the touch_start event.  Be daring. Put one in and see.  If you are always careful to indent properly, it's easy to see when your brackets don't match.

BTW, I didn't answer your other question.  You probably don't want to get rid of the door closing sequence in the touch_start event.  Your choice, of course, but if it were my script, I'd stlll want to be able to close the door "manually".

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...