2 // jukebox script. unknown provenance.
3 // modified for use in opensim by fred huffhines.
5 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
6 // do not use it in objects without fully realizing you are implicitly accepting that license.
11 integer IS_OPENSIM = TRUE;
12 // this must be set to true to turn off the sound queuing. opensim does not currently implement it.
14 float SOUND_OFFSET_PERIOD = 1.1; // number of seconds to start the sound in advance.
16 integer LISTEN_CHAN = 2000;
17 integer SEND_CHAN = 2001;
22 integer g_iListenCtrl = -1;
34 // hold onto the names of all the songs so we don't need to keep
35 // going back to inventory.
39 llSetText(llGetObjectName(), <0, 100, 100>, 10);
42 if ( g_iListenCtrl != -1 )
44 llListenRemove(g_iListenCtrl);
46 g_iListenCtrl = llListen(LISTEN_CHAN,"","","");
51 total_tracks = llGetInventoryNumber(INVENTORY_SOUND);
52 for ( i = 0; i < total_tracks; i++ ) {
53 string name = llGetInventoryName(INVENTORY_SOUND, i);
54 song_names += [ name ];
57 //llOwnerSay("got song names list: " + (string)song_names);
67 llWhisper(0, "Playing...");
69 llSetSoundQueueing(TRUE);
71 llAdjustSoundVolume(1.0);
72 llPlaySound(llList2String(song_names, 0), VOLUME);
73 llPreloadSound(llList2String(song_names, 1));
74 // set the timer interval for just before the track chunk ends.
75 llSetTimerEvent(INTERVAL - SOUND_OFFSET_PERIOD);
83 llWhisper(0, "Stopping...");
85 llAdjustSoundVolume(0);
94 sLink = llGetLinkName(1);
96 if ( llGetSubString(sLink,0,6) == "Jukebox" )
105 // huffware script: auto-retire, by fred huffhines, version 2.8.
106 // distributed under BSD-like license.
107 // !! keep in mind that this code must be *copied* into another
108 // !! script that you wish to add auto-retirement capability to.
109 // when a script has auto_retire in it, it can be dropped into an
110 // object and the most recent version of the script will destroy
111 // all older versions.
113 // the version numbers are embedded into the script names themselves.
114 // the notation for versions uses a letter 'v', followed by two numbers
115 // in the form "major.minor".
116 // major and minor versions are implicitly considered as a floating point
117 // number that increases with each newer version of the script. thus,
118 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
119 // and "hazmap v3.2" is a more recent version.
121 // example usage of the auto-retirement script:
124 // auto_retire(); // make sure newest addition is only version of script.
127 // this script is partly based on the self-upgrading scripts from markov brodsky
128 // and jippen faddoul.
131 string self = llGetScriptName(); // the name of this script.
132 list split = compute_basename_and_version(self);
133 if (llGetListLength(split) != 2) return; // nothing to do for this script.
134 string basename = llList2String(split, 0); // script name with no version attached.
135 string version_string = llList2String(split, 1); // the version found.
137 // find any scripts that match the basename. they are variants of this script.
138 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
139 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
140 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
141 // found a basic match at least.
142 list inv_split = compute_basename_and_version(curr_script);
143 if (llGetListLength(inv_split) == 2) {
144 // see if this script is more ancient.
145 string inv_version_string = llList2String(inv_split, 1); // the version found.
146 // must make sure that the retiring script is completely the identical basename;
147 // just matching in the front doesn't make it a relative.
148 if ( (llList2String(inv_split, 0) == basename)
149 && ((float)inv_version_string < (float)version_string) ) {
150 // remove script with same name from inventory that has inferior version.
151 llRemoveInventory(curr_script);
158 // separates the base script name and version number. used by auto_retire.
159 list compute_basename_and_version(string to_chop_up)
161 // minimum script name is 2 characters plus a version.
162 integer space_v_posn;
163 // find the last useful space and 'v' combo.
164 for (space_v_posn = llStringLength(to_chop_up) - 3;
165 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
167 // look for space and v but do nothing else.
169 if (space_v_posn < 2) return []; // no space found.
170 // now we zoom through the stuff after our beloved v character and find any evil
171 // space characters, which are most likely from SL having found a duplicate item
172 // name and not so helpfully renamed it for us.
174 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
175 if (llGetSubString(to_chop_up, indy, indy) == " ") {
176 // found one; zap it. since we're going backwards we don't need to
177 // adjust the loop at all.
178 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
181 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
182 // ditch the space character for our numerical check.
183 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
184 // strip out a 'v' if there is one.
185 if (llGetSubString(chop_suffix, 0, 0) == "v")
186 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
187 // if valid floating point number and greater than zero, that works for our version.
188 string basename = to_chop_up; // script name with no version attached.
189 if ((float)chop_suffix > 0.0) {
190 // this is a big success right here.
191 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
192 return [ basename, chop_suffix ];
194 // seems like we found nothing useful.
201 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
202 on_rez(integer parm) { state rerun; }
204 state rerun { state_entry() { state default; } }
214 on_rez(integer start_param)
219 g_iPod = start_param - 1;
222 llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
224 // Tell the controller what the CD key is so it can link
225 llWhisper(SEND_CHAN,"LINK " + (string)llGetKey());
230 changed(integer change)
232 if ( change == CHANGED_LINK )
234 if ( llGetLinkNumber() == 0 )
241 llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
243 llMessageLinked(1,llGetLinkNumber(),"LINKID","");
252 if ( id == NULL_KEY )
260 run_time_permissions(integer perm)
262 if ( perm == PERMISSION_ATTACH )
264 llAttachToAvatar(ATTACH_LSHOULDER);
265 llSetTexture("clear",ALL_SIDES);
269 touch_start(integer total_number)
273 for ( i = 0; i < total_number; i++ )
275 if ( llDetectedKey(i) == llGetOwner() )
277 //llWhisper(0,"DEBUG: g_iPlaying=" + (string)g_iPlaying);
278 //llWhisper(0,"DEBUG: Link=" + (string)llGetLinkNumber());
279 //llWhisper(0,"DEBUG: g_iWasLinked=" + (string)g_iWasLinked);
280 //llWhisper(0,"DEBUG: g_iFinished=" + (string)g_iFinished);
281 if ( g_iPlaying ) StopSong();
287 listen(integer channel, string name, key id, string message)
289 if ( message == "RESET" )
291 if ( llGetLinkNumber() == 0 )
295 llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
299 if ( message == "STOP" )
304 llDetachFromAvatar();
309 link_message(integer sender_num, integer num, string str, key id)
324 llMessageLinked(1,llGetLinkNumber(),"UNLINK","");
327 if ( str == "VOLUME" )
329 VOLUME = (float)num / 10.0;
330 llAdjustSoundVolume(VOLUME);
338 //llWhisper(0, "playing song #" + (string)(g_iSound+1) + ": " + llList2String(song_names, g_iSound));
339 llPlaySound(llList2String(song_names, g_iSound),VOLUME);
340 if ( g_iSound < (total_tracks - 1) )
342 llPreloadSound(llList2String(song_names, g_iSound + 1));
345 if ( g_iSound >= total_tracks )
347 llSetTimerEvent(INTERVAL + 5.0);
350 llSetTimerEvent(INTERVAL - SOUND_OFFSET_PERIOD);
353 if ( llGetLinkNumber() != 0 )
355 llSetTimerEvent(0.0);
358 llWhisper(SEND_CHAN,"FINISH");
359 llDetachFromAvatar();
361 llMessageLinked(1,0,"FINISH","");