Advertisement
Guest User

notecard player script

a guest
Jul 20th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. string notecard;
  2. integer line;
  3. key query;
  4.  
  5. list sounds = [];
  6. integer sound = 0;
  7. integer length = 0;
  8. integer shuffle = 0;
  9. float delay = 0;
  10. float volume = 1;
  11.  
  12. play()
  13. {
  14. // Sound variable is incremented immediately after evaluation.
  15. llPlaySound(llList2String(sounds,sound++), volume);
  16. // llOwnerSay("Sound Nr: "+(string)sound +" Delay: "+ (string)delay);
  17. // Prevent overflow, and start over.
  18. if(sound > length -1){
  19. if(shuffle == 1){
  20. llOwnerSay("Pausing then loading next");
  21. llSetTimerEvent(0); //Stop loop
  22. llSleep(delay-0.01); //Wait till current sound is played
  23. random_notecard(); // play next
  24. }
  25. else{
  26. sound = 0; //loop song
  27. // Preload is limited by distance and is somewhat unreliable.
  28. llPreloadSound(llList2String(sounds,sound));
  29. }
  30.  
  31. } else {
  32. // Preload is limited by distance and is somewhat unreliable.
  33. // llOwnerSay("Preloading next");
  34. llPreloadSound(llList2String(sounds,sound));
  35. }
  36.  
  37. }
  38.  
  39. clear()
  40. {
  41. llSetText("", <1,1,1>, 1);
  42. llSetTimerEvent(0);
  43. llStopSound();
  44. sounds = [];
  45. sound = 0;
  46. length = 0;
  47. shuffle = 0;
  48. line = 0;
  49. }
  50.  
  51. random_notecard(){
  52. // Local variable exists only for ownersay debugging purposes.
  53. clear(); integer x = llFloor(llFrand(llGetInventoryNumber(7)));
  54. shuffle = 1;
  55. notecard = llGetInventoryName(7,x);
  56. query = llGetNotecardLine(notecard, line);
  57. llOwnerSay("Loading: "+ notecard +" ("+ (string)x +")"); // debug
  58. }
  59.  
  60. default
  61. {
  62. state_entry()
  63. {
  64. clear(); llListen(1, "", llGetOwner(), "");
  65. llOwnerSay("Type '/1 song.NAME' to loop a song, '/1 shuffle' to randomly play songs, '/1 stop' to stop and '/1 volume' to set volume");
  66. // Allows up to 2 sounds be queued for play.
  67. // (current and ONE awaiting to be played)
  68. // Prevents skipping when llPlaySound is used
  69. // before the currently playing sound has ended.
  70. // The next sound will always be kept queued.
  71. // edit: Setting this to TRUE is actually gay
  72. llSetSoundQueueing(FALSE);
  73. }
  74.  
  75. dataserver(key current_query, string data)
  76. {
  77. if(current_query == query) {
  78.  
  79. if(data != EOF) {
  80. if(line) sounds += [data]; // string
  81. else delay = (float)data; // float
  82. ++line; query = llGetNotecardLine(notecard, line);
  83. }
  84. else {
  85. //Preload Sounds
  86. // llOwnerSay("Preload Sound: "+(string) sound);
  87. llPreloadSound(llList2String(sounds,sound));
  88. length = llGetListLength(sounds);
  89. // timer is less than the sound clip to ensure no silent gaps.
  90. // Sound queueing will prevent skipping for (UUID count * 100) plays.
  91. llSetTimerEvent(delay - 0.01);
  92. llSetText(notecard, <1,1,1>, 1);
  93. play();
  94. }
  95.  
  96. }
  97. }
  98.  
  99. listen(integer c, string n, key id, string m)
  100. {
  101. if(llGetSubString(m, 0, 4) == "song.") {
  102. string x = llGetSubString(m, 5,-1);
  103. if(llGetInventoryType(x) == 7) {
  104. clear();
  105. notecard = x;
  106. query = llGetNotecardLine(notecard, line);
  107. llOwnerSay("Loading.");
  108. }
  109. else llOwnerSay("Invalid name.");
  110. }
  111.  
  112. if(m == "shuffle") {
  113.  
  114. random_notecard();
  115. }
  116.  
  117. if(llGetSubString(m, 0,6) == "volume.") {
  118. volume = (float)llGetSubString(m, 7,-1)/100;
  119. // GetSubString used to truncate the trailing zeroes from float.
  120. // Someone will complain, but performance is not critical nor heavy here.
  121. llOwnerSay("Volume: "+ llGetSubString((string)(volume*100),0,-8) +"%");
  122. }
  123.  
  124. if(m == "stop") {
  125. clear();
  126. }
  127. }
  128.  
  129. timer()
  130. {
  131. play();
  132. }
  133.  
  134. on_rez(integer param)
  135. {
  136. clear();
  137. }
  138.  
  139. changed(integer change)
  140. {
  141. if(change & CHANGED_OWNER) llResetScript();
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement