Advertisement
Guest User

Untitled

a guest
Aug 12th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer STATE_AlwaysOff = 0;
  2. integer STATE_AlwaysOn = 1;
  3. integer STATE_OnAfterDark = 2;
  4.  
  5. integer iOn = FALSE;
  6. integer iNight = FALSE;
  7. integer iState = STATE_OnAfterDark;
  8.  
  9.  
  10. autoSwitch()
  11. {
  12.     vector vecSun = llGetSunDirection();
  13.    
  14.     iNight = (vecSun.z < 0);
  15.  
  16.     if (iState == STATE_AlwaysOff) {
  17.         iOn = FALSE;
  18.     } else if (iState == STATE_AlwaysOn) {
  19.         iOn = TRUE;
  20.     } else {      
  21.         iOn = iNight;
  22.     }
  23.    
  24.     if (iOn) {
  25.         llSetPrimitiveParams ([ PRIM_POINT_LIGHT, iOn, <1.0, 1.0, 1.0>, 1.0, 8.0, 0.5,
  26.                                     PRIM_GLOW, ALL_SIDES, 0.25 ]);
  27.     } else {
  28.         llSetPrimitiveParams ([ PRIM_POINT_LIGHT, iOn, <1.0, 1.0, 1.0>, 0.0, 0.0, 0.0,
  29.                                     PRIM_GLOW, ALL_SIDES, 0.0 ]);
  30.     }
  31. }
  32.  
  33.  
  34. initialize()
  35. {
  36.     iOn = FALSE;
  37.     iState = STATE_OnAfterDark;
  38.     autoSwitch();
  39.  
  40.     llSetTimerEvent(300);
  41. }
  42.  
  43.  
  44. default
  45. {
  46.     on_rez(integer start_param)
  47.     {
  48.         initialize();
  49.     }
  50.  
  51.    
  52.     state_entry()
  53.     {
  54.         llSetText("NightLight",<1,0,0>,1);
  55.         initialize();
  56.     }
  57.  
  58.        
  59.     timer()
  60.     {
  61.         autoSwitch();
  62.     }
  63.  
  64.  
  65.     touch_start(integer total_number)
  66.     {
  67.         if (iState == STATE_AlwaysOff) {
  68.             iState = STATE_AlwaysOn;
  69.             llWhisper(0, "Lamp is now always on.");
  70.         } else if (iState == STATE_AlwaysOn) {
  71.             iState = STATE_OnAfterDark;
  72.             llWhisper(0, "Lamp will now turn itself on after dark.");
  73.         } else {      
  74.             iState = STATE_AlwaysOff;
  75.             llWhisper(0, "Lamp is now always off.");
  76.         }
  77.        
  78.         autoSwitch();        
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement