Advertisement
Mayumi_H

Light on off automatically by day cycle.lsl

Apr 20th, 2022 (edited)
2,534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //MH+ presents, Light on off automatically by day cycle
  2. //join us! => https://discord.me/SLguru
  3. //visit my blog => https://sl-memo.blogspot.com/
  4. //地域に設定された日周期から昼夜判別をして自動で照明のOn/Offを行うサンプルです
  5. //
  6. integer ONOFF;
  7. vector color    = <1,1,1>;
  8. float intensity = 1.0;
  9. float radius    = 5.0;
  10. float falloff   = 0.75;
  11. integer face = 1;
  12. float glow      = 0.5;
  13. float check_sec = 30.0;
  14.  
  15. SW(){
  16.     llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_POINT_LIGHT, ONOFF, color, intensity, radius, falloff
  17.                                           ,PRIM_FULLBRIGHT, face, ONOFF
  18.                                           ,PRIM_GLOW,       face, ((float)ONOFF)*glow]);
  19. }
  20.  
  21. default{
  22.     state_entry(){
  23.         SW();
  24.         llSetTimerEvent(check_sec);
  25.     }
  26.  
  27.     touch_start(integer total_number){
  28.         ONOFF = !ONOFF;
  29.         SW();
  30.         llSetTimerEvent(3600.0);//1時間後に再始動
  31.     }
  32.    
  33.     timer(){
  34.         //現在時刻の計算
  35.         float timeOfDay = (llGetUnixTime() + llGetDayOffset()) % llGetDayLength() * 1.0 / llGetDayLength();
  36.         integer hours   = (integer)(timeOfDay * 24);
  37.         integer minutes = (integer)(timeOfDay * 24 * 60) % 60;
  38.         integer now_time = (integer)((string)hours + llGetSubString((string)(100+minutes), 1, 2));
  39.  
  40.         //日周期からの時刻で昼夜判別
  41.         integer NightMode = !((now_time >= 0300) && (now_time < 2100));
  42.  
  43.         if(NightMode != ONOFF){
  44.             ONOFF = NightMode;
  45.             SW();
  46.         }
  47.         llSetTimerEvent(check_sec);
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement