User:Cow Taurog/Sound looper

From Second Life Wiki
Jump to navigation Jump to search

This script will continuously loop your choice of sounds dropped into it. Click to choose, click and hold to stop, menu responds to owner only. Up to 12 sounds are supported, more if you want to enhance the dialog menu on your own. <lsl> // This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License // http://creativecommons.org/licenses/by-sa/3.0/ // Commercial use is allowed. // Modification and/or distribution is allowed, as long as attribution for each revision is given, and the same license is used. // // Cow Taurog's sound looper, v1.0 // Drop this script, and up to 12 sounds that you want to loop into an object. // Click to choose the sound, click and hold to stop the sound. // The menu will automatically update when new sounds are added or removed, no reset or update is required on your part. integer giChan=882372; float gfHoldFor=2; integer giHold; list glItems; integer listen0; integer i; builditemlist(){ // Build a list of items in inventory

   glItems=[]; // Empty the old list
   integer j=llGetInventoryNumber(INVENTORY_SOUND); // Save the total number of objects
   for(i=0;i<j;i++){glItems+=[llGetInventoryName(INVENTORY_SOUND,i)];} // Store the items to the list

} default{

   on_rez(integer param){llResetScript();}
   state_entry(){llAllowInventoryDrop(TRUE);builditemlist();llStopSound();}
   touch_start(integer num){
       giHold=FALSE;
       llSetTimerEvent(gfHoldFor);
   }
   changed(integer change){if(change&CHANGED_INVENTORY){builditemlist();}}
   touch_end(integer num){if(giHold==FALSE){
       llSetTimerEvent(0);
       if(llDetectedKey(num-1)==llGetOwner()){
           if(glItems!=[]){listen0=llListen(giChan,"","","");llDialog(llGetOwner(),"Pick a sound to loop...",glItems,giChan);}
           else{llOwnerSay("There aren't any sounds in this object to loop, drop some in first.");}
       }
   }}
   listen(integer chan,string name,key id,string mess){if(id==llGetOwner()){
       llLoopSound(mess,1);
       llListenRemove(listen0);
   }}
   timer(){
       giHold=TRUE;
       llStopSound();
       llListenRemove(listen0);
       llSetTimerEvent(0);
   }

} </lsl>