Jump to content

Light controller


Alicia Sautereau
 Share

You are about to reply to a thread that has been inactive for 3089 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Relative simple light controller ;)

 

Create your linkset and drop this script into the root
Name each light bulb prim "bulb"
 If lLinkBulbs = TRUE, all bulbs will set fullbright + light
if lLinkBulbs = FALSE, all bulbs will set fullbright but the root prim will be the light source instead 

////////////////////////////////////////////////////////
// Simple light controller
// Created by Alicia Sautereau
//
// Free to improve, but sharing would be great :)
// Free for personal use
// Free to be resold in your products
// Free to sell the script as-is/no-mod, but your an arse then...
//
// Created 27/12/2011
////////////////////////////////////////////////////////


vector  sunDir;         // Vector as we use a function
integer cmdChannel  = -900101; // Dialog channel we recieve commands on

integer lState  = 2;    // 0 = off, 1 = on, 2 = sun controlled
integer dState  = 0;    // 0 = main, 1 = intensity, 2 = falloff, 3 = radius, 4 = glow

key     User;
integer listner;

float   sunTimer    = 60.0;     // 1 minute
vector  lColorOff   = <222, 187, 153>; // Color of the prim when the light is off (255 = white)
vector  lColorOn    = <222, 187, 153>; // These are the RGB values as you see in the color picker
integer lLinkBulbs  = TRUE;     // Set all linked "bulb" prims to emit light  TRUE = yes, FALSE = fullbright
float   lIntensity  = 0.6;      // Light intesity (doh)
float   lFalloff    = 0.5;      // Light falloff (double doh)
float   lRadius     = 6.0;      // Light radius (oh c`mon, like you didn`t guess that one coming...)
float   lGlow       = 0.45;     // Glow amount, steps of 0.05
float   lGlowDefault = 0.05;    // Amount of glow when the light is off


list order_buttons(list buttons)
{
    // Kinda pointless, but gotta have it as orderd buttons are cool xD
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4)
         + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
} 

// As complicated as this looks, bad joke, we can`t be arsed to copy the dialog text 10 times :)
list dM     = ["Glow", "Show Settings", "Exit", "Intensity", "Falloff", "Radius", "Light On", "Light Off", "Light Sun"];
list dPM    = ["--", "++", "Back"];



// No, it`s not the God function, christ...
doLight()
{
    integer i = llGetNumberOfPrims();
    for (; i >= 0; --i)
    {
        if (llGetLinkName(i) == "bulb")
        {
            // We love burning electricity, ON!
            if (lState == 1 || (lState == 2 && sunDir.z <  0)) { llSetLinkPrimitiveParams( i, [PRIM_FULLBRIGHT, ALL_SIDES, TRUE]);}
            if (!lLinkBulbs && (lState == 1 || (lState == 2 && sunDir.z <  0))) { llSetLinkPrimitiveParams( 1, [PRIM_POINT_LIGHT,TRUE, (lColorOn/255), lIntensity, lRadius, lFalloff]); }
            if (lLinkBulbs && (lState == 1 || (lState == 2 && sunDir.z <  0)))  { llSetLinkPrimitiveParams( i, [PRIM_POINT_LIGHT,TRUE, (lColorOn/255), lIntensity, lRadius, lFalloff, PRIM_GLOW, ALL_SIDES, lGlow, PRIM_COLOR, ALL_SIDES, (lColorOn/255), 1]); }
        
            // Ok, we`re kindof green...off :/ 
            if (lState == 0 || (lState == 2 && sunDir.z > 0)) { llSetLinkPrimitiveParams( i, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE]);}
            if (!lLinkBulbs && (lState == 0 || (lState == 2 && sunDir.z >  0))) { llSetLinkPrimitiveParams( 1, [PRIM_POINT_LIGHT,FALSE, (lColorOn/255), lIntensity, lRadius, lFalloff]); }
            if (lLinkBulbs && (lState == 0 || (lState == 2 && sunDir.z > 0)))  { llSetLinkPrimitiveParams( i, [PRIM_POINT_LIGHT, FALSE, <0.0,1.0,0.0>,1.0, 10.0, 0.5, PRIM_GLOW, ALL_SIDES, lGlowDefault, PRIM_COLOR, ALL_SIDES, (lColorOff/255), 1]); }
        }
    }
}




default
{
    on_rez(integer init)
    {
        // Allways cool to have!
    }
    
    
    state_entry()
    {
        // We could say something else, but "active" will let us know we didn`t kill the script engine, feel free to remove :)
        llSay(0, "Active");
        
        // We are God, and there shall be, darkness???
        if (lState == 2) { llSetTimerEvent(sunTimer); sunDir = llGetSunDirection(); }
        doLight();
    }    
    
    touch_start(integer total_number)
    {
        // Well, we are the user, gimme dialog! :)
        User = llDetectedKey(0);
        listner = llListen(cmdChannel, "", llGetOwner(), "");
        
        llDialog(User, "\nLight controller:\n", dM,  cmdChannel);
    }    

    listen(integer cmdChannel, string name, key id, string dC)
    {
        // Stop reading right here, i know i did...
        dC = llToLower(dC);
        if (dC == "exit")       { dState = 0; llListenRemove(listner);}
        if (dC == "light off")  { lState = 0; llListenRemove(listner); llSetTimerEvent(0.0); llSay(0, "Light off"); doLight(); }
        if (dC == "light on")   { lState = 1; llListenRemove(listner); llSetTimerEvent(0.0); llSay(0, "Light on"); doLight(); }
        if (dC == "light sun")  { lState = 2; llListenRemove(listner); llSetTimerEvent(sunTimer); sunDir = llGetSunDirection(); llSay(0, "Sun controlled"); doLight(); }
        if (dC == "back")       { dState = 0; llDialog(User,"\nLight controller:\n", dM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "intensity")  { dState = 1; llDialog(User,"\nLight intensity:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "falloff")    { dState = 2; llDialog(User,"\nLight falloff:\n",    dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "radius")     { dState = 3; llDialog(User,"\nLight radius:\n",     dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "glow")       { dState = 4; llDialog(User,"\nLight glow:\n",       dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "--" && dState == 1) { lIntensity = lIntensity - 0.1;     llDialog(User,"\nLight intensity:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "++" && dState == 1) { lIntensity = lIntensity + 0.1;     llDialog(User,"\nLight intensity:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "--" && dState == 2) { lFalloff = lFalloff - 0.1;         llDialog(User,"\nLight falloff:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "++" && dState == 2) { lFalloff = lFalloff + 0.1;         llDialog(User,"\nLight falloff:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "--" && dState == 3) { lRadius = lRadius - 1.0;           llDialog(User,"\nLight radius:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "++" && dState == 3) { lRadius = lRadius + 1.0;           llDialog(User,"\nLight radius:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "--" && dState == 4) { lGlow = lGlow - 0.05;          llDialog(User,"\nLight glow:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "++" && dState == 4) { lGlow = lGlow + 0.05;          llDialog(User,"\nLight gLow:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); doLight(); }
        if (dC == "show settings") { llSay(0, "Intensity: "+ (string)lIntensity +", Falloff: "+ (string)lFalloff +", Radius: "+(string) lRadius +", Glow: "+ (string)lGlow +", Color: "+ (string)lColorOn ); llDialog(User, "\nLight controller:\n", dM,  cmdChannel); }
    }
    
    
    timer()
    {
        // Kill listner just incase the user pressed ignore (to bad if he started it right befor the timer hits :))
        llListenRemove(listner);
        if (lState != 2) { llSetTimerEvent(0.0); }
        
        // Can some one tell us where the sun is? please?
        if (lState == 2) { sunDir = llGetSunDirection(); doLight(); }
    }
}

 


  • Like 2
Link to comment
Share on other sites

Small revision:

Re-added the exit button

Removed the doLight() at the end of the listner to the end of each command
Added a "show settings" button that says the current values in local, easy for making this the default light values when you have found a good settin, also works better when copy&ing the object for identical values. 

Link to comment
Share on other sites

Another addon:

Added a glow option, 0.05 steps
Added a default glow value for when the light is turned off (for who wants it)

Added a RGB conversion, now you can just input the RGB values from the color picker :matte-motes-silly: 

Added a color value for when the light is off
Light bulb now changes into the light color used

Use a bright color, say white, for when the light is turned on and use a dark gray color when it`s turned off or keep both values the same 

 

Link to comment
Share on other sites

  • 6 months later...
  • 2 years later...
  • 1 year later...
You are about to reply to a thread that has been inactive for 3089 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...