2 // huffware script: hour hand, modified by fred huffhines.
4 // expanded to support time zones by fred huffhines, december 2009.
6 // noticed this in arcadia asylum's great hobo cuckoo clock.
7 // this script is licensed by Beezle Warburton:
8 // "I released those 'into the wild' years ago,do what you like,
9 // I just ask that people don't resell the scripts by themselves."
11 // fred's changes licensed by:
12 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
13 // do not use it in objects without fully realizing you are implicitly accepting that license.
15 // Optional second hand will be a much simpler script that will be
16 // unrelated to real-time.
18 // note - to reduce load, this script only calculates once a minute, so
19 // this provides a jump style minute hand, rather than a smoothy rotating one.
20 // This (and rounding) makes the clock's accuracy +/- 1 minute.
21 // It's a prim clock anyways, so digital accuracy is just excessive.
23 // It would probably be more elegant to use link messages rather than each
24 // hand having it's own script, however, this method allows for less caution
25 // when linking/unlinking parts of the clock.
27 // To not mess up timekeeping, please keep chime sounds under 4 seconds long.
39 string chimesound = "CuckooClock";
40 float chimevolume = 1.0;
42 // this is what might be adjusted.
43 integer LOCAL_TIME_ZONE_OFFSET = -5; //-5 is EST, -8 is PST.
45 // the code used in linked messages for us.
46 integer SECRET_TIME_ZONE_ADJUSTER_ID = -2091823;
47 string TIME_ZONE_ADJUST_COMMAND = "tzadjust";
51 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
52 on_rez(integer parm) { state rerun; }
54 state rerun { state_entry() { state default; } }
60 // we want to calculate once a minute.
61 llSetTimerEvent(60.0);
65 time = (integer)llGetGMTclock(); // seconds since midnight
66 // adjust the hours for the time zone. this will work for most time zones that
67 // go through daylight saving time, like the pacific zone where SL is rooted.
68 hours = (time / 3600) + LOCAL_TIME_ZONE_OFFSET;
69 // convert from 24 to 12 hour time
72 } else if (hours < 0) {
75 minutes = (time % 3600) / 60;
77 numrings = (integer)hours;
82 // the extra addition here makes a smooth hour hand
83 // for example, at 6:30, the hour hand should actually
84 // be halfway between 6 and 7 on the clock dial
86 anglehours = - (((float)hours / 12) + (((float)minutes / 720))) * TWO_PI;
87 //incompatible with opensim: llSetSoundQueueing(TRUE);
88 llRotateTexture(anglehours, ALL_SIDES);
90 llMessageLinked(-1,numrings,"chime",NULL_KEY);
91 //for (chime = 0; chime < numrings; chime++) {
92 // llPlaySound(chimesound, chimevolume);
96 llSetTimerEvent(60.0);
99 link_message(integer sender, integer num, string msg, key id) {
100 if ( (num != SECRET_TIME_ZONE_ADJUSTER_ID) || (msg != TIME_ZONE_ADJUST_COMMAND) )
101 return; // not for us.
102 // this should be a time zone for us to use.
103 LOCAL_TIME_ZONE_OFFSET = (integer)((string)id);
104 //llSay(0, "got a new time zone of " + (string)LOCAL_TIME_ZONE_OFFSET );
105 // handle this update as soon as possible.
106 llSetTimerEvent(0.1);