Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

GetIsNight

Artemis Tesla
Junior Member
Join date: 24 Aug 2003
Posts: 9
09-19-2003 20:13
Didnt see it anywhere.. so here goes

On the object that will rez the light object
______________________________________
CODE

//By Artemis Tesla
//With math help from Kanker Greenacre

integer iNightBegin;

default
{
state_entry()
{
iNightBegin = TRUE;

llSetTimerEvent(10);
}

timer()
{
vector vSunDir = llGetSunDirection();

float fElevAngle = llAsin(vSunDir.z);
fElevAngle = fElevAngle * RAD_TO_DEG;

//If Night and begining of night
if ((fElevAngle <= -10.0) && (iNightBegin))
{
llRezObject("light",< PLACE POSITION VECTOR HERE >,<0,0,0>,<0,0,0,0>,0);
iNightBegin = FALSE;
}
if ((fElevAngle >= -10.0) && (!iNightBegin))
{
llSay( CHANNEL HERE,"LIGHTS OFF");
iNightBegin = TRUE;
}
}
}


on the light object
______________________________________

//By Artemise Tesla
CODE

default
{
state_entry()
{
llListen(REZZING OBJECT CHANNEL HERE,"REZZING OBJECT NAME HERE", "REZZING OBJECT KEY HERE","LIGHTS OFF");
}

listen(integer channel, string name, key id, string message)
{
llDie();
}
}


And thats it...

If you see any tweaks please let me know..

Artemis Tesla
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
09-20-2003 12:48
Hm I just wonder because I always thought you could tell night much simpler. I thought if the z component of the llGetSunDirection() vector was negative then it was night, if it was positive it was day?
Tyger Lily
Junior Member
Join date: 21 Sep 2003
Posts: 15
10-17-2003 14:53
Does this measure some absolute sun direction? How is it affected by "Mouse Moves Sun" or "Force Sunset"?
Hawk Statosky
Camouflage tourist
Join date: 11 Nov 2003
Posts: 175
11-20-2003 06:27
As far as I can tell, Force Sunset and Mouse Moves Sun are clientside effects so that Joe User can play around with object lighting - the scripts would be reporting the official sun position as calculated on the sim, if my guess is right.

Maybe needs testing.
Harald Nomad
Villager
Join date: 28 May 2003
Posts: 123
11-27-2003 08:22
Yup, Force Sunset is client side and does not influence script execution.

You may want to turn the lights on a little early, as in vSun.z < 0.1 = turn lights on, vSun.z > 0.1 = turn them off.

Now combine this with an IS_ON, either clickable for regular lamps, or activated for vehicles, and we're in business.

All we need now, is to stop paying ridiculous energybills when the lights are not even on. llSetMaterial()...?
Darwin Appleby
I Was Beaten With Satan
Join date: 14 Mar 2003
Posts: 2,779
11-27-2003 10:32
My guess is it reports the sun direction from the owner. The client needs to know the sun direction anyway because the client needs to calculate light etc...
_____________________
Touche.
Ezhar Fairlight
professional slacker
Join date: 30 Jun 2003
Posts: 310
11-27-2003 12:34
Darwin, scripts don't run on the client, they run on the server, which is not informed if you misplace your local sun :)
Kex Godel
Master Slacker
Join date: 14 Nov 2003
Posts: 869
11-29-2003 00:55
This is what I've been using:
CODE

default
{
state_entry()
{
}

touch_start(integer total_number)
{
vector v = llGetSunDirection();
float z = v.z;
if(z >0){
llSay(0,"It is day-time");
}else{
llSay(0,"It is night-time");
}
}
}