Gayngel

Music Box Loop Script

Aug 30th, 2021 (edited)
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Do not sell this; Karma knowz where you live ☠
  2.  
  3. // How-to/Info:
  4. // Put this script with some sound clips (numbered so they play in order)
  5. // into a prim, then change the below values to suit your needs!!!
  6. // Example, change the sound_length to match how long your sound clips are
  7.  
  8. float   sound_length = 9.0;//How long the sound clips are
  9. float   sound_volume = 1.0;//from 0.00 to 1.00
  10. float   slow_server_adjustment = 0.00;//..
  11. float text_alpha = 0.5;//how visible floating text is, from 0.00 to 1.00
  12. vector text_color = <1,2,3>;//color of the floating text
  13. integer num_sounds;//how many sound clips
  14. integer active = FALSE;//Are we on/TRUE or off/FALSE
  15. //list sound_list;// not needed for this job
  16.  
  17. loop_sounds(){
  18.     integer sound;//first sound in the inventory
  19.     for(; sound < num_sounds; ++sound){
  20.         //llOwnerSay((string)sound + " - "+llGetInventoryName(INVENTORY_SOUND, sound));
  21.         llTriggerSound(llGetInventoryName(INVENTORY_SOUND, sound), sound_volume);
  22.         llSleep(sound_length);
  23.     }  
  24. }
  25.  
  26. load_sounds(){
  27.     integer sound;
  28.     for(; sound < num_sounds; ++sound){
  29.         string s = llGetInventoryName(INVENTORY_SOUND, sound);
  30.         llSetText("• Preloading Sound • \n"+s, text_color, text_alpha);
  31.         llPreloadSound(s);
  32.     }llSetText(" ", text_color, text_alpha);
  33. }
  34.  
  35. integer count_sounds(){
  36.     integer i;
  37.     integer n = llGetInventoryNumber(INVENTORY_SOUND);
  38.     list result = [];
  39.     for(i = 0; i < n; i++){
  40.         result += [llGetInventoryName(INVENTORY_SOUND, i)];
  41.     }//sound_list = result;
  42.     return llGetListLength(result);
  43. }
  44.  
  45.  
  46. Play()
  47. {
  48.    
  49.  num_sounds = count_sounds();
  50.             load_sounds();
  51.             llSetTimerEvent((num_sounds * sound_length)-(num_sounds * slow_server_adjustment));
  52.           //  llWhisper(0,"/me • Playing.");
  53.             loop_sounds();  
  54.    
  55. }
  56.  
  57. string help = "• Help / Usage •
  58. 1. Load sounds into the prim that has this script inside.
  59. 2. Open the script and find the \"sound_length\" value.
  60. 3. Change that value to match how your sound clips are.
  61. 4. Touch the object, wait for the sounds to preload.. Done!
  62.  
  63. Note: Uncomment the line in the touch_event to make it \"owner only\".";
  64.  
  65. default{
  66. //
  67.     state_entry(){
  68.         llSetText(" ", text_color, text_alpha);
  69.         active = TRUE;
  70.         Play();
  71.     }
  72. //
  73.     changed(integer c){
  74.  
  75. if(c & CHANGED_OWNER){
  76.             llWhisper(0,"/me "+help);
  77.             llResetScript();
  78.         }
  79.        
  80.          
  81.      else if(c & CHANGED_REGION_START)
  82.      {
  83.      
  84.        llResetScript();    
  85.          
  86.      }
  87.     }
  88. //
  89.    
  90.    
  91.    
  92.    
  93.     //on_rez(integer num_detected){
  94.     touch_start(integer total_number){
  95.         if(llDetectedKey(0) != llGetOwner())return;//uncomment for owner only
  96.         active =! active;
  97.         if(active){
  98.        
  99.             Play();
  100.         }else{
  101.             llSetTimerEvent(0.0);
  102.             llWhisper(0,"/me • Stopped.");
  103.         }
  104.     }
  105. //
  106.     timer(){
  107.         loop_sounds();
  108.     }
  109.    
  110.    
  111. //
  112. }
Add Comment
Please, Sign In to add comment