2 // huffware script: rotanium rotato, by fred huffhines.
4 // causes the object to rotate according to the parameters set below.
5 // this can use herky-jerky timed rotation with llSetRot or it can use
6 // smooth rotation with llTargetOmega.
8 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
9 // do not use it in objects without fully realizing you are implicitly accepting that license.
12 integer RANDOMIZE_ROTATION = TRUE;
14 integer SMOOTH_ROTATION = TRUE;
15 // if this is true, then the object will rotate smoothly rather than
16 // being rotated by the timer.
18 float SMOOTH_TIMER_FREQUENCY = 14.0;
19 // the smooth rotater doesn't need to hit the timer all that often.
21 float SMOOTH_CHANCE_FOR_ADJUSTING = 0.8;
22 // we won't always change the smooth rotation, even though our timer
25 float SMOOTH_ROTATION_GAIN_MAX = 0.0490873852122;
26 // the gain is how fast we will rotate in radians per second.
27 // PI / 2 is about 90 degrees per second, which seems way too fast.
28 // 0.196349540849 is about PI / 16, 0.0981747704244 is about PI / 32,
29 // and 0.0490873852122 is about PI / 64.
31 float JERKY_TIMER_FREQUENCY = 0.50;
32 // this is the fastest that llSetRot rotation can happen anyhow,
33 // so we fire the timer at this rate.
35 float JERKY_CHANCE_FOR_ADJUSTING = 0.1;
36 // this is the probability of changing the current direction.
38 vector current_add_in = <0.0, 0.0, 0.4>;
39 // randomly assigned to if RANDOMIZE_ROTATION is true.
41 float current_gain = -0.05;
42 // speed of smooth rotation; will randomly change if RANDOMIZE_ROTATION is true.
44 float MIN_ADDITION = 0.01;
45 // smallest amount of change we will ever have.
46 float MAX_ADDITION = 7.0;
47 // largest amount of change we will ever have.
49 // sets the gain and add in to random choices.
52 current_gain = randomize_within_range(0.001, SMOOTH_ROTATION_GAIN_MAX, TRUE);
53 current_add_in = random_vector(MIN_ADDITION, MAX_ADDITION, TRUE);
56 // performs the timed rotation that has been configured for us.
59 if (SMOOTH_ROTATION) {
60 // our slack timer went off, so randomize the rotation if requested.
61 if (RANDOMIZE_ROTATION && (llFrand(1.0) >= SMOOTH_CHANCE_FOR_ADJUSTING) )
63 // make sure we are using the rotational values we were asked to.
64 llTargetOmega(current_add_in, current_gain, 1.0);
66 // herky jerky rotation.
68 //hmmm: seeing that GetRot or GetLocalRot might be useful at different times.
69 rotation curr_rot = llGetLocalRot(); // get our current state.
70 vector euler_curr = llRot2Euler(curr_rot); // turn into euler coords.
71 euler_curr *= RAD_TO_DEG; // convert to degrees.
72 vector new_rot = euler_curr + current_add_in; // add our adjustment in.
73 new_rot *= DEG_TO_RAD; // convert to radians.
74 rotation quat = llEuler2Rot(new_rot); // convert to quaternion
75 llSetLocalRot(quat); // rotate the object
76 //will the local work for a single prim?
77 //in the current case, we do want just the local rot to change.
79 // change the rotation add-in if the mood strikes us.
80 float starter = 0.420; // where we start looking for change.
81 float change_cap = starter + JERKY_CHANCE_FOR_ADJUSTING;
82 float randomness = llFrand(1.000);
83 if ( (randomness <= change_cap) && (randomness >= starter) ) {
84 // time for a change in the rotation.
85 if (RANDOMIZE_ROTATION)
92 // start of hufflets...
95 // huffware script: auto-retire, by fred huffhines, version 2.5.
96 // distributed under BSD-like license.
97 // !! keep in mind that this code must be *copied* into another
98 // !! script that you wish to add auto-retirement capability to.
99 // when a script has auto_retire in it, it can be dropped into an
100 // object and the most recent version of the script will destroy
101 // all older versions.
103 // the version numbers are embedded into the script names themselves.
104 // the notation for versions uses a letter 'v', followed by two numbers
105 // in the form "major.minor".
106 // major and minor versions are implicitly considered as a floating point
107 // number that increases with each newer version of the script. thus,
108 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
109 // and "hazmap v3.2" is a more recent version.
111 // example usage of the auto-retirement script:
114 // auto_retire(); // make sure newest addition is only version of script.
117 // this script is partly based on the self-upgrading scripts from markov brodsky
118 // and jippen faddoul.
121 string self = llGetScriptName(); // the name of this script.
122 list split = compute_basename_and_version(self);
123 if (llGetListLength(split) != 2) return; // nothing to do for this script.
124 string basename = llList2String(split, 0); // script name with no version attached.
125 string version_string = llList2String(split, 1); // the version found.
127 // find any scripts that match the basename. they are variants of this script.
128 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
129 //log_it("invpo=" + (string)posn);
130 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
131 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
132 // found a basic match at least.
133 list inv_split = compute_basename_and_version(curr_script);
134 if (llGetListLength(inv_split) == 2) {
135 // see if this script is more ancient.
136 string inv_version_string = llList2String(inv_split, 1); // the version found.
137 // must make sure that the retiring script is completely the identical basename;
138 // just matching in the front doesn't make it a relative.
139 if ( (llList2String(inv_split, 0) == basename)
140 && ((float)inv_version_string < (float)version_string) ) {
141 // remove script with same name from inventory that has inferior version.
142 llRemoveInventory(curr_script);
149 // separates the base script name and version number. used by auto_retire.
150 list compute_basename_and_version(string to_chop_up)
152 // minimum script name is 2 characters plus a version.
153 integer space_v_posn;
154 // find the last useful space and 'v' combo.
155 for (space_v_posn = llStringLength(to_chop_up) - 3;
156 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
158 // look for space and v but do nothing else.
159 //log_it("pos=" + (string)space_v_posn);
161 if (space_v_posn < 2) return []; // no space found.
162 //log_it("space v@" + (string)space_v_posn);
163 // now we zoom through the stuff after our beloved v character and find any evil
164 // space characters, which are most likely from SL having found a duplicate item
165 // name and not so helpfully renamed it for us.
167 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
168 //log_it("indy=" + (string)space_v_posn);
169 if (llGetSubString(to_chop_up, indy, indy) == " ") {
170 // found one; zap it. since we're going backwards we don't need to
171 // adjust the loop at all.
172 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
173 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
176 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
177 // ditch the space character for our numerical check.
178 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
179 // strip out a 'v' if there is one.
180 if (llGetSubString(chop_suffix, 0, 0) == "v")
181 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
182 // if valid floating point number and greater than zero, that works for our version.
183 string basename = to_chop_up; // script name with no version attached.
184 if ((float)chop_suffix > 0.0) {
185 // this is a big success right here.
186 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
187 return [ basename, chop_suffix ];
189 // seems like we found nothing useful.
195 // returns a number at most "maximum" and at least "minimum".
196 // if "allow_negative" is TRUE, then the return may be positive or negative.
197 float randomize_within_range(float minimum, float maximum, integer allow_negative)
199 if (minimum > maximum) {
200 // flip the two if they are reversed.
201 float temp = minimum; minimum = maximum; maximum = temp;
203 float to_return = minimum + llFrand(maximum - minimum);
204 if (allow_negative) {
205 if (llFrand(1.0) < 0.5) to_return *= -1.0;
210 // returns a random vector where x,y,z will be between "minimums" and "maximums"
211 // x,y,z components. if "allow_negative" is true, then any component will
212 // randomly be negative or positive.
213 vector random_bound_vector(vector minimums, vector maximums, integer allow_negative)
215 return <randomize_within_range(minimums.x, maximums.x, allow_negative),
216 randomize_within_range(minimums.y, maximums.y, allow_negative),
217 randomize_within_range(minimums.z, maximums.z, allow_negative)>;
220 // returns a vector whose components are between minimum and maximum.
221 // if allow_negative is true, then they can be either positive or negative.
222 vector random_vector(float minimum, float maximum, integer allow_negative)
224 return random_bound_vector(<minimum, minimum, minimum>,
225 <maximum, maximum, maximum>, allow_negative);
233 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
234 on_rez(integer parm) { state rerun; }
236 state rerun { state_entry() { state default; } }
243 // if needed, we will set our initial random rotation.
244 if (RANDOMIZE_ROTATION) randomize_values();
245 // do a first rotate, so we move right at startup. otherwise we won't move
246 // until after our first timer hits.
247 rotate_as_requested();
248 // now set the timer for our mode.
249 if (SMOOTH_ROTATION) {
250 llSetTimerEvent(SMOOTH_TIMER_FREQUENCY);
252 llSetTimerEvent(JERKY_TIMER_FREQUENCY);
256 timer() { rotate_as_requested(); }