Advertisement
Teraunce

LaserDoorKludgeFullV1.1

Oct 25th, 2022 (edited)
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // materialize/dematerialize door movement script
  3. // JohnG Linden
  4.  
  5. // NOTE: these definitions should be the same as those from the lock
  6. // object or the door will not actually work
  7. integer     direction;
  8. integer b;
  9. integer getLinkWithName(string name) {
  10.     integer i = llGetLinkNumber() != 0;   // Start at zero (single prim) or 1 (two or more prims)
  11.     integer x = llGetNumberOfPrims() + i; // [0, 1) or [1, llGetNumberOfPrims()]
  12.     for (; i < x; ++i)
  13.         if (llGetLinkName(i) == name)
  14.             return i; // Found it! Exit loop early with result
  15.     return -1; // No prim with that name, return -1.
  16. }
  17. integer gLockChannel = 9394832;
  18. string  gOpenMsg = "MSG_OPEN";
  19. string  gCloseMsg = "MSG_CLOSE";
  20. string Lasername = "BridgeDoorLasers";
  21. string DontTouch = "Dematerializing Door V1.1"; //Well ok you can touch it but it involves editing linked prims.
  22.  
  23. vector color_on = <1.0,0.0,0.0>; //change this to the color that you whant the light to be
  24. float intensity_on = 0.25; //change this for the intenstity max 1.0 - min 0.0
  25. float radius_on = 5.0; //change this for the radius max 20.0 = min 0.0
  26. float falloff_on = 0.75; //change this for the fulloff max 2.00 - min 0.0
  27.  
  28.  
  29. // where we are when closed
  30. vector startingSize;
  31. vector      move;
  32. vector scale;
  33. vector      gClosedPos;
  34. rotation    gClosedRot;
  35. // internal timer for opening
  36. float       gOpenTimer;
  37.  
  38. // how long it takes to open/close
  39. float   gOpenTime = 1.3;
  40. // how many steps along the way
  41. float   gOpenTimeStep = 0.2;
  42. // how transparent when open
  43. float   gOpenAlpha = 0.00;
  44. float   gClosedAlpha = 1.0;
  45.  
  46. // sound we loop when opening/closing
  47. string  gOpenSound = "open";
  48. string  gCloseSound = "close";
  49. float   gSoundVolume = 0.6;
  50.  
  51. //
  52. // helper functions
  53. //
  54.  
  55. func_debug(string str)
  56. {
  57. //    llSay(0, str);
  58. }
  59. debug(string str)
  60. {
  61. //    llSay(0, str);
  62. }
  63. say(string str)
  64. {
  65.     llSay(0, str);
  66. }
  67. slide_prim()
  68.     {
  69.         if (direction == 1){scale=<0.01,0.01,0.01>;
  70.         b = 1;}
  71.         else {scale = startingSize;
  72.         b = 2;}
  73.         //float i;
  74.         //for (i=0;i<1;i=i+speed)
  75.         {
  76.             llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, llGetLocalPos() + move*direction*llGetLocalRot(),PRIM_SIZE,scale,PRIM_PHYSICS_SHAPE_TYPE,b ]);
  77.         }
  78.         direction *= -1;
  79.     }
  80. //
  81. // states begin here
  82. //
  83.  
  84. default
  85. {
  86.     on_rez(integer arg) { llResetScript(); }
  87.    
  88.     state_entry()
  89.     {
  90.         direction = 1;
  91.         scale = <0.01,0.01,0.01>;
  92.         startingSize = llList2Vector(llGetLinkPrimitiveParams(LINK_THIS,[PRIM_SIZE]),0);
  93.         func_debug("default state_entry");
  94.         move = startingSize;
  95.         // no physics
  96.         llSetStatus(STATUS_PHYSICS, FALSE);
  97.         // open/close timer
  98.         gOpenTimer = 0.0;
  99.         // listen for open/close messages
  100.         llListen(gLockChannel, "", "", "");
  101.         // and go to closed state
  102.         state door_closed;
  103.         llSetLinkPrimitiveParamsFast(getLinkWithName(Lasername), [PRIM_PHYSICS_SHAPE_TYPE,2]);//False?
  104.     }
  105. }
  106.  
  107. state door_closed
  108. {
  109.     on_rez(integer arg) { llResetScript(); }
  110.    
  111.     state_entry()
  112.     {
  113.         func_debug("door_closed state_entry");
  114.         // make us impermeable
  115.         llListen(gLockChannel, "", "", "");
  116.         //llSetLinkPrimitiveParamsFast(getLinkWithName(Lasername), [PRIM_PHYSICS_SHAPE_TYPE,2]);//False?
  117.         llSetLinkPrimitiveParamsFast(getLinkWithName(DontTouch), [PRIM_PHYSICS_SHAPE_TYPE,2]);//False?
  118.     }
  119.  
  120.     listen(integer channel, string name, key id, string msg)
  121.     {
  122.         if ( msg == gOpenMsg )
  123.         {
  124.             state door_opening;
  125.         }
  126.     }
  127. }
  128.  
  129. state door_opening
  130. {
  131.     on_rez(integer arg) { llResetScript(); }
  132.    
  133.     state_entry()
  134.     {
  135.         func_debug("door_opening state_entry");
  136.         // start opening sound
  137.         llLoopSound(gOpenSound, gSoundVolume);
  138.         // start opening process
  139.         llResetTime();
  140.         gOpenTimer = 0.0;
  141.         llListen(gLockChannel, "", "", "");
  142.         llSetTimerEvent(gOpenTimeStep);
  143.     }
  144.    
  145.     timer()
  146.     {
  147.         float   time = llGetTime();
  148.        
  149.         // interpolate transparency from closed to open
  150.         float   alpha = (1 - (time / gOpenTime)) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha;
  151.         llSetAlpha(alpha, ALL_SIDES);
  152.          llSetLinkPrimitiveParamsFast
  153.                 (LINK_THIS,[
  154.                     PRIM_POINT_LIGHT,
  155.                 TRUE,
  156.                 color_on,
  157.                 alpha,
  158.                 radius_on,
  159.                 falloff_on
  160.                     ]);
  161.  
  162.         if ( time > gOpenTime )
  163.         {
  164.             // stop timer interrupts
  165.             llSetTimerEvent(0.0);
  166.             // door is now open
  167.             state door_open;
  168.         }
  169.     }
  170.    
  171.     state_exit()
  172.     {
  173.         llStopSound();
  174.     }
  175. }
  176.  
  177. state door_open
  178. {
  179.     on_rez(integer arg) { llResetScript(); }
  180.    
  181.     state_entry()
  182.     {
  183.         func_debug("door_open state_entry");
  184.         // make us permeable
  185.         llListen(gLockChannel, "", "", "");
  186.         slide_prim();
  187.         //llSetLinkPrimitiveParamsFast(getLinkWithName(Lasername), [PRIM_PHYSICS_SHAPE_TYPE,1]);//True?
  188.         llSetLinkPrimitiveParamsFast(getLinkWithName(DontTouch), [PRIM_PHYSICS_SHAPE_TYPE,1]);//True?
  189.     }
  190.  
  191.     listen(integer channel, string name, key id, string msg)
  192.     {
  193.         if ( msg == gCloseMsg )
  194.         {
  195.             state door_closing;
  196.         }
  197.     }
  198. }
  199.  
  200. state door_closing
  201. {
  202.     on_rez(integer arg) { llResetScript(); }
  203.    
  204.     state_entry()
  205.     {
  206.         func_debug("door_closing state_entry");
  207.         // audio
  208.         slide_prim();
  209.         llLoopSound(gCloseSound, gSoundVolume);
  210.         // start opening process
  211.         llResetTime();
  212.         gOpenTimer = 0.0;
  213.         llListen(gLockChannel, "", "", "");
  214.         llSetTimerEvent(gOpenTimeStep);
  215.     }
  216.    
  217.     timer()
  218.     {
  219.         float   time = llGetTime();
  220.        
  221.         // interpolate transparency from closed to open
  222.         float   alpha = (time / gOpenTime) * (gClosedAlpha - gOpenAlpha) + gOpenAlpha;
  223.         llSetAlpha(alpha, ALL_SIDES);
  224.          llSetLinkPrimitiveParamsFast
  225.                 (LINK_THIS,[
  226.                     PRIM_POINT_LIGHT,
  227.                 TRUE,
  228.                 color_on,
  229.                 alpha,
  230.                 radius_on,
  231.                 falloff_on
  232.                     ]);
  233.  
  234.         if ( time > gOpenTime )
  235.         {
  236.             // stop timer interrupts
  237.             llSetTimerEvent(0.0);
  238.             // door is now closed
  239.             state door_closed;
  240.         }
  241.     }
  242.    
  243.     state_exit()
  244.     {
  245.         // kill closing sound
  246.         llStopSound();
  247.     }
  248. }
  249.  
  250.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement