Advertisement
Gayngel

Music Box Play Once On Touch Script

Aug 30th, 2021
3,209
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. 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.         Play();
  70.     }
  71. //
  72.     changed(integer c){
  73.  
  74. if(c & CHANGED_OWNER){
  75.             llWhisper(0,"/me "+help);
  76.             llResetScript();
  77.         }
  78.        
  79.          
  80.      else if(c & CHANGED_REGION_START)
  81.      {
  82.      
  83.        llResetScript();    
  84.          
  85.      }
  86.     }
  87. //
  88.    
  89.    
  90.    
  91.    
  92.     //on_rez(integer num_detected){
  93.     touch_start(integer total_number){
  94.         if(llDetectedKey(0) != llGetOwner())return;//uncomment for owner only
  95.         active =! active;
  96.         if(active){
  97.        
  98.             Play();
  99.         }else{
  100.             llSetTimerEvent(0.0);
  101.             llWhisper(0,"/me • Stopped.");
  102.         }
  103.     }
  104. //
  105.     timer(){
  106.         loop_sounds();
  107.     }
  108.    
  109.    
  110. //
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement