Advertisement
Dorex

Untitled

Dec 5th, 2023
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //
  3. list linkList;
  4. //
  5. turn_on()
  6. {
  7.     integer count = llGetListLength(linkList);
  8.     while (count--){
  9.         llSetLinkPrimitiveParamsFast(llList2Key(linkList, count), [
  10.                 PRIM_TEXTURE, 1, "UUID", <1.0, 0.5, 0.0>, <0.0, -0.25, 0.0>, 0.0,
  11.                 PRIM_FULLBRIGHT, 1, TRUE]);
  12.                 llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[
  13.                 PRIM_POINT_LIGHT,TRUE,<1,.759,.383>,1,5,.75,
  14.                 PRIM_TEXTURE,0,TEXTURE_BRASS_LIGHT,<1,1,0>,<0,0,0>,0,
  15.                 PRIM_TEXTURE,1,TEXTURE_GLASS_LIGHT,<1,1,0>,<0,0,0>,0,
  16.                 PRIM_TEXTURE,2,TEXTURE_LAMP_LIGHT,<1,1,0>,<0,0,0>,0,
  17.                 PRIM_FULLBRIGHT,1,TRUE,
  18.                 PRIM_FULLBRIGHT,2,TRUE,
  19.                 PRIM_GLOW,1,.05,
  20.                 PRIM_PROJECTOR, "UUID", 0.8, 0.0, 0.0
  21.         ]);  
  22.     }
  23. }
  24.  
  25. default
  26. {
  27.     state_entry()
  28.     {
  29.         linkList = [];
  30.         integer links = llGetNumberOfPrims();
  31.         while (links--){
  32.            if (llSubStringIndex(llGetLinkName(links), "light") > -1){
  33.                 linkList += (list)links;
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39.      
  40.  /////////////////////////////////////////////////////////////////////////
  41.  //
  42.  // Automatic lights on/off with region night/day cycle with fixed override
  43.  //
  44.  // Based on code by Aaack Straaf (Second Life) 09/12/08
  45.  //
  46.  // Modified by Rime Wirsing (InWorldz) 6/11/10
  47.  //
  48.  // Added parameters for all options for easier modification
  49.  // Added comments to help explain what does what
  50.  // Added stay on, stay off, automatic modes selected via menu dialog (owner only)
  51.  // Pulled light on/off code into functions
  52.  //
  53.  /////////////////////////////////////////////////////////////////////////
  54.  
  55. key TEXTURE_BRASS_DARK="UUID";
  56. key TEXTURE_BRASS_LIGHT="UUID";
  57. key TEXTURE_GLASS_DARK="UUID";
  58. key TEXTURE_GLASS_LIGHT="UUID";
  59. key TEXTURE_LAMP_DARK="UUID";
  60. key TEXTURE_LAMP_LIGHT="UUID";
  61.  
  62. //integer lightsLink= 999;
  63.  
  64.  // Menu dialog options
  65. list ActionChoices = ["Stay Off", "Stay On", "Automatic"];
  66. string msg = "\nLight controller \nPlease select an option:";
  67.  
  68. key TouchedByKey;           // Key of avatar triggering touch event
  69. integer channel_dialog;     // Dialog comms channel
  70. integer listen_id;          // Dialog listen ID
  71.  
  72.  // Day night detection parameters
  73. vector sun;             // Store the suns position
  74. integer check_sun = 60; // How often (in seconds) to check sun position
  75.                         // (60 seconds is plenty short enough)
  76.  
  77.  
  78. list linkList;
  79.  
  80. /////////////////////////////////////////////////////////////////////////
  81.  
  82. // Function to turn light on
  83. turn_on()
  84. {
  85.     integer count = llGetListLength(linkList);
  86.     while (count--){
  87.         llSetLinkPrimitiveParamsFast(llList2Key(linkList, count), [
  88.                 PRIM_TEXTURE, 1, "UUID", <1.0, 0.5, 0.0>, <0.0, -0.25, 0.0>, 0.0,
  89.                 PRIM_FULLBRIGHT, 1, TRUE]);
  90.                 llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[
  91.                 PRIM_POINT_LIGHT,TRUE,<1,.759,.383>,1,5,.75,
  92.                 PRIM_TEXTURE,0,TEXTURE_BRASS_LIGHT,<1,1,0>,<0,0,0>,0,
  93.                 PRIM_TEXTURE,1,TEXTURE_GLASS_LIGHT,<1,1,0>,<0,0,0>,0,
  94.                 PRIM_TEXTURE,2,TEXTURE_LAMP_LIGHT,<1,1,0>,<0,0,0>,0,
  95.                 PRIM_FULLBRIGHT,1,TRUE,
  96.                 PRIM_FULLBRIGHT,2,TRUE,
  97.                 PRIM_GLOW,1,.05,
  98.                 PRIM_PROJECTOR, "UUID", 0.8, 0.0, 0.0
  99.         ]);  
  100.     }
  101. }
  102.  
  103.  /////////////////////////////////////////////////////////////////////////
  104.  
  105.  // Function to turn light off
  106. turn_off()
  107. {
  108.     integer count = llGetListLength(linkList);
  109.     while (count--){
  110.         llSetLinkPrimitiveParamsFast(llList2Key(linkList, count), [
  111.             PRIM_TEXTURE, 1, "UUID", <1.0, 0.5, 0.0>, <0.0, 0.25, 0.0>, 0.0,
  112.             PRIM_FULLBRIGHT, 1, FALSE]);
  113.             llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[
  114.             PRIM_TEXTURE,0,TEXTURE_BRASS_DARK,<1,1,0>,<0,0,0>,0,
  115.             PRIM_TEXTURE,1,TEXTURE_GLASS_DARK,<1,1,0>,<0,0,0>,0,
  116.             PRIM_TEXTURE,2,TEXTURE_LAMP_DARK,<1,1,0>,<0,0,0>,0,
  117.             PRIM_TEXTURE,3,TEXTURE_BRASS_DARK,<1,1,0>,<0,0,0>,0,
  118.             PRIM_TEXTURE,4,TEXTURE_GLASS_DARK,<1,1,0>,<0,0,0>,0,
  119.             PRIM_TEXTURE,5,TEXTURE_LAMP_DARK,<1,1,0>,<0,0,0>,0,
  120.             PRIM_FULLBRIGHT,1,FALSE,
  121.             PRIM_FULLBRIGHT,2,FALSE,
  122.             PRIM_GLOW,1,FALSE,
  123. //            PRIM_COLOR,ALL_SIDES,<1,1,1>,0,
  124.             PRIM_POINT_LIGHT, FALSE, <1,1,1>, 1.0, 5.0, 2.0
  125.         ]);
  126.     }
  127. }
  128.  
  129.  /////////////////////////////////////////////////////////////////////////
  130.  
  131.  // The default state
  132. default
  133. {
  134.     state_entry()
  135.     {
  136.         // Generate a unique comms channel for owner control dialog based on object key
  137. //    ScanLinkNames();
  138.         channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
  139.  
  140.         // Default to stay off mode so timer is off
  141.         llSetTimerEvent(0);
  142.  
  143.         linkList = [];
  144.         integer links = llGetNumberOfPrims();
  145.         while (links--){
  146.            if (llSubStringIndex(llGetLinkName(links), "light") > -1){
  147.                 linkList += (list)links;
  148.             }
  149.         }
  150.  
  151.     }
  152.  
  153.  /////////////////////////////////////////////////////////////////////////
  154.  
  155. // Look for owner touch to activate menu
  156. touch_start(integer num_detected)
  157. {
  158.         TouchedByKey = llDetectedKey(0);
  159.         if ( TouchedByKey == llGetOwner() )
  160.         {
  161.             // Generate and display menu dialog
  162.             llDialog(TouchedByKey, msg, ActionChoices, channel_dialog);
  163.  
  164.             // Open a dialog listener specific to the owner
  165.             listen_id = llListen( channel_dialog, "", TouchedByKey, "");
  166.         }
  167.         else
  168.         {
  169.         }
  170. }
  171.  
  172.  /////////////////////////////////////////////////////////////////////////
  173.  
  174. // Detect and act on owners selection from menu dialog
  175. listen(integer channel, string name, key id, string choice)
  176. {
  177.     if (choice == "Stay Off") {
  178.         // Turn off the timer if we switch from automatic
  179.         llSetTimerEvent(0);
  180.  
  181.         // Call the function to turn off the light
  182.         turn_off();
  183.  
  184.         // Kill the listener
  185.         llListenRemove(listen_id);
  186.    
  187.     } else if (choice == "Stay On") {
  188.         // Turn off the timer if we switch from automatic
  189.         llSetTimerEvent(0);
  190.  
  191.         // Call the function to turn off the light
  192.         turn_on();
  193.  
  194.         // Kill the listener
  195.         llListenRemove(listen_id);
  196.    
  197.     } else if (choice == "Automatic") {
  198.         // Turn on the automatic timer
  199.         llSetTimerEvent(check_sun);
  200.  
  201.         // Light will switch state at next timer event
  202.  
  203.         // Kill the listener
  204.         llListenRemove(listen_id);
  205.     }
  206.  
  207. }
  208.  
  209. /////////////////////////////////////////////////////////////////////////
  210.  
  211. // Timer for automatic mode
  212. timer()
  213. {
  214.     sun = llGetSunDirection();
  215.     if (sun.z <= 0.12){ // EEP Sun
  216.         turn_on();
  217.    
  218.     } else {
  219.         turn_off();
  220.     }
  221. }
  222.  
  223.  /////////////////////////////////////////////////////////////////////////
  224. }
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement