normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / fredboxmux_no_rot_v3.0.txt
1 
2 // huffware script: fredboxmux (no rotation), by fred huffhines.
3 //
4 // a memory saving kludge script; it is the combination of the canonical huffware
5 // scripts: (1) non-script giver, (2) rotanium rotato, (3) text label.
6 // our theory is that by having only two scripts per display object (this script and
7 // the updater client) instead of four, we'll save some cpu on our overburdened but
8 // beloved server (serene).
9 // given that this script is intended to replace those three scripts, it will eat them
10 // on startup to avoid having redundant services in the object.
11 // update for april 24 2011: added a question menu before doing the copying to user's
12 // inventory, since opensim can do a weird thing that sets all folders to "loading...".
13 // this now keeps the objects from being super annoying when one didn't mean to click it.
14 //
15 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
16 // do not use it in objects without fully realizing you are implicitly accepting that license.
17 //
18
19 // non-script giver:
20 //
21 // gives all objects, notecards, etc contained in an object when that object is touched.
22 // does not give out scripts, since these are generally not something that should be handed
23 // to the customer.
24 //
25 // rotanium rotato:
26 //
27 // causes the object to rotate according to the parameters set below.
28 // this can use herky-jerky timed rotation with llSetRot or it can use
29 // smooth rotation with llTargetOmega.
30 //
31 // text label:
32 //
33 // a super simple script for giving an object readable text.
34
35 integer DEBUGGING = FALSE;  // set to true for noisier runs.
36
37 integer DO_ROTATION = FALSE;  // is this the rotating version or not?
38
39 integer USE_SENSORS = TRUE;  // should we look for avatars so we can display the label?
40
41 float SMOOTH_TIMER_FREQUENCY = 7.0;
42     // fastest possible rate of change for the smooth rotater, in seconds.  the smooth
43     // rotater doesn't need to hit the timer all that often, but this is faster than it
44     // needs to be for rotation, since it is also used as the rate at which the avatar sensor
45     // fires.
46
47 float TIME_TO_CLEAR_TITLE = 8.0;
48     // how many seconds before the title that was set for an avatar or due to a touch will
49     // disappear again.
50
51 vector LABEL_COLOR = <0.3, 0.9, 0.4>;
52     // color of the text above object.
53
54 float ACTIVE_LABEL_DISTANCE = 5.0;
55     // how far away can avatars cause the label to light up?
56
57 integer ONLY_GIVE_TO_OWNER = TRUE;
58     // if this is true, then only the owner will receive a copy of the items.
59
60 integer GIVE_UNCOPYABLES = FALSE;
61     // this flag is dangerous when true, because it means that uncopyable objects will still
62     // be handed to the target.  if that target refuses the non-copyable items, then the items
63     // will be lost forever.  that is not so good if you've sold the person a non-copy item.
64
65 string EXCLUDED_NOTECARD = "product description";
66     // a special case; if there is a giftorse configuration card, we won't hand that out.
67
68 float SMOOTH_CHANCE_FOR_ADJUSTING = 0.28;
69     // we won't always change the smooth rotation, even though our timer is pretty slow.
70     // this value is the percentage of the time that we do actually change rotation (divided
71     // by 100).
72
73 float SMOOTH_ROTATION_GAIN_MAX = 0.0490873852122;
74     // the gain is how fast we will rotate in radians per second.
75     // PI / 2 is about 90 degrees per second, which seems way too fast.
76     // 0.196349540849 is about PI / 16, 0.0981747704244 is about PI / 32,
77     // and 0.0490873852122 is about PI / 64.
78
79 string object_label = "default";  // change this if you want a specific name.
80
81 string old_name;  // tracks the last known name so we know if we need to update title.
82 float old_opacity = 3.14;  // tracks the last opacity setting for the label.
83
84 integer label_changed = TRUE;
85     // this remembers if the label has stayed put or not.  we use it to decide
86     // whether we need to check the label for carriage returns.
87
88 vector current_add_in = <0.0, 0.0, 0.4>;
89     // randomly assigned to if RANDOMIZE_ROTATION is true.
90
91 float current_gain = -0.05;
92     // speed of smooth rotation; will randomly change if RANDOMIZE_ROTATION is true.
93
94 float MIN_ADDITION = 0.01;
95     // smallest amount of change we will ever have.
96 float MAX_ADDITION = 7.0;
97     // largest amount of change we will ever have.
98
99 key first_toucher;  // tracks who clicked on the object to get contents.
100
101 float label_opacity = 1.0;  // how opaque should text be?  1.0 is solid, 0.0 transparent.
102
103 // takes out the 3 scripts that have been combined into the mux.  otherwise, it's
104 // more of a pain to update all the boxes with this thing when it's ready to go.
105 remove_redundant_scripts()
106 {
107     integer posn;
108     string self = llGetScriptName();
109     // zoom across the scripts to see if we have any in the inventory that
110     // are slated for removal.
111     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
112         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
113         if (curr_script != self) {
114             if ( (llSubStringIndex(curr_script, "non-script giver") == 0)
115                 || (llSubStringIndex(curr_script, "rotanium rotato") == 0)
116                 || (llSubStringIndex(curr_script, "text label") == 0) ) {
117                 // this one is a match!  zap it.
118                 llRemoveInventory(curr_script);
119             }
120             
121         }
122     }
123 }
124
125 // the avatar has said it's okay to hand out all the stuff to her/him.
126 really_give_contents() { give_out_contents(first_toucher); }
127
128 // give out pictures, notecards, objects, etc. that are hiding in the object.
129 give_out_contents(key give_to)
130 {
131     list all_to_give = [];  // the set we will hand over in a batch.
132     list uncopyables = [];  // the list we have to do individually.
133     // find out how many items there are.
134     integer count = llGetInventoryNumber(INVENTORY_ALL);
135     // iterate across all the items and add them to the gift list if appropriate.
136     integer indy;
137     for (indy = 0; indy < count; indy++) {
138         string item_name = llGetInventoryName(INVENTORY_ALL, indy);
139         integer type = llGetInventoryType(item_name);
140         if ( (type != INVENTORY_SCRIPT) 
141             && ( (type != INVENTORY_NOTECARD) || (item_name != EXCLUDED_NOTECARD) ) ) {
142             // it's okay to add this item; it's not a script and we are not skipping the special notecard.
143             integer mask = MASK_OWNER;
144             if (!ONLY_GIVE_TO_OWNER) mask = MASK_EVERYONE;
145             integer perms = llGetInventoryPermMask(item_name, mask);
146             if (perms & PERM_COPY) {
147                 // a normal object that we can hand out.
148                 all_to_give += item_name;
149             } else {
150                 uncopyables += item_name;
151             }
152         }
153     }
154     // hand the customer the whole set as one big chunk, named after the object.
155     llGiveInventoryList(give_to, llGetObjectName(), all_to_give);
156
157     // handle any problematic items.  we cannot copy these objects into a category folder,
158     // so we can either not try to copy them (a lot safer) or we can try to deliver them
159     // normally as individual items.  the latter choice is more dangerous, because if the
160     // owner discards these items rather than keeping them, the items will be lost forever!
161     if (llGetListLength(uncopyables) > 0) {
162         string plural = " ";
163         string is_verb = "is ";
164         string third_noun_subj = "it ";
165         string third_noun_obj = "it ";
166         if (llGetListLength(uncopyables) > 1) {
167             plural = "s ";
168             is_verb = "are ";
169             third_noun_subj = "they ";
170             third_noun_obj = "them ";
171         }
172         
173         string uncopyable_message = "will be left inside the object.  To get " + third_noun_obj
174             + ", please copy " + third_noun_obj + "\nmanually from this object into your inventory.";
175         if (GIVE_UNCOPYABLES) {
176             uncopyable_message = "will be moved over to your inventory."
177             + "\nPlease look in your main folders for "
178             + third_noun_obj + "(e.g., in Objects or Textures).";
179         }
180         
181         string failure_message = "The item" + plural
182             + "[" + llDumpList2String(uncopyables, "; ") + "]\n"
183             + is_verb + "not copyable; " + third_noun_subj
184             + uncopyable_message;
185             
186         if (llGetOwner() == give_to) {
187             // the object can be moved to inventory, but not with the category method.
188             llOwnerSay(failure_message);
189         } else {
190             // this seems like a weird case; it will probably just fail anyhow?
191             // if the item's not copyable and you're not the owner of this object,
192             // how can we give it to you?
193             llInstantMessage(give_to, failure_message);
194         }
195         
196         // now that we've announced this weird situation, handle it appropriately.
197         if (GIVE_UNCOPYABLES) {
198             for (indy = 0; indy < llGetListLength(uncopyables); indy++) {
199                 string item_name = llList2String(uncopyables, indy);
200                 llGiveInventory(give_to, item_name);
201             }
202         }  // otherwise leave them be.
203     }
204 }
205
206 // causes the object to rotate using whatever the current settings are.
207 smooth_rotate_using_our_settings()
208 {
209     // make sure we are using the rotational values we were asked to.
210     llTargetOmega(current_add_in, current_gain, 1.0);
211 }
212
213 // sets the gain and add in to random choices.
214 randomize_values()
215 {
216     current_gain = randomize_within_range(0.001, SMOOTH_ROTATION_GAIN_MAX, TRUE);
217     current_add_in = random_vector(MIN_ADDITION, MAX_ADDITION, TRUE);
218 }
219
220 // performs the timed rotation that has been configured for us.
221 rotate_as_requested()
222 {
223     // our slack timer went off, so randomize the rotation if requested.
224     if (llFrand(1.0) >= (1.0 - SMOOTH_CHANCE_FOR_ADJUSTING) ) {
225         randomize_values();
226         smooth_rotate_using_our_settings();
227     }
228 }
229
230 initialize_fredboxmux()
231 {
232     // make sure we pick a good random channel.
233     menu_system_channel = -1 * (integer)randomize_within_range(200, 10000000, FALSE);
234
235     // if needed, we will set our initial random rotation.
236     randomize_values();
237         
238     // do a first rotate, so we move right at startup.  otherwise we won't move
239     // until after our first timer hits.
240     if (DO_ROTATION) rotate_as_requested();
241
242     // now set the timer for our mode.
243     llSetTimerEvent(SMOOTH_TIMER_FREQUENCY);
244     if (DO_ROTATION) smooth_rotate_using_our_settings();
245 }
246
247 set_text()
248 {
249 //log_it("old name " + old_name + " -- curr name " + llGetObjectName());
250     if (old_name != llGetObjectName()) {
251         // we're out of synch on the object name.
252         label_changed = TRUE;
253     }
254     if (old_opacity != label_opacity) {
255         // here we're out of synch on last opacity used.
256         label_changed = TRUE;
257     }
258     if (label_changed) {
259         // reset the object title to a decorated version of object name if it says "default".
260         string new_label = object_label;
261         if (new_label == "default") new_label = llGetObjectName();
262     
263         integer indy;
264         integer keep_going = TRUE;
265         while (keep_going) {
266             indy = find_substring(new_label, "\\n");
267             if (indy < 0) {
268                 keep_going = FALSE;
269             } else {
270                 new_label = llGetSubString(new_label, 0, indy - 1)
271                     + "\n" + llGetSubString(new_label, indy + 2, -1);
272             }
273         }
274         old_name = llGetObjectName();
275         old_opacity = label_opacity;
276         label_changed = FALSE;  // we have dealt with it now.
277 //log_it("setting text: " + new_label);
278         llSetText(new_label, LABEL_COLOR, label_opacity);
279     }
280     if (label_opacity != 0) {
281         // if we set a lit-up title, clear it again pretty soon.
282         llSetTimerEvent(TIME_TO_CLEAR_TITLE);
283     }
284 }
285
286 //////////////
287 // code borrowed from menutini to raise a menu asking if they actually meant to get all
288 // the contents.  an opensim inventory bug makes all the folders look foolish if we
289 // do any inventory giving accidentally.
290 //////////////
291
292 // global variables...
293
294 list _private_global_buttons;  // holds onto the active set of menu options.
295 string _private_global_av_key;  // the key for the avatar who clicks the menu.
296 string _private_global_title;  // holds onto current title text.
297
298 integer _menu_base_start = 0;  // position in the items of the current menu.
299
300 integer listening_id = 0;
301     // the current id of our listening for the menu.  it's an id returned by LSL
302     // that we need to track so we can cancel the listen.
303
304 integer menu_system_channel = -123;
305     // messages come back to us from this channel when user clicks the dialog.
306     // this is set later and the default is meaningless.
307
308 string global_menu_name = "";
309     // hangs onto the current menu's name.
310
311 //hmmm: note; to manage multiple concurrent menus on different channels,
312 //      we must make these into lists.  then the timeouts should apply
313 //      individually to these instead of overall (if we even do timeouts;
314 //      it's nicer if menus never stop being active).
315
316 string NEXT_MENU_TEXT = "Next >>";
317     // what the next item will say for showing next menu page.
318     
319 //integer TIMEOUT_FOR_MENU = 42;
320     // timeout for the menu in seconds.
321
322 // displays the menu requested.  it's "menu_name" is an internal name that is
323 // not displayed to the user.  the "title" is the content shown in the main area
324 // of the menu.  "commands_in" is the list of menu items to show as buttons.
325 // the "menu_channel" is where the user's clicked response will be sent.  the
326 // "listen_to" key is the avatar expected to click the menu, which is needed to
327 // listen to his response.
328 show_menu(string menu_name, string title, list buttons,
329     integer menu_channel, key listen_to)
330 {
331     // save our new parms.
332     global_menu_name = menu_name;
333     _private_global_title = title;
334     _private_global_buttons = buttons;
335     menu_system_channel = menu_channel;
336     _private_global_av_key = listen_to;
337     if (DEBUGGING) {
338         log_it("menu name: " + global_menu_name);
339         log_it("title: " + _private_global_title);
340         log_it("buttons: " + (string)buttons);
341         log_it("channel: " + (string)menu_system_channel);
342         log_it("listen key: " + (string)listen_to);
343     }
344
345     integer add_next = FALSE;  // true if we should add a next menu item.
346
347     // the math here incorporates current button position.
348     integer current = _menu_base_start;
349     integer max_buttons = llGetListLength(buttons) - current;
350
351     if (max_buttons > 12) {
352         // limitation of SL: menus have a max of 12 buttons.
353         max_buttons = 12;
354         add_next = TRUE;
355     } else if (llGetListLength(buttons) > 12) {
356         // we already have been adding next.  let's make sure this gets
357         // a wrap-around next button.
358         add_next = TRUE;
359     }
360     // chop out what we can use in a menu.
361     list trunc_buttons = llList2List(buttons, current, current + max_buttons - 1);
362     if (add_next) {
363         // we were asked to add a menu item for the next screen.
364         trunc_buttons = llList2List(trunc_buttons, 0, 10) + NEXT_MENU_TEXT;
365     }
366
367     listening_id = llListen(menu_channel, "", listen_to, "");
368     list commands;
369     integer i;
370     // take only the prefix of the string, to avoid getting a length complaint.
371     for (i = 0; i < llGetListLength(trunc_buttons); i++) {
372         string curr = llList2String(trunc_buttons, i);
373         integer last_pos = 23;  // default maximum, highest possible is 24.
374         if (llStringLength(curr) - 1 < last_pos) last_pos = llStringLength(curr) - 1;
375         curr = llGetSubString(curr, 0, last_pos);
376         commands += curr;
377     }
378     llDialog(listen_to, title, commands, menu_channel);
379 }
380
381 // shuts down any connection we might have had with any active menu.  we will not
382 // send any responses after this point (although we might already have responded when
383 // the user clicked the menu).
384 clear_menu()
385 {
386     llListenRemove(listening_id);
387 }
388
389 // process the response when the user chooses a menu item.
390 process_menu_response(integer channel, string name, key id, string message)
391 {
392   if (channel != menu_system_channel) return;  // not for us.
393   
394     if (message == NEXT_MENU_TEXT) {
395         // this is the special choice, so we need to go to the next page.
396         _menu_base_start += 11;
397         if (_menu_base_start > llGetListLength(_private_global_buttons)) {
398             // we have wrapped around the list.  go to the start again.
399             _menu_base_start = 0;
400         }
401         show_menu(global_menu_name, _private_global_title,
402             _private_global_buttons, menu_system_channel,
403             _private_global_av_key);
404         return;  // handled by opening a new menu.
405     }
406     
407     string calculated_name;
408     integer indy;
409     // first try for an exact match.
410     for (indy = 0; indy < llGetListLength(_private_global_buttons); indy++) {
411         string curr = llList2String(_private_global_buttons, indy);
412         if (curr == message) {
413             // correct the answer based on the full button string.
414             calculated_name = curr;
415         }
416     }
417     if (calculated_name == "") {
418         // try an imprecise match if the exact matching didn't work.
419         for (indy = 0; indy < llGetListLength(_private_global_buttons); indy++) {
420             string curr = llList2String(_private_global_buttons, indy);
421             if (is_prefix(curr, message)) {
422                 // correct the answer based on the full button string.
423                 calculated_name = curr;
424             }
425         }
426     }
427     if (calculated_name == "yes") {
428         // only send a response if that menu choice made sense to us.
429         really_give_contents();
430         clear_menu();
431     }
432 }
433
434 // end from menutini.
435 //////////////
436
437 //////////////
438 // start of hufflets...
439
440 // returns a number at most "maximum" and at least "minimum".
441 // if "allow_negative" is TRUE, then the return may be positive or negative.
442 float randomize_within_range(float minimum, float maximum, integer allow_negative)
443 {
444     if (minimum > maximum) {
445         // flip the two if they are reversed.
446         float temp = minimum; minimum = maximum; maximum = temp;
447     }
448     float to_return = minimum + llFrand(maximum - minimum);
449     if (allow_negative) {
450         if (llFrand(1.0) < 0.5) to_return *= -1.0;
451     }
452     return to_return;
453 }
454
455 // returns a random vector where x,y,z will be between "minimums" and "maximums"
456 // x,y,z components.  if "allow_negative" is true, then any component will
457 // randomly be negative or positive.
458 vector random_bound_vector(vector minimums, vector maximums, integer allow_negative)
459 {
460     return <randomize_within_range(minimums.x, maximums.x, allow_negative),
461         randomize_within_range(minimums.y, maximums.y, allow_negative),
462         randomize_within_range(minimums.z, maximums.z, allow_negative)>;
463 }
464
465 // returns a vector whose components are between minimum and maximum.
466 // if allow_negative is true, then they can be either positive or negative.
467 vector random_vector(float minimum, float maximum, integer allow_negative)
468 {
469     return random_bound_vector(<minimum, minimum, minimum>,
470         <maximum, maximum, maximum>, allow_negative);
471 }
472
473 //////////////
474
475 integer debug_num = 0;
476
477 // a debugging output method.  can be disabled entirely in one place.
478 log_it(string to_say)
479 {
480     debug_num++;
481     // tell this to the owner.    
482     llOwnerSay(llGetDate() + ": " + llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
483 //llWhisper(0, llGetDate() + ": " + llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
484     // say this on an unusual channel for chat if it's not intended for general public.
485 //    llSay(108, llGetDate() + ": " + llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
486     // say this on open chat that anyone can hear.  we take off the bling for this one.
487 //    llSay(0, to_say);
488 }
489
490 // returns the index of the first occurrence of "pattern" inside
491 // the "full_string".  if it is not found, then a negative number is returned.
492 integer find_substring(string full_string, string pattern)
493 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
494
495 // returns TRUE if the "prefix" string is the first part of "compare_with".
496 integer is_prefix(string compare_with, string prefix)
497 { return (llSubStringIndex(compare_with, prefix) == 0); }
498
499 //////////////
500 // huffware script: auto-retire, by fred huffhines, version 2.8.
501 // distributed under BSD-like license.
502 //   !!  keep in mind that this code must be *copied* into another
503 //   !!  script that you wish to add auto-retirement capability to.
504 // when a script has auto_retire in it, it can be dropped into an
505 // object and the most recent version of the script will destroy
506 // all older versions.
507 //
508 // the version numbers are embedded into the script names themselves.
509 // the notation for versions uses a letter 'v', followed by two numbers
510 // in the form "major.minor".
511 // major and minor versions are implicitly considered as a floating point
512 // number that increases with each newer version of the script.  thus,
513 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
514 // and "hazmap v3.2" is a more recent version.
515 //
516 // example usage of the auto-retirement script:
517 //     default {
518 //         state_entry() {
519 //            auto_retire();  // make sure newest addition is only version of script.
520 //        }
521 //     }
522 // this script is partly based on the self-upgrading scripts from markov brodsky
523 // and jippen faddoul.
524 //////////////
525 auto_retire() {
526     string self = llGetScriptName();  // the name of this script.
527     list split = compute_basename_and_version(self);
528     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
529     string basename = llList2String(split, 0);  // script name with no version attached.
530     string version_string = llList2String(split, 1);  // the version found.
531     integer posn;
532     // find any scripts that match the basename.  they are variants of this script.
533     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
534         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
535         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
536             // found a basic match at least.
537             list inv_split = compute_basename_and_version(curr_script);
538             if (llGetListLength(inv_split) == 2) {
539                 // see if this script is more ancient.
540                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
541                 // must make sure that the retiring script is completely the identical basename;
542                 // just matching in the front doesn't make it a relative.
543                 if ( (llList2String(inv_split, 0) == basename)
544                     && ((float)inv_version_string < (float)version_string) ) {
545                     // remove script with same name from inventory that has inferior version.
546                     llRemoveInventory(curr_script);
547                 }
548             }
549         }
550     }
551 }
552 //
553 // separates the base script name and version number.  used by auto_retire.
554 list compute_basename_and_version(string to_chop_up)
555 {
556     // minimum script name is 2 characters plus a version.
557     integer space_v_posn;
558     // find the last useful space and 'v' combo.
559     for (space_v_posn = llStringLength(to_chop_up) - 3;
560         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
561         space_v_posn--) {
562         // look for space and v but do nothing else.
563     }
564     if (space_v_posn < 2) return [];  // no space found.
565     // now we zoom through the stuff after our beloved v character and find any evil
566     // space characters, which are most likely from SL having found a duplicate item
567     // name and not so helpfully renamed it for us.
568     integer indy;
569     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
570         if (llGetSubString(to_chop_up, indy, indy) == " ") {
571             // found one; zap it.  since we're going backwards we don't need to
572             // adjust the loop at all.
573             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
574         }
575     }
576     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
577     // ditch the space character for our numerical check.
578     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
579     // strip out a 'v' if there is one.
580     if (llGetSubString(chop_suffix, 0, 0) == "v")
581         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
582     // if valid floating point number and greater than zero, that works for our version.
583     string basename = to_chop_up;  // script name with no version attached.
584     if ((float)chop_suffix > 0.0) {
585         // this is a big success right here.
586         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
587         return [ basename, chop_suffix ];
588     }
589     // seems like we found nothing useful.
590     return [];
591 }
592 //
593 //////////////
594
595 //end hufflets...
596 //////////////
597
598 default
599 {
600     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
601     on_rez(integer parm) { state rerun; }
602 }
603 state rerun { state_entry() { state default; } }
604
605 state real_default
606 {
607     state_entry() {
608         auto_retire();
609         remove_redundant_scripts();
610         initialize_fredboxmux();
611         label_opacity = 1;  // start out showing the label.
612         set_text();
613     }
614     
615     on_rez(integer start_parm) { state default; }
616     
617     changed(integer change) {
618         if (change & CHANGED_INVENTORY) {
619             // we show the label at least a bit when the contents change.
620             label_opacity = 1;
621             set_text(); 
622         }
623     }
624     
625     touch_start(integer num) {
626         label_opacity = 1.0;
627         set_text();
628         first_toucher = llDetectedKey(0);
629         // are we only supposed to give stuff to the owner?
630         if (ONLY_GIVE_TO_OWNER && (first_toucher != llGetOwner()) ) {
631             first_toucher = NULL_KEY;
632             return;  // bail out.
633         }
634         show_menu("askreally", "Would you like a copy of this object's contents?",
635             ["yes", "no"], -18264, first_toucher);
636     }
637
638     listen(integer channel, string name, key id, string message)
639     { process_menu_response(channel, name, id, message); }
640
641     timer() {
642         llSetTimerEvent(0);
643         if (DO_ROTATION) rotate_as_requested();
644         if (USE_SENSORS) {
645             llSensor("", NULL_KEY, AGENT, ACTIVE_LABEL_DISTANCE, PI);
646         } else {
647             if (label_opacity != 0.0) {
648                 label_opacity = 0.0;
649                 set_text();
650             }            
651         }
652         llSetTimerEvent(SMOOTH_TIMER_FREQUENCY);
653     }
654
655     sensor(integer count) {
656         if (label_opacity != 1.0) {
657             label_opacity = 1.0;
658             set_text();
659         }
660     }
661     
662     no_sensor() {
663         if (label_opacity != 0.0) {
664             label_opacity = 0.0;
665             set_text();
666         }
667     }
668 }
669