Weekly Raffle
Top Free Scripts
ASD Web Tools
Day/Night Script
 
Script ID : 39
Published Date: 2010/5/12 5:16:41
Reads : 5111
Time

Keeps track if the sun in a region is day or night.

You can use this script to turn a light on automatically when it becomes night time and off in the day. Just add your script snippets where it says "Do something here" below.

integer time 120//How many seconds between checking
integer IsDay;

Check()
{
    
vector sun_dir llGetSunDirection(); //gets sun direction

    
if (sun_dir.&& IsDay == FALSE//a positive value for sun_dir.z means its daytime
    
{
        
IsDay TRUE;
        
//Do something here for when it is day.
    
}
    else if (
sun_dir.&& IsDay == TRUE//a negative value for sun_dir.z means its nighttime
    
{
        
IsDay FALSE;
        
//Do something here for when it is night.
    
}
}

default
{
    
on_rez(integer start_param)
    {
        
llResetScript();
    }
    
    
state_entry()
    {
        
vector sun_dir llGetSunDirection();
        
IsDay = (sun_dir.0);
        
Check();
        
llSetTimerEvent(time);
    }

    
timer()
    {
        
Check(); //this calls the function to check the day / night status
    
}

    
touch_start(integer total_number//only for debug - can be removed
    
{
        
Check();
        if (
IsDay == TRUE)
        {
            
llSay(0"It is currently day.");
        }
        else
        {
            
llSay(0"It is currently night.");
        }
    }
}

Printer Friendly Page Send this Script to a Friend

Disclaimer: While I do not mind if these scripts are used in things you sell, I do not wish for these scripts to be sold either on their own or in script packs.
Most Popular Raffle System In Second Life
Visit ASD Studios Hollywood
Search for Help
Monthly Free Item
Tip All Tip Chest


Limit one per avatar
Teleport Now!



Sponsor

Site Info
Total Hits: