Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

SL1.3-enchanced automatic light control

Chromal Brodsky
ExperimentalMetaphysicist
Join date: 24 Feb 2004
Posts: 243
04-01-2004 14:48
This post contains two versions of the script. The first version will simply turn the light on (by setting the prim to LIGHT) at dusk and off (by setting the prim to GLASS) at dawn.

CODE

// My Light Control (no dataserver)
// Chromal Brodsky
// v0.0.4 - 2004-03-30
//
// Controls a light based upon the virtual time of day.
//
// v0.0.1 - 0.0.3 - initial revs
// v0.0.4 - uses the new llSetPrimitiveParams() call to disable client light rendering when off!

float fTime = 0;
float fDayThresh = 0.66;
float fNightThresh = 3.46;
integer iTimerSecs = 300;
string sOutPre;

init()
{
sOutPre = llGetScriptName() + ": ";

refresh();
llSetTimerEvent(iTimerSecs);

llWhisper(0, sOutPre + (string)fTime + ": startup...");
llWhisper(0, "Timer interval is: " + (string)iTimerSecs + " seconds.");
}

refresh()
{
fTime = llGetTimeOfDay() / 3600.0;
}

set_light(integer iOn)
{
if (iOn == TRUE)
{
llSetPrimitiveParams( [PRIM_MATERIAL, PRIM_MATERIAL_LIGHT] );
}
else
{
llSetPrimitiveParams( [PRIM_MATERIAL, PRIM_MATERIAL_GLASS] );
}
}

integer IsDay(float fTimeOfDay)
{
integer iDay;

if ( fTimeOfDay > fDayThresh && fTimeOfDay < fNightThresh )
{
iDay = TRUE;
}
else
{
iDay = FALSE;
}

return iDay;
}

default
{
state_entry()
{
init();
if ( IsDay(fTime) )
{
state Day;
}
else
{
state Night;
}
}
}

state Day
{
state_entry()
{
refresh();
set_light( FALSE );
}

timer()
{
refresh();
if ( !IsDay(fTime) )
{
state Night;
}
}
}

state Night
{
state_entry()
{
refresh();
set_light( TRUE );
}

timer()
{
refresh();

if ( IsDay(fTime) )
{
state Day;
}
}
}


The second version will do the same thing as the first with a twist-- the light will only be turned on at night if the owner is connected.

CODE

// My Light Control
// Chromal Brodsky
// v0.0.4 - 2004-03-30
//
// Controls a light based upon the virtual time of day and owner's online status.
//
// v0.0.1 - 0.0.3 - initial revs
// v0.0.4 - uses the new llSetPrimitiveParams() call to disable client light rendering when off!

float fTime = 0;
float fDayThresh = 0.66;
float fNightThresh = 3.46;
integer iIsOnline = FALSE;
integer iTimerSecs = 30;
string sOutPre;

init()
{
sOutPre = llGetScriptName() + ": ";

refresh();
llSetTimerEvent(iTimerSecs);

llWhisper(0, sOutPre + (string)fTime + ": startup...");
llWhisper(0, "Timer interval is: " + (string)iTimerSecs + " seconds.");
}

refresh()
{
fTime = llGetTimeOfDay() / 3600.0;
llRequestAgentData( llGetOwner(), DATA_ONLINE );
}

set_light(integer iOn)
{
if (iOn == TRUE)
{
llSetPrimitiveParams( [PRIM_MATERIAL, PRIM_MATERIAL_LIGHT] );
}
else
{
llSetPrimitiveParams( [PRIM_MATERIAL, PRIM_MATERIAL_GLASS] );
}
}

integer IsDay(float fTimeOfDay)
{
integer iDay;

if ( fTimeOfDay > fDayThresh && fTimeOfDay < fNightThresh )
{
iDay = TRUE;
}
else
{
iDay = FALSE;
}

return iDay;
}

default
{
state_entry()
{
init();
if ( IsDay(fTime) )
{
state Day;
}
else
{
state Night;
}
}

}

