2 // huffware script: phantomizer, by fred huffhines
4 // turns the object that contains this into a phantom on the schedule specified below.
5 // note that this should not be done to physical objects or they will sink into whatever
6 // they were sitting on.
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.
14 float SECONDS_per_minute = 60.0;
18 integer solid; // a boolean that represents our current solidity (TRUE=solid).
20 // constant-ish functions.
22 float solid_duration() // how long to be solid, in seconds.
23 { return 4.20 * SECONDS_per_minute; }
24 float phantom_duration() // how long to be ghosty, in seconds.
28 // huffware script: auto-retire, by fred huffhines, version 2.5.
29 // distributed under BSD-like license.
30 // !! keep in mind that this code must be *copied* into another
31 // !! script that you wish to add auto-retirement capability to.
32 // when a script has auto_retire in it, it can be dropped into an
33 // object and the most recent version of the script will destroy
34 // all older versions.
36 // the version numbers are embedded into the script names themselves.
37 // the notation for versions uses a letter 'v', followed by two numbers
38 // in the form "major.minor".
39 // major and minor versions are implicitly considered as a floating point
40 // number that increases with each newer version of the script. thus,
41 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
42 // and "hazmap v3.2" is a more recent version.
44 // example usage of the auto-retirement script:
47 // auto_retire(); // make sure newest addition is only version of script.
50 // this script is partly based on the self-upgrading scripts from markov brodsky
51 // and jippen faddoul.
54 string self = llGetScriptName(); // the name of this script.
55 list split = compute_basename_and_version(self);
56 if (llGetListLength(split) != 2) return; // nothing to do for this script.
57 string basename = llList2String(split, 0); // script name with no version attached.
58 string version_string = llList2String(split, 1); // the version found.
60 // find any scripts that match the basename. they are variants of this script.
61 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
62 //log_it("invpo=" + (string)posn);
63 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
64 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
65 // found a basic match at least.
66 list inv_split = compute_basename_and_version(curr_script);
67 if (llGetListLength(inv_split) == 2) {
68 // see if this script is more ancient.
69 string inv_version_string = llList2String(inv_split, 1); // the version found.
70 // must make sure that the retiring script is completely the identical basename;
71 // just matching in the front doesn't make it a relative.
72 if ( (llList2String(inv_split, 0) == basename)
73 && ((float)inv_version_string < (float)version_string) ) {
74 // remove script with same name from inventory that has inferior version.
75 llRemoveInventory(curr_script);
82 // separates the base script name and version number. used by auto_retire.
83 list compute_basename_and_version(string to_chop_up)
85 // minimum script name is 2 characters plus a version.
87 // find the last useful space and 'v' combo.
88 for (space_v_posn = llStringLength(to_chop_up) - 3;
89 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
91 // look for space and v but do nothing else.
92 //log_it("pos=" + (string)space_v_posn);
94 if (space_v_posn < 2) return []; // no space found.
95 //log_it("space v@" + (string)space_v_posn);
96 // now we zoom through the stuff after our beloved v character and find any evil
97 // space characters, which are most likely from SL having found a duplicate item
98 // name and not so helpfully renamed it for us.
100 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
101 //log_it("indy=" + (string)space_v_posn);
102 if (llGetSubString(to_chop_up, indy, indy) == " ") {
103 // found one; zap it. since we're going backwards we don't need to
104 // adjust the loop at all.
105 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
106 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
109 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
110 // ditch the space character for our numerical check.
111 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
112 // strip out a 'v' if there is one.
113 if (llGetSubString(chop_suffix, 0, 0) == "v")
114 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
115 // if valid floating point number and greater than zero, that works for our version.
116 string basename = to_chop_up; // script name with no version attached.
117 if ((float)chop_suffix > 0.0) {
118 // this is a big success right here.
119 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
120 return [ basename, chop_suffix ];
122 // seems like we found nothing useful.
130 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
131 on_rez(integer parm) { state rerun; }
133 state rerun { state_entry() { state default; } }
141 llSetStatus(STATUS_PHANTOM, TRUE);
142 //llWhisper(0, "resetting and taking on phantom state.");
144 llSetTimerEvent(phantom_duration());
150 // we turn ethereal now.
152 llWhisper(0, "becoming a phantom");
153 llSetStatus(STATUS_PHANTOM, TRUE);
155 llSetTimerEvent(phantom_duration());
159 llWhisper(0, "becoming solid");
160 llSetStatus(STATUS_PHANTOM, FALSE);
162 llSetTimerEvent(solid_duration());