SungAli

4-Right Panel Control

Dec 1st, 2025 (edited)
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Adjustable Constants
  2. integer CommandChannel = 594923831; //Randomly Chosen Channel Number.  Must Match for all controllers.  Change for different sets controls and responders.
  3. float OffsetFraction = 0.8; //multiply panel width by this amount to get how far to move the door.
  4. integer MoveSteps = 5; //Number of steps to perform the move in.
  5.  
  6. //variables
  7. vector ClosedPos; // Local Position when Closed
  8. float Offset; // How far we want to move to the left (local -x direction)
  9. key Owner;
  10. integer ListenHandle;
  11.  
  12. //Functions
  13. move( float distance) { //move along the local x axis the indicated distance.
  14.     integer step;
  15.     vector stepDist = <distance/MoveSteps, 0, 0>;
  16.     vector newPos = llGetLocalPos();
  17.     for( step = 1; step <= MoveSteps; step++ ) {
  18.         newPos += stepDist;
  19.         llSetPos( newPos );
  20.     }
  21. }
  22.  
  23. //States
  24. default {
  25.     state_entry() {
  26.         ClosedPos = llGetLocalPos();
  27.         vector t = llGetScale(); //Get the door panel's dimentsions
  28.         Offset = t.x * OffsetFraction;
  29.         Owner = llGetOwner();
  30.         ListenHandle = llListen( CommandChannel, "", NULL_KEY, "Open");
  31.     }
  32.    
  33.     on_rez( integer param ) {
  34.         llSetPos( ClosedPos );
  35.         llResetScript();
  36.     }
  37.  
  38.     listen( integer channel, string name, key id, string message) {
  39.         //Ignore messages from objects with different owners.
  40.         if( llList2Key( llGetObjectDetails(id, [OBJECT_OWNER] ), 0 ) != Owner ) return;
  41.         if( message == "Open" ) {
  42.             llListenRemove( ListenHandle ); //Only listen for the currently relevant command.
  43.             ListenHandle = llListen( CommandChannel, "", NULL_KEY, "Close");
  44.             move( Offset ); //Open right ( +x local directon )
  45.         } else if( message == "Close" ) {
  46.            llListenRemove( ListenHandle ); //Only listen for the currently relevant command.
  47.             ListenHandle = llListen( CommandChannel, "", NULL_KEY, "Open");
  48.             move( -Offset ); //Close left ( -x local directon )
  49.             llSetPos(ClosedPos); //Resetting to starting position on close prevents accumulationg floating point roundoff errors.
  50.         } //else ignore unknown messages.
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment