Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - string notecard;
 - integer line;
 - key query;
 - list sounds = [];
 - integer sound = 0;
 - integer length = 0;
 - integer shuffle = 0;
 - float delay = 0;
 - float volume = 1;
 - play()
 - {
 - // Sound variable is incremented immediately after evaluation.
 - llPlaySound(llList2String(sounds,sound++), volume);
 - // llOwnerSay("Sound Nr: "+(string)sound +" Delay: "+ (string)delay);
 - // Prevent overflow, and start over.
 - if(sound > length -1){
 - if(shuffle == 1){
 - llOwnerSay("Pausing then loading next");
 - llSetTimerEvent(0); //Stop loop
 - llSleep(delay-0.01); //Wait till current sound is played
 - random_notecard(); // play next
 - }
 - else{
 - sound = 0; //loop song
 - // Preload is limited by distance and is somewhat unreliable.
 - llPreloadSound(llList2String(sounds,sound));
 - }
 - } else {
 - // Preload is limited by distance and is somewhat unreliable.
 - // llOwnerSay("Preloading next");
 - llPreloadSound(llList2String(sounds,sound));
 - }
 - }
 - clear()
 - {
 - llSetText("", <1,1,1>, 1);
 - llSetTimerEvent(0);
 - llStopSound();
 - sounds = [];
 - sound = 0;
 - length = 0;
 - shuffle = 0;
 - line = 0;
 - }
 - random_notecard(){
 - // Local variable exists only for ownersay debugging purposes.
 - clear(); integer x = llFloor(llFrand(llGetInventoryNumber(7)));
 - shuffle = 1;
 - notecard = llGetInventoryName(7,x);
 - query = llGetNotecardLine(notecard, line);
 - llOwnerSay("Loading: "+ notecard +" ("+ (string)x +")"); // debug
 - }
 - default
 - {
 - state_entry()
 - {
 - clear(); llListen(1, "", llGetOwner(), "");
 - 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");
 - // Allows up to 2 sounds be queued for play.
 - // (current and ONE awaiting to be played)
 - // Prevents skipping when llPlaySound is used
 - // before the currently playing sound has ended.
 - // The next sound will always be kept queued.
 - // edit: Setting this to TRUE is actually gay
 - llSetSoundQueueing(FALSE);
 - }
 - dataserver(key current_query, string data)
 - {
 - if(current_query == query) {
 - if(data != EOF) {
 - if(line) sounds += [data]; // string
 - else delay = (float)data; // float
 - ++line; query = llGetNotecardLine(notecard, line);
 - }
 - else {
 - //Preload Sounds
 - // llOwnerSay("Preload Sound: "+(string) sound);
 - llPreloadSound(llList2String(sounds,sound));
 - length = llGetListLength(sounds);
 - // timer is less than the sound clip to ensure no silent gaps.
 - // Sound queueing will prevent skipping for (UUID count * 100) plays.
 - llSetTimerEvent(delay - 0.01);
 - llSetText(notecard, <1,1,1>, 1);
 - play();
 - }
 - }
 - }
 - listen(integer c, string n, key id, string m)
 - {
 - if(llGetSubString(m, 0, 4) == "song.") {
 - string x = llGetSubString(m, 5,-1);
 - if(llGetInventoryType(x) == 7) {
 - clear();
 - notecard = x;
 - query = llGetNotecardLine(notecard, line);
 - llOwnerSay("Loading.");
 - }
 - else llOwnerSay("Invalid name.");
 - }
 - if(m == "shuffle") {
 - random_notecard();
 - }
 - if(llGetSubString(m, 0,6) == "volume.") {
 - volume = (float)llGetSubString(m, 7,-1)/100;
 - // GetSubString used to truncate the trailing zeroes from float.
 - // Someone will complain, but performance is not critical nor heavy here.
 - llOwnerSay("Volume: "+ llGetSubString((string)(volume*100),0,-8) +"%");
 - }
 - if(m == "stop") {
 - clear();
 - }
 - }
 - timer()
 - {
 - play();
 - }
 - on_rez(integer param)
 - {
 - clear();
 - }
 - changed(integer change)
 - {
 - if(change & CHANGED_OWNER) llResetScript();
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment