2 // huffware script: texture mover, by fred huffhines
4 // moves a texture across the object, either by smooth animation or brute force offsetting.
6 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
7 // do not use it in objects without fully realizing you are implicitly accepting that license.
12 integer USE_TEXTURE_ANIMATION = TRUE;
13 // by default, we use texture animation which is a lower-lag way to
14 // make the texture move. if this is false, then we use a timed update
15 // to move the texture instead.
16 // note: these modes are actually really different. the texture animation
17 // is included here because i wanted to smooth out some objects that used
20 // used in both types...
22 float TIMER_INTERVAL = 0.2; // how fast do we move texture?
24 // for timed movement...
26 vector OFFSET_MOVEMENT = ZERO_VECTOR; // no movement.
27 //vector OFFSET_MOVEMENT = <0.0, -0.02, 0.0>;
28 // how much to move the texture by in x,y,z directions.
30 //float OFFSET_ROTATION = 0.0; // in degrees.
31 float OFFSET_ROTATION = -1.0; // in degrees.
33 // for texture animations...
35 float MOVER_TIMER_DIVISOR = 30.0;
36 // makes the movement comparable to timed method.
38 float ROTATER_TIMER_DIVISOR = 7.0;
39 // makes the rotation comparable to timed method.
41 // iterative movement of texture.
42 move_texture(vector offset)
44 vector current = llGetTextureOffset(ALL_SIDES);
46 if (current.x > 1.0) current.x = -1.0;
47 if (current.x < -1.0) current.x = 1.0;
48 if (current.y > 1.0) current.y = -1.0;
49 if (current.y < -1.0) current.y = 1.0;
50 llOffsetTexture(current.x, current.y, ALL_SIDES);
53 // iterative rotation of texture. "spin" is measured in degrees.
54 spin_texture(float spin)
56 float rot = llGetTextureRot(ALL_SIDES); // get our current state.
57 rot += spin * DEG_TO_RAD; // add some rotation.
58 llRotateTexture(rot, ALL_SIDES); //rotate the object
61 initialize_texture_mover()
63 if (!USE_TEXTURE_ANIMATION) {
64 // we're stuck with the timed update style for movement.
65 llSetTimerEvent(TIMER_INTERVAL);
66 // turn off previous animation.
67 llSetTextureAnim(0, ALL_SIDES, 0, 0, 0, 0, 0);
69 // we can just set the texture movement here and be done with it.
72 llSetTimerEvent(0); // we don't use a timer.
74 //hmmm: how do we combine rotation and offsets? currently mutually exclusive.
76 if (OFFSET_MOVEMENT != ZERO_VECTOR) {
77 float timer_interval = TIMER_INTERVAL / MOVER_TIMER_DIVISOR;
78 log_it("getting x_frames=" + (string)x_frames
79 + " y_frames=" + (string)y_frames
80 + " timer_intvl=" + (string)timer_interval);
82 llSetTextureAnim(ANIM_ON | LOOP | SMOOTH, ALL_SIDES,
84 0, 100, timer_interval);
85 } else if (OFFSET_ROTATION != 0.0) {
86 float timer_interval = TIMER_INTERVAL / ROTATER_TIMER_DIVISOR;
87 // we're actually not using the rotation at all here, except for
88 // the sign. that seems pretty busted.
89 if (OFFSET_ROTATION < 0) timer_interval *= -1.0;
90 llSetTextureAnim(ANIM_ON | LOOP | SMOOTH | ROTATE, ALL_SIDES,
92 0, TWO_PI, timer_interval);
100 integer debug_num = 0;
102 // a debugging output method. can be disabled entirely in one place.
103 log_it(string to_say)
106 // tell this to the owner.
107 llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
108 // say this on an unusual channel for chat if it's not intended for general public.
109 // llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
110 // say this on open chat that anyone can hear. we take off the bling for this one.
117 // huffware script: auto-retire, by fred huffhines, version 2.5.
118 // distributed under BSD-like license.
119 // !! keep in mind that this code must be *copied* into another
120 // !! script that you wish to add auto-retirement capability to.
121 // when a script has auto_retire in it, it can be dropped into an
122 // object and the most recent version of the script will destroy
123 // all older versions.
125 // the version numbers are embedded into the script names themselves.
126 // the notation for versions uses a letter 'v', followed by two numbers
127 // in the form "major.minor".
128 // major and minor versions are implicitly considered as a floating point
129 // number that increases with each newer version of the script. thus,
130 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
131 // and "hazmap v3.2" is a more recent version.
133 // example usage of the auto-retirement script:
136 // auto_retire(); // make sure newest addition is only version of script.
139 // this script is partly based on the self-upgrading scripts from markov brodsky
140 // and jippen faddoul.
143 string self = llGetScriptName(); // the name of this script.
144 list split = compute_basename_and_version(self);
145 if (llGetListLength(split) != 2) return; // nothing to do for this script.
146 string basename = llList2String(split, 0); // script name with no version attached.
147 string version_string = llList2String(split, 1); // the version found.
149 // find any scripts that match the basename. they are variants of this script.
150 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
151 //log_it("invpo=" + (string)posn);
152 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
153 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
154 // found a basic match at least.
155 list inv_split = compute_basename_and_version(curr_script);
156 if (llGetListLength(inv_split) == 2) {
157 // see if this script is more ancient.
158 string inv_version_string = llList2String(inv_split, 1); // the version found.
159 // must make sure that the retiring script is completely the identical basename;
160 // just matching in the front doesn't make it a relative.
161 if ( (llList2String(inv_split, 0) == basename)
162 && ((float)inv_version_string < (float)version_string) ) {
163 // remove script with same name from inventory that has inferior version.
164 llRemoveInventory(curr_script);
171 // separates the base script name and version number. used by auto_retire.
172 list compute_basename_and_version(string to_chop_up)
174 // minimum script name is 2 characters plus a version.
175 integer space_v_posn;
176 // find the last useful space and 'v' combo.
177 for (space_v_posn = llStringLength(to_chop_up) - 3;
178 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
180 // look for space and v but do nothing else.
181 //log_it("pos=" + (string)space_v_posn);
183 if (space_v_posn < 2) return []; // no space found.
184 //log_it("space v@" + (string)space_v_posn);
185 // now we zoom through the stuff after our beloved v character and find any evil
186 // space characters, which are most likely from SL having found a duplicate item
187 // name and not so helpfully renamed it for us.
189 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
190 //log_it("indy=" + (string)space_v_posn);
191 if (llGetSubString(to_chop_up, indy, indy) == " ") {
192 // found one; zap it. since we're going backwards we don't need to
193 // adjust the loop at all.
194 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
195 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
198 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
199 // ditch the space character for our numerical check.
200 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
201 // strip out a 'v' if there is one.
202 if (llGetSubString(chop_suffix, 0, 0) == "v")
203 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
204 // if valid floating point number and greater than zero, that works for our version.
205 string basename = to_chop_up; // script name with no version attached.
206 if ((float)chop_suffix > 0.0) {
207 // this is a big success right here.
208 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
209 return [ basename, chop_suffix ];
211 // seems like we found nothing useful.
218 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
219 on_rez(integer parm) { state rerun; }
221 state rerun { state_entry() { state default; } }
227 initialize_texture_mover();
231 // the timed approach is the only one so far that allows both a
232 // movement of the texture and a rotation.
233 if (OFFSET_MOVEMENT != ZERO_VECTOR) move_texture(OFFSET_MOVEMENT);
234 if (OFFSET_ROTATION != 0.0) spin_texture(OFFSET_ROTATION);