2 // huffware script: box mover, by fred huffhines.
4 // a really simple script to make a box jump out of one's way.
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.
11 //hmmm: fix this to use a notecard for dimensions and members.
14 // modifiable constants.
16 vector jump_offset = <4.0, -3.0, 0.0>; // how far to jump away from the starting place.
18 list allowed_avatars = [ "fred huffhines", "Chronical Koolhoven", "Mojopickle Haystack",
19 "Zeno Olifone", "After9 NightFire", "Wam7c Macchi" ];
23 vector home; // where do we live normally?
25 // makes our list of allowed keys into uniform lower case.
30 for (i = 0; i < llGetListLength(allowed_avatars); i++) {
31 string curr = llList2String(allowed_avatars, i);
32 curr = llToLower(curr);
35 allowed_avatars = fixed_list;
36 //llOwnerSay("got a new list of: " + (string)allowed_avatars);
40 // huffware script: auto-retire, by fred huffhines, version 2.5.
41 // distributed under BSD-like license.
42 // !! keep in mind that this code must be *copied* into another
43 // !! script that you wish to add auto-retirement capability to.
44 // when a script has auto_retire in it, it can be dropped into an
45 // object and the most recent version of the script will destroy
46 // all older versions.
48 // the version numbers are embedded into the script names themselves.
49 // the notation for versions uses a letter 'v', followed by two numbers
50 // in the form "major.minor".
51 // major and minor versions are implicitly considered as a floating point
52 // number that increases with each newer version of the script. thus,
53 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
54 // and "hazmap v3.2" is a more recent version.
56 // example usage of the auto-retirement script:
59 // auto_retire(); // make sure newest addition is only version of script.
62 // this script is partly based on the self-upgrading scripts from markov brodsky
63 // and jippen faddoul.
66 string self = llGetScriptName(); // the name of this script.
67 list split = compute_basename_and_version(self);
68 if (llGetListLength(split) != 2) return; // nothing to do for this script.
69 string basename = llList2String(split, 0); // script name with no version attached.
70 string version_string = llList2String(split, 1); // the version found.
72 // find any scripts that match the basename. they are variants of this script.
73 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
74 //log_it("invpo=" + (string)posn);
75 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
76 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
77 // found a basic match at least.
78 list inv_split = compute_basename_and_version(curr_script);
79 if (llGetListLength(inv_split) == 2) {
80 // see if this script is more ancient.
81 string inv_version_string = llList2String(inv_split, 1); // the version found.
82 // must make sure that the retiring script is completely the identical basename;
83 // just matching in the front doesn't make it a relative.
84 if ( (llList2String(inv_split, 0) == basename)
85 && ((float)inv_version_string < (float)version_string) ) {
86 // remove script with same name from inventory that has inferior version.
87 llRemoveInventory(curr_script);
94 // separates the base script name and version number. used by auto_retire.
95 list compute_basename_and_version(string to_chop_up)
97 // minimum script name is 2 characters plus a version.
99 // find the last useful space and 'v' combo.
100 for (space_v_posn = llStringLength(to_chop_up) - 3;
101 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
103 // look for space and v but do nothing else.
104 //log_it("pos=" + (string)space_v_posn);
106 if (space_v_posn < 2) return []; // no space found.
107 //log_it("space v@" + (string)space_v_posn);
108 // now we zoom through the stuff after our beloved v character and find any evil
109 // space characters, which are most likely from SL having found a duplicate item
110 // name and not so helpfully renamed it for us.
112 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
113 //log_it("indy=" + (string)space_v_posn);
114 if (llGetSubString(to_chop_up, indy, indy) == " ") {
115 // found one; zap it. since we're going backwards we don't need to
116 // adjust the loop at all.
117 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
118 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
121 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
122 // ditch the space character for our numerical check.
123 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
124 // strip out a 'v' if there is one.
125 if (llGetSubString(chop_suffix, 0, 0) == "v")
126 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
127 // if valid floating point number and greater than zero, that works for our version.
128 string basename = to_chop_up; // script name with no version attached.
129 if ((float)chop_suffix > 0.0) {
130 // this is a big success right here.
131 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
132 return [ basename, chop_suffix ];
134 // seems like we found nothing useful.
142 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
143 on_rez(integer parm) { state rerun; }
145 state rerun { state_entry() { state default; } }
150 auto_retire(); // make sure newest addition is only version of script.
151 fix_list_items(); // make sure entries are lower case.
155 touch_start(integer total_number) {
156 llOwnerSay("touched by " + llDetectedName(0));
157 // if we're not the owner, then we've got a few extra requirements before
158 // we do anything at all.
159 if (llDetectedKey(0) != llGetOwner()) {
160 list lowname = [ llToLower(llDetectedName(0)) ];
161 if (llListFindList(allowed_avatars, lowname) < 0) {
162 // this guy is not in our access list.
163 llOwnerSay("denying " + llDetectedName(0) + " because not in list and not owner.");
167 float max_drift = 0.01;
168 // are we considered close enough to home? not if farther than this amount.
169 vector diff = llGetPos() - home;
170 if (diff.x < 0.0) diff = <diff.x * -1.0, diff.y, diff.z>;
171 if (diff.y < 0.0) diff = <diff.x, diff.y * -1.0, diff.z>;
172 if (diff.z < 0.0) diff = <diff.x, diff.y, diff.z * -1.0>;
173 // this all is not really a vector difference, but more a check on each component.
174 if ( (diff.x > max_drift) || (diff.y > max_drift) || (diff.z > max_drift) ) {
175 // we're far away from home, so let's jump back there.
178 // we are at home, so we're jumping away.
179 llSetPos(home - jump_offset);
180 llSetTimerEvent(14.0); // reset the position in a few secs.
185 llSetTimerEvent(0.0); // reset timer.