2 // huffware script: cowpole ignite, by fred huffhines
4 // a simple bridge to get the lamp lit. this script needs to be in the lamp post and not in the bulb.
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.
10 integer SECRET_LIGHT_BULB_ILLUMINATI_CODE = -14058;
11 // a semi-secret code that is used in a linked message when some other script
12 // wants the lamp to turn on or off.
15 // huffware script: auto-retire, by fred huffhines, version 2.5.
16 // distributed under BSD-like license.
17 // !! keep in mind that this code must be *copied* into another
18 // !! script that you wish to add auto-retirement capability to.
19 // when a script has auto_retire in it, it can be dropped into an
20 // object and the most recent version of the script will destroy
21 // all older versions.
23 // the version numbers are embedded into the script names themselves.
24 // the notation for versions uses a letter 'v', followed by two numbers
25 // in the form "major.minor".
26 // major and minor versions are implicitly considered as a floating point
27 // number that increases with each newer version of the script. thus,
28 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
29 // and "hazmap v3.2" is a more recent version.
31 // example usage of the auto-retirement script:
34 // auto_retire(); // make sure newest addition is only version of script.
37 // this script is partly based on the self-upgrading scripts from markov brodsky
38 // and jippen faddoul.
41 string self = llGetScriptName(); // the name of this script.
42 list split = compute_basename_and_version(self);
43 if (llGetListLength(split) != 2) return; // nothing to do for this script.
44 string basename = llList2String(split, 0); // script name with no version attached.
45 string version_string = llList2String(split, 1); // the version found.
47 // find any scripts that match the basename. they are variants of this script.
48 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
49 //log_it("invpo=" + (string)posn);
50 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
51 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
52 // found a basic match at least.
53 list inv_split = compute_basename_and_version(curr_script);
54 if (llGetListLength(inv_split) == 2) {
55 // see if this script is more ancient.
56 string inv_version_string = llList2String(inv_split, 1); // the version found.
57 // must make sure that the retiring script is completely the identical basename;
58 // just matching in the front doesn't make it a relative.
59 if ( (llList2String(inv_split, 0) == basename)
60 && ((float)inv_version_string < (float)version_string) ) {
61 // remove script with same name from inventory that has inferior version.
62 llRemoveInventory(curr_script);
69 // separates the base script name and version number. used by auto_retire.
70 list compute_basename_and_version(string to_chop_up)
72 // minimum script name is 2 characters plus a version.
74 // find the last useful space and 'v' combo.
75 for (space_v_posn = llStringLength(to_chop_up) - 3;
76 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
78 // look for space and v but do nothing else.
79 //log_it("pos=" + (string)space_v_posn);
81 if (space_v_posn < 2) return []; // no space found.
82 //log_it("space v@" + (string)space_v_posn);
83 // now we zoom through the stuff after our beloved v character and find any evil
84 // space characters, which are most likely from SL having found a duplicate item
85 // name and not so helpfully renamed it for us.
87 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
88 //log_it("indy=" + (string)space_v_posn);
89 if (llGetSubString(to_chop_up, indy, indy) == " ") {
90 // found one; zap it. since we're going backwards we don't need to
91 // adjust the loop at all.
92 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
93 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
96 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
97 // ditch the space character for our numerical check.
98 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
99 // strip out a 'v' if there is one.
100 if (llGetSubString(chop_suffix, 0, 0) == "v")
101 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
102 // if valid floating point number and greater than zero, that works for our version.
103 string basename = to_chop_up; // script name with no version attached.
104 if ((float)chop_suffix > 0.0) {
105 // this is a big success right here.
106 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
107 return [ basename, chop_suffix ];
109 // seems like we found nothing useful.
116 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
117 on_rez(integer parm) { state rerun; }
119 state rerun { state_entry() { state default; } }
123 state_entry() { auto_retire(); }
124 touch_start(integer total_number)
126 llMessageLinked(LINK_SET, SECRET_LIGHT_BULB_ILLUMINATI_CODE, "", "");