2 // huffware script: jump good, by fred huffhines
3 // "jump good" is an homage to samurai jack.
5 // if you wear an object containing this script (and using the
6 // jump_good_jump_strength() value), then this script will make
7 // your jumps much higher than normal. other values for the
8 // jump strength will vary the force on you accordingly.
10 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
11 // do not use it in objects without fully realizing you are implicitly accepting that license.
16 // this section provides some example forces one might want to exert.
17 // all floating point numbers below are measured in meters per second squared,
18 // which is a measurement of acceleration.
20 float EARTH_ACCELERATION = 9.80665;
21 // the acceleration due to gravity on earth.
23 float JUPITER_ACCELERATION = 25.93;
24 // the acceleration on jupiter due to gravity.
26 float earth_jump_strength() { return EARTH_ACCELERATION - EARTH_ACCELERATION; }
27 // normal gravity for the earth; no additional force added.
29 float jupiter_jump_strength()
30 { return EARTH_ACCELERATION - (JUPITER_ACCELERATION - EARTH_ACCELERATION); }
31 // this is what the jump force should be when approximating jupiter's gravity.
33 float jump_good_jump_strength() { return 8.4; }
34 // samurai jack was probably able to jump this high after the tree dwellers
35 // taught him how to jump good.
37 integer DEBUGGING = FALSE;
38 // if this is true, then extra noise is made about state transitions.
40 float TIMER_PERIOD = 4.0;
41 // how frequently to check our state.
45 // this is the most important jump strength, since it's the one we'll use...
47 float jump_strength() { return jump_good_jump_strength(); }
48 // the amount of force that you're "thrown" upwards with. this is
49 // relative to your mass. the force of gravity pulls on objects with
50 // a force of 9.80665, so if the jump strength exceeds that, the object
51 // will never return to earth.
55 // global variables...
57 key attached_key; // key of the avatar wearing the object, if any avatar is.
59 integer _last_seen_flying; // tracks the attached avatar's flight state.
61 integer enabled; // records device's state; if false, then it's off.
65 // makes the force appropriate to the mass of the overall object.
66 use_configured_force()
68 float mass = llGetMass();
69 //log_it("mass is " + (string)mass);
70 if (mass == 0.0) mass = 20000;
71 // fake there being a good mass.
72 vector force = <0,0, mass * jump_strength()>;
73 //log_it("using force of " + (string)force + ".");
74 llSetForce(force, FALSE);
77 // resets force to zero to have normal gravity return.
79 //log_it("using zero force.");
81 llSetForce(<0,0,0>, FALSE); }
83 // changes the objects current velocity to match "new_velocity".
84 // if the "local_axis" is true, then it applies the velocity to the
85 // object's own axis. if false, then it uses the global axis of
87 set_velocity(vector new_velocity, integer local_axis)
89 vector current_velocity = llGetVel();
92 rotation rot = llGetRot();
93 current_velocity /= rot; // undo the rotation.
96 new_velocity -= current_velocity;
97 new_velocity *= llGetMass();
99 llApplyImpulse(new_velocity, local_axis);
102 // picks the right amount of force based on whether the object is
103 // attached to an avatar and whether the avatar is flying.
104 set_force_appropriately()
106 if (attached_key != NULL_KEY) {
107 // make sure we're not flying now; jump force would be redundant.
108 if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING) {
109 if (!_last_seen_flying) {
110 //log_it("avatar wasn't flying, is now. setting zero force.");
113 _last_seen_flying = TRUE;
115 //if (_last_seen_flying) {
116 //log_it("avatar was just flying, but is not now. setting configured force.");
118 // we're not flying so keep our force set.
119 _last_seen_flying = FALSE;
120 use_configured_force();
124 // there's no one attached, so just follow our plan with the force.
125 use_configured_force();
132 _last_seen_flying = FALSE;
133 attached_key = NULL_KEY;
134 llSetTimerEvent(TIMER_PERIOD); // check avatar's state periodically.
135 if (llGetAttached() != 0) {
136 // there's an avatar attached right now! get the stats right.
137 attached_key = llGetOwner();
138 if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING) _last_seen_flying = TRUE;
139 else _last_seen_flying = FALSE;
141 set_force_appropriately();
145 // huffware script: auto-retire, by fred huffhines, version 2.5.
146 // distributed under BSD-like license.
147 // !! keep in mind that this code must be *copied* into another
148 // !! script that you wish to add auto-retirement capability to.
149 // when a script has auto_retire in it, it can be dropped into an
150 // object and the most recent version of the script will destroy
151 // all older versions.
153 // the version numbers are embedded into the script names themselves.
154 // the notation for versions uses a letter 'v', followed by two numbers
155 // in the form "major.minor".
156 // major and minor versions are implicitly considered as a floating point
157 // number that increases with each newer version of the script. thus,
158 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
159 // and "hazmap v3.2" is a more recent version.
161 // example usage of the auto-retirement script:
164 // auto_retire(); // make sure newest addition is only version of script.
167 // this script is partly based on the self-upgrading scripts from markov brodsky
168 // and jippen faddoul.
171 string self = llGetScriptName(); // the name of this script.
172 list split = compute_basename_and_version(self);
173 if (llGetListLength(split) != 2) return; // nothing to do for this script.
174 string basename = llList2String(split, 0); // script name with no version attached.
175 string version_string = llList2String(split, 1); // the version found.
177 // find any scripts that match the basename. they are variants of this script.
178 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
179 //log_it("invpo=" + (string)posn);
180 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
181 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
182 // found a basic match at least.
183 list inv_split = compute_basename_and_version(curr_script);
184 if (llGetListLength(inv_split) == 2) {
185 // see if this script is more ancient.
186 string inv_version_string = llList2String(inv_split, 1); // the version found.
187 // must make sure that the retiring script is completely the identical basename;
188 // just matching in the front doesn't make it a relative.
189 if ( (llList2String(inv_split, 0) == basename)
190 && ((float)inv_version_string < (float)version_string) ) {
191 // remove script with same name from inventory that has inferior version.
192 llRemoveInventory(curr_script);
199 // separates the base script name and version number. used by auto_retire.
200 list compute_basename_and_version(string to_chop_up)
202 // minimum script name is 2 characters plus a version.
203 integer space_v_posn;
204 // find the last useful space and 'v' combo.
205 for (space_v_posn = llStringLength(to_chop_up) - 3;
206 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
208 // look for space and v but do nothing else.
209 //log_it("pos=" + (string)space_v_posn);
211 if (space_v_posn < 2) return []; // no space found.
212 //log_it("space v@" + (string)space_v_posn);
213 // now we zoom through the stuff after our beloved v character and find any evil
214 // space characters, which are most likely from SL having found a duplicate item
215 // name and not so helpfully renamed it for us.
217 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
218 //log_it("indy=" + (string)space_v_posn);
219 if (llGetSubString(to_chop_up, indy, indy) == " ") {
220 // found one; zap it. since we're going backwards we don't need to
221 // adjust the loop at all.
222 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
223 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
226 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
227 // ditch the space character for our numerical check.
228 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
229 // strip out a 'v' if there is one.
230 if (llGetSubString(chop_suffix, 0, 0) == "v")
231 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
232 // if valid floating point number and greater than zero, that works for our version.
233 string basename = to_chop_up; // script name with no version attached.
234 if ((float)chop_suffix > 0.0) {
235 // this is a big success right here.
236 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
237 return [ basename, chop_suffix ];
239 // seems like we found nothing useful.
249 integer debug_num = 0;
251 // a debugging output method. can be disabled entirely in one place.
252 log_it(string to_say)
255 // tell this to the owner.
257 if (DEBUGGING) addition = llGetScriptName() + "[" + (string)debug_num + "] ";
258 llOwnerSay(addition + to_say);
259 // say this on an unusual channel for chat if it's not intended for general public.
260 // llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
261 // say this on open chat that anyone can hear. we take off the bling for this one.
269 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
270 on_rez(integer parm) { state rerun; }
272 state rerun { state_entry() { state default; } }
278 //log_it("state_entry");
283 // we can't do anything without physics enabled.
284 if (!llGetStatus(STATUS_PHYSICS))
285 llSetStatus(STATUS_PHYSICS, TRUE);
286 if (!llGetStatus(STATUS_PHANTOM))
287 llSetStatus(STATUS_PHANTOM, FALSE);
288 if (enabled) set_force_appropriately();
289 else use_zero_force();
294 //log_it("into attach, key=" + (string)avatar);
298 on_rez(integer parm) {
303 touch_start(integer count) {
304 if (llDetectedKey(0) != llGetOwner()) return; // not listening to that guy.
305 if (llGetAttached() == 0) return; // cannot change state if not attached.
306 // flip the current state, since they clicked.
308 log_it("disabled gravity control.");
312 log_it("enabled gravity control.");
314 use_configured_force();