2 // huffware script: timed expiration, by fred huffhines.
4 // this ensures that an object only lives a set amount of time before de-rezzing.
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 float PRODUCT_LIFETIME = 0.9; // time allowed before the object terminates, in minutes.
11 // since we now make the object temporary, this has to be less than a minute
12 // for our own dying scene to take place. otherwise the object just disappears.
14 float EXPIRY_VOLUME = 0.25;
15 // we have found that this volume level is generally good, since you don't want
16 // the object screaming like crazy as it evaporates.
20 // huffware script: auto-retire, by fred huffhines, version 1.9.
21 // distributed under BSD-like license.
22 // partly based on the self-upgrading scripts from markov brodsky and jippen faddoul.
23 // the function auto_retire() should be added *inside* a version numbered script that
24 // you wish to give the capability of self-upgrading.
25 // this script supports a notation for versions embedded in script names where a 'v'
26 // is followed by a number in the form "major.minor", e.g. "grunkle script by ted v8.2".
27 // when the containing script is dropped into an object with a different version, the
28 // most recent version eats any existing ones.
29 // keep in mind that this code must be *copied* into your script you wish to add
30 // auto-retirement capability to.
32 // example usage of the auto-retirement script:
36 // auto_retire(); // make sure newest addition is only version of script.
40 string self = llGetScriptName(); // the name of this script.
41 list split = compute_basename_and_version(self);
42 if (llGetListLength(split) != 2) return; // nothing to do for this script.
43 string basename = llList2String(split, 0); // script name with no version attached.
44 string version_string = llList2String(split, 1); // the version found.
46 // find any scripts that match the basename. they are variants of this script.
47 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
48 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
49 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
50 // found a basic match at least.
51 list inv_split = compute_basename_and_version(curr_script);
52 if (llGetListLength(inv_split) == 2) {
53 // see if this script is more ancient.
54 string inv_version_string = llList2String(inv_split, 1); // the version found.
55 if ((float)inv_version_string < (float)version_string) {
56 // remove script with same name from inventory that has inferior version.
57 llRemoveInventory(curr_script);
64 // separates the base script name and version number. used by auto_retire.
65 list compute_basename_and_version(string to_chop_up)
67 if (llSubStringIndex(to_chop_up, " ") < 0) return []; // no space found, not a valid name to work on.
69 string basename = to_chop_up; // script name with no version attached.
72 // minimum script name is 2 characters plus version.
73 for (posn = llStringLength(to_chop_up) - 1;
74 (posn >= 2) && (llGetSubString(to_chop_up, posn, posn) != " ");
76 // find the space. do nothing else.
78 if (posn < 2) return []; // no space found.
79 string full_suffix = llGetSubString(to_chop_up, posn, -1);
80 // ditch the space character for our numerical check.
81 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
82 // strip out a 'v' if there is one.
83 if (llGetSubString(chop_suffix, 0, 0) == "v")
84 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
85 // if valid floating point number and greater than zero, that works for our version.
86 if ((float)chop_suffix > 0.0) {
87 // this is a big success right here.
88 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
89 return [ basename, chop_suffix ];
91 // seems like we found nothing useful.
97 // how many times the timer is hit per minute.
98 float TICKS_PER_MINUTE = 20.0;
100 float ticks_to_live; // how long this particular object has left.
104 // integer secs_left = (integer)(60.0 * ticks_to_live / TICKS_PER_MINUTE);
105 // llWhisper(14, (string)secs_left + " seconds before expiration.");
110 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
111 on_rez(integer parm) { state rerun; }
113 state rerun { state_entry() { state default; } }
118 llParticleSystem([]); // kill any old particles running.
120 //llWhisper(0, "starting up " + llGetObjectName());
121 ticks_to_live = PRODUCT_LIFETIME * TICKS_PER_MINUTE;
122 llSetTimerEvent(60.0 / TICKS_PER_MINUTE); // check avatar's state periodically.
123 // make sure this is a temporary object.
124 llSetPrimitiveParams([PRIM_TEMP_ON_REZ, TRUE]);
129 // make sure we don't wait too long to reset our temporariness.
130 integer time_now = llGetUnixTime();
131 // check whether we should stay alive or not.
132 if (--ticks_to_live <= 0.0) {
133 // llWhisper(0, llGetObjectName() + " is terminating now.");
134 string first_sound = llGetInventoryName(INVENTORY_SOUND, 0);
135 if (first_sound != "")
136 llTriggerSound(first_sound, EXPIRY_VOLUME);
137 string first_pic = llGetInventoryName(INVENTORY_TEXTURE, 0);
139 llMakeExplosion(20, 1.0, 5, 3.0, 1.0, first_pic, ZERO_VECTOR);
141 // resetting this since if we're here, we don't want to keep blowing up.
142 ticks_to_live = PRODUCT_LIFETIME * TICKS_PER_MINUTE;
148 on_rez(integer param) {
149 // make sure we start over when this is a new object.
153 touch_start(integer total_number)
155 ticks_to_live += TICKS_PER_MINUTE; // add a minute to its life.
156 // llWhisper(0, "Object gets another minute to live.");