Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //
- list linkList;
- //
- turn_on()
- {
- integer count = llGetListLength(linkList);
- while (count--){
- llSetLinkPrimitiveParamsFast(llList2Key(linkList, count), [
- PRIM_TEXTURE, 1, "UUID", <1.0, 0.5, 0.0>, <0.0, -0.25, 0.0>, 0.0,
- PRIM_FULLBRIGHT, 1, TRUE]);
- llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[
- PRIM_POINT_LIGHT,TRUE,<1,.759,.383>,1,5,.75,
- PRIM_TEXTURE,0,TEXTURE_BRASS_LIGHT,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,1,TEXTURE_GLASS_LIGHT,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,2,TEXTURE_LAMP_LIGHT,<1,1,0>,<0,0,0>,0,
- PRIM_FULLBRIGHT,1,TRUE,
- PRIM_FULLBRIGHT,2,TRUE,
- PRIM_GLOW,1,.05,
- PRIM_PROJECTOR, "UUID", 0.8, 0.0, 0.0
- ]);
- }
- }
- default
- {
- state_entry()
- {
- linkList = [];
- integer links = llGetNumberOfPrims();
- while (links--){
- if (llSubStringIndex(llGetLinkName(links), "light") > -1){
- linkList += (list)links;
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////
- //
- // Automatic lights on/off with region night/day cycle with fixed override
- //
- // Based on code by Aaack Straaf (Second Life) 09/12/08
- //
- // Modified by Rime Wirsing (InWorldz) 6/11/10
- //
- // Added parameters for all options for easier modification
- // Added comments to help explain what does what
- // Added stay on, stay off, automatic modes selected via menu dialog (owner only)
- // Pulled light on/off code into functions
- //
- /////////////////////////////////////////////////////////////////////////
- key TEXTURE_BRASS_DARK="UUID";
- key TEXTURE_BRASS_LIGHT="UUID";
- key TEXTURE_GLASS_DARK="UUID";
- key TEXTURE_GLASS_LIGHT="UUID";
- key TEXTURE_LAMP_DARK="UUID";
- key TEXTURE_LAMP_LIGHT="UUID";
- //integer lightsLink= 999;
- // Menu dialog options
- list ActionChoices = ["Stay Off", "Stay On", "Automatic"];
- string msg = "\nLight controller \nPlease select an option:";
- key TouchedByKey; // Key of avatar triggering touch event
- integer channel_dialog; // Dialog comms channel
- integer listen_id; // Dialog listen ID
- // Day night detection parameters
- vector sun; // Store the suns position
- integer check_sun = 60; // How often (in seconds) to check sun position
- // (60 seconds is plenty short enough)
- list linkList;
- /////////////////////////////////////////////////////////////////////////
- // Function to turn light on
- turn_on()
- {
- integer count = llGetListLength(linkList);
- while (count--){
- llSetLinkPrimitiveParamsFast(llList2Key(linkList, count), [
- PRIM_TEXTURE, 1, "UUID", <1.0, 0.5, 0.0>, <0.0, -0.25, 0.0>, 0.0,
- PRIM_FULLBRIGHT, 1, TRUE]);
- llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[
- PRIM_POINT_LIGHT,TRUE,<1,.759,.383>,1,5,.75,
- PRIM_TEXTURE,0,TEXTURE_BRASS_LIGHT,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,1,TEXTURE_GLASS_LIGHT,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,2,TEXTURE_LAMP_LIGHT,<1,1,0>,<0,0,0>,0,
- PRIM_FULLBRIGHT,1,TRUE,
- PRIM_FULLBRIGHT,2,TRUE,
- PRIM_GLOW,1,.05,
- PRIM_PROJECTOR, "UUID", 0.8, 0.0, 0.0
- ]);
- }
- }
- /////////////////////////////////////////////////////////////////////////
- // Function to turn light off
- turn_off()
- {
- integer count = llGetListLength(linkList);
- while (count--){
- llSetLinkPrimitiveParamsFast(llList2Key(linkList, count), [
- PRIM_TEXTURE, 1, "UUID", <1.0, 0.5, 0.0>, <0.0, 0.25, 0.0>, 0.0,
- PRIM_FULLBRIGHT, 1, FALSE]);
- llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[
- PRIM_TEXTURE,0,TEXTURE_BRASS_DARK,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,1,TEXTURE_GLASS_DARK,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,2,TEXTURE_LAMP_DARK,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,3,TEXTURE_BRASS_DARK,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,4,TEXTURE_GLASS_DARK,<1,1,0>,<0,0,0>,0,
- PRIM_TEXTURE,5,TEXTURE_LAMP_DARK,<1,1,0>,<0,0,0>,0,
- PRIM_FULLBRIGHT,1,FALSE,
- PRIM_FULLBRIGHT,2,FALSE,
- PRIM_GLOW,1,FALSE,
- // PRIM_COLOR,ALL_SIDES,<1,1,1>,0,
- PRIM_POINT_LIGHT, FALSE, <1,1,1>, 1.0, 5.0, 2.0
- ]);
- }
- }
- /////////////////////////////////////////////////////////////////////////
- // The default state
- default
- {
- state_entry()
- {
- // Generate a unique comms channel for owner control dialog based on object key
- // ScanLinkNames();
- channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
- // Default to stay off mode so timer is off
- llSetTimerEvent(0);
- linkList = [];
- integer links = llGetNumberOfPrims();
- while (links--){
- if (llSubStringIndex(llGetLinkName(links), "light") > -1){
- linkList += (list)links;
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////
- // Look for owner touch to activate menu
- touch_start(integer num_detected)
- {
- TouchedByKey = llDetectedKey(0);
- if ( TouchedByKey == llGetOwner() )
- {
- // Generate and display menu dialog
- llDialog(TouchedByKey, msg, ActionChoices, channel_dialog);
- // Open a dialog listener specific to the owner
- listen_id = llListen( channel_dialog, "", TouchedByKey, "");
- }
- else
- {
- }
- }
- /////////////////////////////////////////////////////////////////////////
- // Detect and act on owners selection from menu dialog
- listen(integer channel, string name, key id, string choice)
- {
- if (choice == "Stay Off") {
- // Turn off the timer if we switch from automatic
- llSetTimerEvent(0);
- // Call the function to turn off the light
- turn_off();
- // Kill the listener
- llListenRemove(listen_id);
- } else if (choice == "Stay On") {
- // Turn off the timer if we switch from automatic
- llSetTimerEvent(0);
- // Call the function to turn off the light
- turn_on();
- // Kill the listener
- llListenRemove(listen_id);
- } else if (choice == "Automatic") {
- // Turn on the automatic timer
- llSetTimerEvent(check_sun);
- // Light will switch state at next timer event
- // Kill the listener
- llListenRemove(listen_id);
- }
- }
- /////////////////////////////////////////////////////////////////////////
- // Timer for automatic mode
- timer()
- {
- sun = llGetSunDirection();
- if (sun.z <= 0.12){ // EEP Sun
- turn_on();
- } else {
- turn_off();
- }
- }
- /////////////////////////////////////////////////////////////////////////
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement