Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string DoubleDoor = "NO"; // set this to "YES" if it's a double door
- integer InOut = 1; // 1 to open one direction, -1 to open other direction
- string doorsound = "TARDIS"; // leave blank for no sound, or change sound name
- // CHANGE THESE IF YOUR HOUSE HAS MULTIPLE DOOR SETS
- string Open = "OPEN"; // change to OPEN2... OPEN3 etc
- string Close = "CLOSE"; // change to CLOSE2... CLOSE3 etc.
- // Doors open in THREE steps. Change these three variables to degree of rotation desired divided by 3 (ie: 90 / 3 = 30)
- // These are the X Y Z axis. Depending on which axis your door rotates on, switch the 30 apprppriately.
- float X = 0;
- float Y = 0;
- float Z = 30;
- integer opentime = 30; // Amount of time it stays open
- //NOTE: If creating a phantom door, set collliding=0 and phantom=1 and DO NOT LINK
- integer colliding = 0; // 1=Door opens when bumped (ie Star Trek) 0=Door requires touching (standard door)
- integer phantom = 0; // Phantom door option (vanishes). 0=Not phantom 1=phantom.
- integer lockchan = 5; // 0-ignore locking ... any other number is the speaking channel to lock your door (ie /5 LOCK)
- string NoEntry = "Sorry, this door is locked."; // Set this to your locked response
- //=================================
- // Non-changable variables. Ignore code from this point onward unless modifying.
- //=================================
- rotation orig; // original position of door
- integer locked; // is door locked or unlocked?
- integer open; // is door open or closed?
- key touched; // who's at the door?
- key owner; // owner of the door
- OpenDoor(){
- open=1; // set door flag to "open"
- // Phantom door routine
- if(phantom == 1){
- llSetStatus(STATUS_PHANTOM,TRUE);
- llSetAlpha(0.3,ALL_SIDES);
- llSetTimerEvent(opentime);
- return;
- }
- // Otherwise... it's a standard door
- //Now do idiotic pain-in-hiney rotation math.
- //Thanks lots Linden Lab. Never use one simple command when 3 complex ones will do
- llSetLocalRot(llEuler2Rot(<X, Y, Z> * InOut * DEG_TO_RAD) * llGetLocalRot());
- llSetLocalRot(llEuler2Rot(<X, Y, Z> * InOut * DEG_TO_RAD) * llGetLocalRot());
- llSetLocalRot(llEuler2Rot(<X, Y, Z> * InOut * DEG_TO_RAD) * llGetLocalRot());
- llSetTimerEvent(opentime); // wait for x seconds before closing door automatically
- }
- CloseDoor(){
- llSetTimerEvent(0);//turn off automatic close
- open = 0; // set open flag to "not open"
- if(phantom == 1){
- llSetAlpha(1,ALL_SIDES);
- llSetStatus(STATUS_PHANTOM,FALSE);
- return;
- }
- llSetLocalRot(llEuler2Rot(<X, Y, Z> * -InOut * DEG_TO_RAD) * llGetLocalRot());
- llSetLocalRot(llEuler2Rot(<X, Y, Z> * -InOut * DEG_TO_RAD) * llGetLocalRot());
- llSetLocalRot(llEuler2Rot(<X, Y, Z> * -InOut * DEG_TO_RAD) * llGetLocalRot());
- llSetLocalRot(orig); // make sure the door is closed to original postion
- }
- default{
- on_rez(integer q){llResetScript();}
- state_entry(){
- orig = llGetLocalRot(); // record the original position of the door for closing consistency
- owner = llGetOwner();
- if(lockchan > 0){llListen(lockchan,"",owner,"");} // set up listen for lock/unlock command
- }
- changed(integer change){
- if(change & CHANGED_OWNER){llResetScript();} // This fixes ownership recognition bugs
- }
- listen(integer chan,string name,key id,string str){
- if(lockchan == 0){return;} // if not a lockable door, skip this section
- str = llToUpper(str);
- if(str == "LOCK"){locked=1;llOwnerSay("Door locked.");}
- if(str == "UNLOCK"){locked=0;llOwnerSay("Door unlocked.");}
- }
- link_message(integer src,integer num,string msg,key id){
- if((msg == Open) && (open == 0)){OpenDoor();}
- if((msg == Close) && (open == 1)){CloseDoor();}
- }
- touch_start(integer a){
- touched=llDetectedKey(0); // who touched the door?
- // if door is locked and owner not at the door, don't open
- if(locked & (touched != owner)){llSay(0,NoEntry);return;}
- // if door is already open, close it
- if(DoubleDoor == "YES" && open){llMessageLinked(LINK_ALL_OTHERS,0,Close,"");}
- if(open){CloseDoor();return;}
- // otherwise... open the door
- if((DoubleDoor == "YES")){llMessageLinked(LINK_ALL_OTHERS,0,Open,"");}
- OpenDoor();
- }
- timer(){
- llSetTimerEvent(0);CloseDoor(); // auto-close the door
- }}
- // NOTE: This script is free, open source and is to be kept that way.
- // This script may be freely distributed, even in objects for sale, but not resold of iteself.
- // If you try to sell the script itself, your most prized bodily parts may fail to work and possibly even fall off entirely. :D
Advertisement
Add Comment
Please, Sign In to add comment