normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / invisiprim_v0.8.txt
1 
2 // huffware script: invisiprim, by fred huffhines.
3 //
4 // a click on and off invisibility script.
5 //
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.
8 //
9
10 //////////////
11 // huffware script: auto-retire, by fred huffhines, version 2.5.
12 // distributed under BSD-like license.
13 //   !!  keep in mind that this code must be *copied* into another
14 //   !!  script that you wish to add auto-retirement capability to.
15 // when a script has auto_retire in it, it can be dropped into an
16 // object and the most recent version of the script will destroy
17 // all older versions.
18 //
19 // the version numbers are embedded into the script names themselves.
20 // the notation for versions uses a letter 'v', followed by two numbers
21 // in the form "major.minor".
22 // major and minor versions are implicitly considered as a floating point
23 // number that increases with each newer version of the script.  thus,
24 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
25 // and "hazmap v3.2" is a more recent version.
26 //
27 // example usage of the auto-retirement script:
28 //     default {
29 //         state_entry() {
30 //            auto_retire();  // make sure newest addition is only version of script.
31 //        }
32 //     }
33 // this script is partly based on the self-upgrading scripts from markov brodsky
34 // and jippen faddoul.
35 //////////////
36 auto_retire() {
37     string self = llGetScriptName();  // the name of this script.
38     list split = compute_basename_and_version(self);
39     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
40     string basename = llList2String(split, 0);  // script name with no version attached.
41     string version_string = llList2String(split, 1);  // the version found.
42     integer posn;
43     // find any scripts that match the basename.  they are variants of this script.
44     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
45 //log_it("invpo=" + (string)posn);
46         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
47         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
48             // found a basic match at least.
49             list inv_split = compute_basename_and_version(curr_script);
50             if (llGetListLength(inv_split) == 2) {
51                 // see if this script is more ancient.
52                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
53                 // must make sure that the retiring script is completely the identical basename;
54                 // just matching in the front doesn't make it a relative.
55                 if ( (llList2String(inv_split, 0) == basename)
56                     && ((float)inv_version_string < (float)version_string) ) {
57                     // remove script with same name from inventory that has inferior version.
58                     llRemoveInventory(curr_script);
59                 }
60             }
61         }
62     }
63 }
64 //
65 // separates the base script name and version number.  used by auto_retire.
66 list compute_basename_and_version(string to_chop_up)
67 {
68     // minimum script name is 2 characters plus a version.
69     integer space_v_posn;
70     // find the last useful space and 'v' combo.
71     for (space_v_posn = llStringLength(to_chop_up) - 3;
72         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
73         space_v_posn--) {
74         // look for space and v but do nothing else.
75 //log_it("pos=" + (string)space_v_posn);
76     }
77     if (space_v_posn < 2) return [];  // no space found.
78 //log_it("space v@" + (string)space_v_posn);
79     // now we zoom through the stuff after our beloved v character and find any evil
80     // space characters, which are most likely from SL having found a duplicate item
81     // name and not so helpfully renamed it for us.
82     integer indy;
83     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
84 //log_it("indy=" + (string)space_v_posn);
85         if (llGetSubString(to_chop_up, indy, indy) == " ") {
86             // found one; zap it.  since we're going backwards we don't need to
87             // adjust the loop at all.
88             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
89 //log_it("saw case of previously redundant item, aieee.  flattened: " + to_chop_up);
90         }
91     }
92     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
93     // ditch the space character for our numerical check.
94     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
95     // strip out a 'v' if there is one.
96     if (llGetSubString(chop_suffix, 0, 0) == "v")
97         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
98     // if valid floating point number and greater than zero, that works for our version.
99     string basename = to_chop_up;  // script name with no version attached.
100     if ((float)chop_suffix > 0.0) {
101         // this is a big success right here.
102         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
103         return [ basename, chop_suffix ];
104     }
105     // seems like we found nothing useful.
106     return [];
107 }
108 //
109 //////////////
110
111 default
112 {
113     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
114     on_rez(integer parm) { state rerun; }
115 }
116 state rerun { state_entry() { state default; } }
117
118 state real_default
119 {
120     state_entry() {
121         auto_retire();
122         llSetTexture("e97cf410-8e61-7005-ec06-629eba4cd1fb", ALL_SIDES);
123             // This is one of the invisiprim textures.
124         llSetAlpha(1.0, ALL_SIDES);
125     }
126     touch(integer num) {
127         if (llDetectedKey(0) == llGetOwner()) {
128             // When touched, it will go back to a non-invisiprim.
129             state blank;
130         }
131     }
132 }
133
134 state blank
135 {
136     state_entry() {
137         llSetTexture("4c1ce202-4196-f1c1-0409-367b3a71543e", ALL_SIDES);
138             // This is the 'Blank' texture
139         llSetAlpha(1.0, ALL_SIDES);
140     }
141     touch(integer num) {
142         if (llDetectedKey(0) == llGetOwner()) {
143             // When touched, it will go back to an invisiprim.
144             state default;
145         }
146     }
147     on_rez(integer parm) { llResetScript(); }
148 }
149
150 // attributions:
151 //   invisiprim original version created by Opus Beck 9 aug 2007