Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

light on/off based on time of day (sun position)?

Alpha Vargas
Crisis Core addict
Join date: 6 Mar 2006
Posts: 96
03-29-2006 04:47
I know I've seen the script before, I just can't remember where.
I need a script that will turn a light (the object I'm putting the script in) on or off, based on the time of day.
I don't know how that works, but is it possible to have a soft light "glow" at night, and disable it in daylight hours? Would that be a particle or not? Is it laggy?
It's a small light, it only needs to illuminate maybe a 2m radius.

Any and all help & scripts is/are appreciated. Thank you!

You can IM me in SL (Alpha Vargas), or just post here. =P
_____________________
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
03-29-2006 05:11
CODE
// Daytime/nighttime script
// Ordinal Malaprop
// 2006-03-29

integer daytime()
{
vector pos = llGetSunDirection();
if (pos.z > 0) return TRUE;
else return FALSE;
}

default
{
state_entry()
{
if (!daytime()) state night;
llSetTimerEvent(300.0);
// then your daytime code here
}

timer()
{
if (!daytime()) state night;
}
}

state night
{
state_entry()
{
if (daytime()) state default;
llSetTimerEvent(300.0);
// then your nighttime code here
}

timer()
{
if (daytime()) state default;
}
}


As for the light effect itself... you could use llSetPrimitiveParams to change the item from normal to full bright, or from glass to light material... You could indeed add a big emissive particle as a glow with PSYS_SRC_PATTERN_DROP, but I find that that sort of use is rather unreliable, and it would be a little laggy.

You could have a "light glow" prim surrounding it that listened for a command to turn on and off. My lighthouse has two large beams that appear at night, for instance.
Alpha Vargas
Crisis Core addict
Join date: 6 Mar 2006
Posts: 96
03-29-2006 05:17
thanks for the code!

uh, how do I use llSetPrimitiveParams? I'm *very* new to scripting.

I'm trying to put a small light "glow" underneath an unside-down "cup", to light up a small area of water in the center of the fountain. Would an object or a particle be better for that?

Sorry for all the questions... I'm still a newbie. ^^;
_____________________
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
03-29-2006 05:26
Probably a primitive if it's just a directional light.

Here's a simple one: If you make, say, a cone or cylinder type thing and put it underneath the lamp, to be the light beam itself, setting it to have partial transparency probably or using a texture, then put that script in it and edit it so that it calls

llSetAlpha(0.0, ALL_SIDES);

when it's daytime and

llSetAlpha(0.5, ALL_SIDES);

at night - assuming you've given it 50% transparency - that should work.

Or, alternatively, you could use a texture. I have a fading light beam texture that I use but I'm at work right now so can't give it to you at the moment. (I should put it in my freebie giver, come to think of it.)
Alpha Vargas
Crisis Core addict
Join date: 6 Mar 2006
Posts: 96
03-29-2006 05:41
hmm, thanks. I think I can apply that to a sphere, too.
I'll mess around with sticking in a small "glowing" particle effect too.

Quick question about LSL format:
when I stick some code in for the day and night states, do I have to further indent the particle script I've inserted? (you know how those things have a ton of brackets and whatnot)

Thanks again for all your help. =D
_____________________
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
03-29-2006 05:48
You don't have to indent anything, it just makes it more readable.
Alpha Vargas
Crisis Core addict
Join date: 6 Mar 2006
Posts: 96
03-29-2006 06:09
really? I thought languages like these were really picky about that.
Ok then!

if you're not busy, do you think you could stop by? I'm still not sure where I'm going with this light thing. Thanks for the night/day script, though! That's a huge help! I can copy and transfer that, right?

EDIT: nvm, I think I got it.
_____________________