state Day
{
state_entry()
{
refresh();
set_light( FALSE );
}

timer()
{
refresh();
if ( !IsDay(fTime) )
{
state Night;
}
}

dataserver( key kOwner, string sIsOnline )
{
iIsOnline = (integer)sIsOnline;
}
}

state Night
{
timer()
{
refresh();

if ( IsDay(fTime) )
{
state Day;
}

if (iIsOnline)
{
set_light( TRUE );
}
}

dataserver( key kOwner, string sIsOnline )
{
iIsOnline = (integer)sIsOnline;
}
}


If everybody uses these scripts, we can cut down on the client render-local-light load during the day and make everyons client FPS higher. Please use it! A light left running during the day isn't just wasteful of electricity! It's also wasteful of my client CPU!
Lumiere Noir
Ivory Tower Dweller
Join date: 25 Dec 2003
Posts: 212
04-30-2004 23:54
I feel a bit silly posting this here, I have a light that I believe does the same thing as your first version, but nowhere near as gracefully, I'm sure. It's a rather simple, brute force method as most of my scripting is. Every five minutes it checks for the height of the virtual sun, and if it's Z height is below zero, it turns on the light. If the sun'z Z height is above zero, it turns off the light. I've discected this from other scripts and the like. Can't take any credit for it but it's simple enough for me to understand.

////////////////////////////////////////////////
default
{
state_entry()
{
llSetTimerEvent(300.0);
}

timer()
{
vector sun_dur = llGetSunDirection();
if (sun_dur.z > 0)
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_STONE]);
else
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_LIGHT]);
}
}
////////////////////////////////////////////////

Lumi
_____________________
Want to learn to build? Visit the Ivory Tower Library of Primitives at Natoma (205, 170)

Have an Edifice Complex? Join the building group Edifice Rex, IM me by name!

PrimWiki! http://ivorytowerlibrary.com/primwiki
Ivory Tower Forums http://ivorytowerlibrary.com/forums
Natoma Picayune http://ivorytowerlibrary.com
Jim Bunderfeld
The Coder
Join date: 1 Mar 2004
Posts: 161
Re: SL1.3-enchanced automatic light control
05-02-2004 17:43
Thank you for the update version Chromal! ^__^
Chromal Brodsky
ExperimentalMetaphysicist
Join date: 24 Feb 2004
Posts: 243
05-11-2004 12:55
From: someone
I feel a bit silly posting this here, I have a light that I believe does the same thing as your first version, but nowhere near as gracefully, I'm sure.


Hehe, methinks I detect a little false modesty. Your script is definitely doing this with a minimum number of lines. You might want to consider making a version that only makes the llSetPrimitiveParams() call during a change from day to night or vice-versa-- each call may be producing a full object update. (Now I am going have to check and see if its "smart" enough to not full-update when the object is changed to an identical version of itself).

This approach has another advantage-- heavily loaded sims will actually fall off of schedule if their time-dilation falls below 1.00 for any length of time, though they seem to be "synchronized" to 0000 SLT (SecondLife Time) in unison with all the other sims, so it can unpredictably go from 2h38m to 0h00m, depending upon sim load-- sun position avoids this.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
Oil on the fire.
05-12-2004 21:05
From: someone
Originally posted by Chromal Brodsky
You might want to consider making a version that only makes the llSetPrimitiveParams() call during a change from day to night or vice-versa-- each call may be producing a full object update.


CODE

integer e;

default
{
state_entry()
{
llSetTimerEvent(300.0);
}

timer()
{
vector sun_dur = llGetSunDirection();
integer a=(sun_dur.z<0)*(PRIM_MATERIAL_STONE - PRIM_MATERIAL_LIGHT) + PRIM_MATERIAL_LIGHT;
if (e!=a)
llSetPrimitiveParams([PRIM_MATERIAL,e=a]);
}
}


couldn't resist.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey