Advertisement
Guest User

Phantom Door

a guest
Jul 6th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // PhantomDoor
  2. // Ryonen Moon 21 Nov 2011
  3. //
  4. // A door script that becomes phantom and fades to transparent when opened,
  5. // and then automatically closes again after an interval.
  6. //
  7. // License: You may use this script as you please in any of your endeavors or projects, including commercial use.
  8. // I only ask that you don't claim this script is yours, or charge anyone else for it.
  9. //
  10.  
  11. // Door State enumerator
  12. integer doorCLOSED = 0;
  13. integer doorOPENING = 1;
  14. integer doorOPEN = 2;
  15. integer doorCLOSING = 3;
  16.  
  17. integer NUM_TRANSPARENCY_STEPS = 15;
  18. float   STEP_DELAY; //  = 1.5 / (float)NUM_TRANSPARENCY_STEPS;
  19. float   FADE_BASE = 0.9;
  20.  
  21. integer gDoorTransparencyStep;      // For progressively changing the door to be transparent
  22. integer gDoorState;                 // Current state of door (See door state enumerator)
  23.  
  24. openDoor()
  25. {
  26.     gDoorState = doorOPENING;
  27.     llSetLinkPrimitiveParamsFast(0, [PRIM_PHANTOM, TRUE]);
  28.     gDoorTransparencyStep = NUM_TRANSPARENCY_STEPS;
  29.     llSetTimerEvent(STEP_DELAY);
  30. }
  31.  
  32. closeDoor()
  33. {
  34.     gDoorState = doorCLOSING;
  35.     gDoorTransparencyStep = 0;
  36.     llSetTimerEvent(STEP_DELAY);
  37.     llSetLinkPrimitiveParamsFast(0, [PRIM_PHANTOM, FALSE]);
  38. }
  39.  
  40. default
  41. {
  42.     state_entry()
  43.     {
  44.         STEP_DELAY = 1.5 / (float)NUM_TRANSPARENCY_STEPS;
  45.     }
  46.    
  47.     touch_start(integer total_number)
  48.     {
  49.         if (gDoorState == doorOPEN)
  50.             closeDoor();
  51.         else if (gDoorState == doorCLOSED)
  52.             openDoor();
  53.         // Ignore clicks if in transition between open and closed - events will transpire on their own            
  54.     }
  55.    
  56.     timer()
  57.     {
  58.         if (gDoorState == doorOPENING) {
  59.             gDoorTransparencyStep -= 1;
  60.             llSetAlpha(1.0 - llPow(FADE_BASE, gDoorTransparencyStep), ALL_SIDES);
  61.            
  62.             if (gDoorTransparencyStep < 1) {
  63.                 gDoorState = doorOPEN;
  64.                 llSetTimerEvent(10.0);    // Set delay before door will automatically close
  65.             }
  66.         } else if (gDoorState == doorOPEN) {
  67.             closeDoor();
  68.            
  69.         } else if (gDoorState == doorCLOSING) {
  70.             gDoorTransparencyStep += 1;
  71.             llSetAlpha(1.0 - llPow(FADE_BASE, gDoorTransparencyStep), ALL_SIDES);
  72.            
  73.             if (gDoorTransparencyStep >= NUM_TRANSPARENCY_STEPS) {
  74.                 gDoorState = doorCLOSED;
  75.                 llSetTimerEvent(0.0);
  76.                 llSetAlpha(1.0, ALL_SIDES);    
  77.             }
  78.         } else {   // Shouldn't happen, but...
  79.             gDoorState = doorCLOSED;
  80.             llSetTimerEvent(0.0);
  81.             llSetAlpha(1.0, ALL_SIDES);
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement