Jump to content

Simple light controller - review


Alicia Sautereau
 Share

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

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

Recommended Posts

Hello all :)

After getting back and shopping for some new furniture i discoverd a commen trend amongst creators...
After discovering that no-mod lamps have the light radius and intensity of a rocket launch, i`ve decided to make a lil script quickly  so that our great furniture creators hopefully let us edit the light settings on their no-mods :)

Posting it here in the hope some could improve the script befor i post it in the library as i am no great scripter, but get the job done 1 way or another ;) 

 

Thanks :)

 

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  = 0;    // 0 = off, 1 = on, 2 = sun controlled
integer dState  = 0;    // 0 = main, 1 = intensity, 2 = falloff, 3 = radius

key     User;
integer listner;

float   sunTimer    = 60.0; // 1 minute
vector  lColor      =  <1.0, 0.8, 0.6>;
integer lLinkBulbs  = FALSE; // Set all linked "bulb" prims to emit light  TRUE = yes, FALSE = fullbright
float   lIntensity  = 0.6;  // Light intesity (doh)
float   lFalloff    = 0.6;  // Light falloff (double doh)
float   lRadius     = 10.0; // Light radius (oh c`mon, like you didn`t guess that one coming...)


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     = ["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, lColor, lIntensity, lRadius, lFalloff]); }
            if (lLinkBulbs && (lState == 1 || (lState == 2 && sunDir.z <  0)))  { llSetLinkPrimitiveParams( i, [PRIM_POINT_LIGHT,TRUE, lColor, lIntensity, lRadius, lFalloff]);}
        
            // 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, lColor, 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]);}
        }
    }
}




default
{
    on_rez(integer init)
    {
        // Allways cool to have!
        llResetScript();
    }
    
    
    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???
        doLight();
    }    
    
    touch_start(integer total_number)
    {
        // Well, we are the user, gimme dialog! :)
        User = llDetectedKey(0);
        listner = llListen(cmdChannel, "", "", "");
        
        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"); }
        if (dC == "light on")   { lState = 1; llListenRemove(listner); llSetTimerEvent(0.0); llSay(0, "Light on"); }
        if (dC == "light sun")  { lState = 2; llListenRemove(listner); llSetTimerEvent(sunTimer); sunDir = llGetSunDirection(); llSay(0, "Sun controlled"); }
        if (dC == "back")       { dState = 0; llDialog(User,"\nLight controller:\n", dM, cmdChannel); llSetTimerEvent(sunTimer); }
        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 == "--" && dState == 1) { lIntensity = lIntensity - 0.1;     llDialog(User,"\nLight intensity:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "++" && dState == 1) { lIntensity = lIntensity + 0.1;     llDialog(User,"\nLight intensity:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "--" && dState == 2) { lFalloff = lFalloff - 0.1;         llDialog(User,"\nLight falloff:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "++" && dState == 2) { lFalloff = lFalloff + 0.1;         llDialog(User,"\nLight falloff:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "--" && dState == 3) { lRadius = lRadius - 1.0;           llDialog(User,"\nLight radius:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        if (dC == "++" && dState == 3) { lRadius = lRadius + 1.0;           llDialog(User,"\nLight radius:\n",  dPM, cmdChannel); llSetTimerEvent(sunTimer); }
        doLight();
    }
    
    
    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(); }
    }
}

 

Link to comment
Share on other sites

there is already a script out there that gives a menu to adjust lighting levels.... the problem is it is not reliable... i build lighting and i never put the brightest level of light in... the script that is out there also does not do a very good job if at all of giving "glow" where it belongs, or "corona" where it belongs, or of "lightbeam" effect... if you want to visit my shop.... your more than welcome to... and i will be glad to show you some of what i mean...

http://slurl.com/secondlife/Neveryear/26/118/69

 

Link to comment
Share on other sites

Seems you only set the timer if sun controlled, so the listen is removed for the top 4 buttons but for the rest just sits there.

But that's details... A bigger thing is that your lamp can have only one lightbulb...what if there are several?

The script would be much more general if it made a list of light-emitting links somewhere in the state_entry and then did llSetLinkPrimitiveParams() on that list. But then of course it'd be too good to be free :)

 

Link to comment
Share on other sites

*oops* got me there with the listner lol, was a quick script while building my house to settle in and configuring a webserver for my next few projects so missed it :P

On the multiple lights, getting tempted to add that now tho i hate linksets as it`s never "fixed"
 

A script is never to good to be free, give me a few weeks and i`ll prove it with making some enemies with tier/rental/vendor system operators to start with :D

Link to comment
Share on other sites

Ok a quick change on Ela`s idea :)

Now you can drop it in the root prim
Rename all prims that are the light bulbs to "bulb"
Added an extra var lLinkedBulbs to set fullbright only or fullbright+light
*Edit* If lLinkBulbs i set to FALSE, the root prim will set the light but NOT full bright :)

Fixed the open listner :)

The object creator can set the default light behavior in the default variables ontop, default on/of/intensity/falloff/radius/color, i have just set it to off as default 

In the default state doLight() grabs the default settings and applies them immidiatly :)

 

 

 

Never stopped loving the wiki :D

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4549 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...