Advertisement
Gayngel

Music Box Play on Collision

Aug 30th, 2021
2,468
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.76;//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. integer loop_sounds(){
  18.    
  19.     active = TRUE;  
  20.     integer sound;//first sound in the inventory
  21.     for(; sound < num_sounds; ++sound){
  22.         //llOwnerSay((string)sound + " - "+llGetInventoryName(INVENTORY_SOUND, sound));
  23.         llTriggerSound(llGetInventoryName(INVENTORY_SOUND, sound), sound_volume);
  24.         llSleep(sound_length);
  25.     }
  26.    
  27.     return TRUE;
  28. }
  29.  
  30. load_sounds(){
  31.     integer sound;
  32.     for(; sound < num_sounds; ++sound){
  33.         string s = llGetInventoryName(INVENTORY_SOUND, sound);
  34.     //    llSetText("• Preloading Sound • \n"+s, text_color, text_alpha);
  35.         llPreloadSound(s);
  36.     }llSetText(" ", text_color, text_alpha);
  37. }
  38.  
  39. integer count_sounds(){
  40.     integer i;
  41.     integer n = llGetInventoryNumber(INVENTORY_SOUND);
  42.     list result = [];
  43.     for(i = 0; i < n; i++){
  44.         result += [llGetInventoryName(INVENTORY_SOUND, i)];
  45.     }//sound_list = result;
  46.     return llGetListLength(result);
  47. }
  48.  
  49.  
  50. integer Play()
  51. {
  52.    
  53.  num_sounds = count_sounds();
  54.             load_sounds();
  55.           //  llSetTimerEvent((num_sounds * sound_length)-(num_sounds * slow_server_adjustment));
  56.           //  llWhisper(0,"/me • Playing.");
  57.        
  58.          if (loop_sounds() == TRUE)
  59.          {
  60.           return TRUE;  
  61.         }
  62.        
  63.         else
  64.         { return FALSE;}
  65. }
  66.  
  67. string help = "• Help / Usage •
  68. 1. Load sounds into the prim that has this script inside.
  69. 2. Open the script and find the \"sound_length\" value.
  70. 3. Change that value to match how your sound clips are.
  71. 4. Touch the object, wait for the sounds to preload.. Done!
  72.  
  73. Note: Uncomment the line in the touch_event to make it \"owner only\".";
  74.  
  75. default{
  76. //
  77.    
  78. //
  79.     changed(integer c){
  80.  
  81. if(c & CHANGED_OWNER){
  82.             llWhisper(0,"/me "+help);
  83.             llResetScript();
  84.         }
  85.        
  86.          
  87.      else if(c & CHANGED_REGION_START)
  88.      {
  89.      
  90.        llResetScript();    
  91.          
  92.      }
  93.     }
  94. //
  95.    
  96.    
  97.    
  98.    
  99.     //on_rez(integer num_detected){
  100.     collision_start(integer total_number)
  101.     {
  102.      
  103.        
  104.        
  105.          
  106.          state play_sound;
  107.            
  108.        
  109.     }
  110. //
  111.     timer(){
  112.         loop_sounds();
  113.     }
  114.    
  115.    
  116. //
  117. }
  118.  
  119.  
  120. state play_sound
  121. {
  122.    
  123.     state_entry()
  124.     {
  125.        
  126.         if(Play() == TRUE)
  127.         state default;
  128.        
  129.     }
  130.    
  131.    
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement