2 // huffware script: fade opacity, by fred huffhines, bsd-style license.
4 // when the object is touched, the opacity changes towards either
5 // totally transparent or totally opaque. when touch stops, the
6 // changes stop. the next time the objects is touched, the opacity
7 // changes in the opposite direction.
9 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
10 // do not use it in objects without fully realizing you are implicitly accepting that license.
13 // modifiable parameters for the fading...
15 integer SWITCH_ONLY = FALSE; // if true, does not fade, just switches on and off.
17 float pace_increment = 0.02; // how much we change transparency in one timer call.
19 float timer_interval = 0.1; // how frequently timer is hit.
21 float highest_opacity = 1.0; // the most visible an object can be.
23 float lowest_opacity = 0.0; // the least visible an object can be.
25 //integer FADE_TARGETS = LINK_THIS; // affect only the prim this script is in.
26 integer FADE_TARGETS = LINK_SET; // fade the entire object, all prims.
27 //integer FADE_TARGETS = 3; // fade just the second prim, not the root.
31 float global_direction = -1.0;
32 // tells us whether we are making the object more transparent
33 // (positive numbers) or less transparent (negative numbers).
36 // unix time of last mention of the opacity.
38 // displays the current opaqueness of the object.
41 float opacity = llGetAlpha(ALL_SIDES) / (float)llGetNumberOfSides() * 100.0;
42 string message = (string)((integer)opacity) + "% opacity";
43 llSetText(message, <.2, .8, .6>, 1.0);
44 // whisper the setting if we haven't in a bit.
45 if (llGetUnixTime() - last_update >= 2) {
46 llWhisper(0, message);
47 last_update = llGetUnixTime();
51 // get rid of the text label.
52 show_nothing() { llSetText("", <0.0, 0.0, 0.0>, 0.0); }
57 // huffware script: auto-retire, by fred huffhines, version 2.5.
58 // distributed under BSD-like license.
59 // !! keep in mind that this code must be *copied* into another
60 // !! script that you wish to add auto-retirement capability to.
61 // when a script has auto_retire in it, it can be dropped into an
62 // object and the most recent version of the script will destroy
63 // all older versions.
65 // the version numbers are embedded into the script names themselves.
66 // the notation for versions uses a letter 'v', followed by two numbers
67 // in the form "major.minor".
68 // major and minor versions are implicitly considered as a floating point
69 // number that increases with each newer version of the script. thus,
70 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
71 // and "hazmap v3.2" is a more recent version.
73 // example usage of the auto-retirement script:
76 // auto_retire(); // make sure newest addition is only version of script.
79 // this script is partly based on the self-upgrading scripts from markov brodsky
80 // and jippen faddoul.
83 string self = llGetScriptName(); // the name of this script.
84 list split = compute_basename_and_version(self);
85 if (llGetListLength(split) != 2) return; // nothing to do for this script.
86 string basename = llList2String(split, 0); // script name with no version attached.
87 string version_string = llList2String(split, 1); // the version found.
89 // find any scripts that match the basename. they are variants of this script.
90 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
91 //log_it("invpo=" + (string)posn);
92 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
93 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
94 // found a basic match at least.
95 list inv_split = compute_basename_and_version(curr_script);
96 if (llGetListLength(inv_split) == 2) {
97 // see if this script is more ancient.
98 string inv_version_string = llList2String(inv_split, 1); // the version found.
99 // must make sure that the retiring script is completely the identical basename;
100 // just matching in the front doesn't make it a relative.
101 if ( (llList2String(inv_split, 0) == basename)
102 && ((float)inv_version_string < (float)version_string) ) {
103 // remove script with same name from inventory that has inferior version.
104 llRemoveInventory(curr_script);
111 // separates the base script name and version number. used by auto_retire.
112 list compute_basename_and_version(string to_chop_up)
114 // minimum script name is 2 characters plus a version.
115 integer space_v_posn;
116 // find the last useful space and 'v' combo.
117 for (space_v_posn = llStringLength(to_chop_up) - 3;
118 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
120 // look for space and v but do nothing else.
121 //log_it("pos=" + (string)space_v_posn);
123 if (space_v_posn < 2) return []; // no space found.
124 //log_it("space v@" + (string)space_v_posn);
125 // now we zoom through the stuff after our beloved v character and find any evil
126 // space characters, which are most likely from SL having found a duplicate item
127 // name and not so helpfully renamed it for us.
129 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
130 //log_it("indy=" + (string)space_v_posn);
131 if (llGetSubString(to_chop_up, indy, indy) == " ") {
132 // found one; zap it. since we're going backwards we don't need to
133 // adjust the loop at all.
134 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
135 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
138 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
139 // ditch the space character for our numerical check.
140 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
141 // strip out a 'v' if there is one.
142 if (llGetSubString(chop_suffix, 0, 0) == "v")
143 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
144 // if valid floating point number and greater than zero, that works for our version.
145 string basename = to_chop_up; // script name with no version attached.
146 if ((float)chop_suffix > 0.0) {
147 // this is a big success right here.
148 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
149 return [ basename, chop_suffix ];
151 // seems like we found nothing useful.
159 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
160 on_rez(integer parm) { state rerun; }
162 state rerun { state_entry() { state default; } }
168 show_nothing(); // clean out any existing text.
169 last_update = llGetUnixTime();
172 touch_start(integer total_number) {
173 global_direction *= -1.0; // change the direction for next time.
175 if (global_direction > 0.0)
176 llSetLinkAlpha(FADE_TARGETS, highest_opacity, ALL_SIDES);
178 llSetLinkAlpha(FADE_TARGETS, lowest_opacity, ALL_SIDES);
180 // do the full fade routine. start the timer to change the
181 // opacity while the avatar keeps touching the object.
182 llSetTimerEvent(timer_interval);
186 touch_end(integer total_number) {
187 llSetTimerEvent(0); // stop the timer.
188 show_nothing(); // clear the text out.
192 float current = llGetAlpha(ALL_SIDES) / (float)llGetNumberOfSides()
193 + pace_increment * global_direction;
194 if (current > highest_opacity) { current = highest_opacity; }
195 if (current < lowest_opacity) { current = lowest_opacity; }
196 // change transparency on all links, including root prim.
197 llSetLinkAlpha(FADE_TARGETS, current, ALL_SIDES);