Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Opengrid - Parcel Audio System
#1
Music 
Script For Opengrid testing osgrid

:cool:

Code:
// BAS PmP
// last modified 11 December 2010

// written by Cookie Bertone
// this script is PUBLIC DOMAIN

// if instructions are renamed make change in this script also!!

// Ported to Opensim by Oddball Otoole
// Removed the update option.
string version = "1.65"; // Version number of this item

string gName = "channels"; // name of the notecard that holds the channel list
integer gLine = 0; // current line number, set to 0 so it starts at the beginning
key gQueryID; // id used to identify dataserver queries
list GenreElementList = [];
integer populating_list = TRUE;
string nPlaying = "Unknown";
integer FloatText = TRUE;

// start 1.5 extras

list trackpulllist = [];
float gap = 5.0;
float counter = 0.0;
string nPlayingURL = "http://";
string TrackElementHold = "";
integer nPlayingSHOW = TRUE;

// end 1.5 extras

// start 1.6 extras

key gkOwner;
key serverID = "70245bf0-1f2f-40d5-abde-8235ea4f47b3";
integer InstalledTextures = 0;

// end 1.6 extras

key menuitem; // id used to get menu selection
list MainMenu = ["tuner", "options", "off"];
list OptionsMenu = ["texton", "textoff", "playing", "list", "reset", "-", "main menu"];
string tuner_dialog = "\nParcel Music Player\n\nMake a selection or press 'ignore' to close this dialog box.";
string chatline = "------------------------------------------------------";

list first_menu;
list second_menu;
list third_menu;
list fourth_menu;
list fifth_menu;
list sixth_menu;
list seventh_menu;
list eigth_menu;
list ninth_menu;
string lastpage = "Page 9";

default
{
    // when device is first rezzed it will reset the script
    on_rez(integer start_param)
    {
        llSay(0, "Player installed. Setting defaults.");
        llResetScript();
        llSay(0, "Defaults set.");
    }
    
    // when script is started or restarted it will display some details about the device,
    // tell it to read the data file, start the listen and set the text on the device
    state_entry()
    {
        llSetLinkColor(2, <0.0, 0.9, 0.0>, ALL_SIDES);
        llSay(978, "reset");
        llSay(0, "\n\n" +chatline+ "\n(Parcel Music Player) " +version+ "\nScript written by Cookie Bertone\n" +chatline+ "\nBrought to Opensim by\n Oddball Otoole\nLoading channels.\nPlease wait for 'Ready'.\n\n");
        llSetParcelMusicURL("");
        gQueryID = llGetNotecardLine(gName, gLine); // request first line
        llListen(97, "", NULL_KEY, ""); // listen for request on channel 97
        llSetText("Parcel Audio System " +version, <0.0,1.0,1.0>, .5);
        llSetTimerEvent(gap); // Activate the timer listener every X seconds
    }
    
    // when the device is touched it will display the main menu
    touch_start(integer touchNumber)
    {
        llDialog(llDetectedKey(0), tuner_dialog, MainMenu, 97);
    }
  
    listen(integer channel, string name, key id, string message)
    {
        integer index = llListFindList(GenreElementList, [message]);

        if (index != -1)
        {
            llSay(0, "Found "+message+" in channel list. Setting channel.");
            llSetLinkColor(2, <0.0, 0.9, 0.0>, ALL_SIDES);
            gQueryID = llGetNotecardLine(gName, index);
        }
        else if (message=="list")
        {
            llSay(0, "Listing possible genres:");
            integer x;
            integer length=llGetListLength(GenreElementList);
            for (x=0; x<length; x++)
            {
                llSay(0,llList2String(GenreElementList,x));
            }
        }
        else if (message=="playing")
        {
            llSay(0, "Now playing: "+nPlaying);
        }
        else if (message=="texton")
        {
            FloatText = TRUE;
            nPlayingSHOW = TRUE;
            llSetText("Now playing: "+nPlaying+".", <0.0,1.0,1.0>, .5);
        }
        else if (message=="textoff")
        {
            FloatText = FALSE;
            nPlayingSHOW = FALSE;
            llSetText(" ", <0.0,1.0,1.0>, .5);
        }
        else if (message=="XXpictureXX")
        {
            integer InstalledTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
            if (InstalledTextures == 1)
            {
                string TextureName = llGetInventoryName(INVENTORY_TEXTURE, 0);
                llSay (0,"Texture found: " +TextureName);
                if (name != "")
                    llSetTexture(TextureName, 5);
            }
            if (InstalledTextures > 1)
            {
                float RandTexture = llFrand(InstalledTextures);
                integer TextureChoice = (integer)RandTexture;
                string TextureName = llGetInventoryName(INVENTORY_TEXTURE, TextureChoice);
                llSay (0,"Choosing a random texture: "+TextureName);
                if (name != "")
                    llSetTexture(TextureName, 5);
            }
            if (InstalledTextures < 1)
            {
                llSay(0,"There are no textures installed.");
            }
        }
             else if (message=="reset")
        {
            llSay(0, "Resetting.");
            llResetScript();
        }
        else if (message=="options")
        {
            llDialog(id, tuner_dialog, OptionsMenu, 97);
        }
   //     else if (message=="update")
   //     {
   //         llOwnerSay("Contacting update server.");
   //         llEmail(serverID,"Update Request",llGetObjectName() + ":" + version + "|" + (string)llGetOwner());
   //     }
        else if (message=="off")
        {
            llSay(0, "System Off");
            llSetLinkColor(2, <1.0, 0.0, 0.0>, ALL_SIDES);
            llSay(978, "red");
            llSetParcelMusicURL("");
            //next two lines new for v1.5, these reset variables to stop it displaying track names when switched off
            nPlayingURL = "http://";
            TrackElementHold = "";
            if (FloatText = TRUE)
            {
                llSetText("Parcel Audio System " +version+ " OFF", <0.0,1.0,1.0>, .5);
            }
        }
        else if (message=="tuner")
        {
            if(llGetListLength(GenreElementList) > 80)
            {
                llSay(0, "Only the first 80 channels will be displayed in the menu.");
            }
            if(llGetListLength(GenreElementList) > 12)
            {
                // remember that a list starts at 0, not 1
                // all the menus except the first one are set here so the following if statements can change them if necessary
                second_menu = ["Page 1", "main menu", "Page 3"] + llList2List(GenreElementList, 9, 17);
                third_menu = ["Page 2", "main menu", "Page 4"] + llList2List(GenreElementList, 18, 26);
                fourth_menu = ["Page 3", "main menu", "Page 5"] + llList2List(GenreElementList, 27, 35);
                fifth_menu = ["Page 4", "main menu", "Page 6"] + llList2List(GenreElementList, 36, 44);
                sixth_menu = ["Page 5", "main menu", "Page 7"] + llList2List(GenreElementList, 45, 53);
                seventh_menu = ["Page 6", "main menu", "Page 8"] + llList2List(GenreElementList, 54, 62);
                eigth_menu = ["Page 7", "main menu", "Page 9"] + llList2List(GenreElementList, 63, 71);
                ninth_menu = ["Page 8", "main menu", "Page 1"] + llList2List(GenreElementList, 72, 80);

                // this bit sets which page will be the last so no empty menus are displayed
                if(llGetListLength(GenreElementList) < 81)
                {
                    ninth_menu = ["Page 8", "main menu", "Page 1"] + llList2List(GenreElementList, 72, 80);
                    lastpage = "Page 9";
                }
                if(llGetListLength(GenreElementList) < 72)
                {
                    eigth_menu = ["Page 7", "main menu", "Page 1"] + llList2List(GenreElementList, 63, 71);
                    lastpage = "Page 8";
                }
                if(llGetListLength(GenreElementList) < 63)
                {
                    seventh_menu = ["Page 6", "main menu", "Page 1"] + llList2List(GenreElementList, 54, 62);
                    lastpage = "Page 7";
                }
                if(llGetListLength(GenreElementList) < 54)
                {
                    sixth_menu = ["Page 5", "main menu", "Page 1"] + llList2List(GenreElementList, 45, 53);
                    lastpage = "Page 6";
                }
                if(llGetListLength(GenreElementList) < 45)
                {
                    fifth_menu = ["Page 4", "main menu", "Page 1"] + llList2List(GenreElementList, 36, 44);
                    lastpage = "Page 5";
                }
                if(llGetListLength(GenreElementList) < 36)
                {
                    fourth_menu = ["Page 3", "main menu", "Page 1"] + llList2List(GenreElementList, 27, 35);
                    lastpage = "Page 4";
                }
                if(llGetListLength(GenreElementList) < 27)
                {
                    third_menu = ["Page 2", "main menu", "Page 1"] + llList2List(GenreElementList, 18, 26);
                    lastpage = "Page 3";
                }
                if(llGetListLength(GenreElementList) < 18)
                {
                    second_menu = ["Page 1", "main menu", "Page 1"] + llList2List(GenreElementList, 9, 17);
                    lastpage = "Page 2";
                }

                // the first menu is set here 'after' the last page has been defined (above) then the first dialog is displayed
                first_menu = [lastpage, "main menu", "Page 2"] + llList2List(GenreElementList, 0, 8);
                llDialog(id, tuner_dialog, first_menu, 97);
            }
            else
            {
                // if there are less than 12 items in the menu it displays this dialog that doesn't need the page buttons
                llDialog(id, tuner_dialog, GenreElementList, 97);
            }
        }
        else if(message=="Page 1")
        {
            llDialog(id, tuner_dialog, first_menu, 97);
        }
        else if(message=="Page 2")
        {
            llDialog(id, tuner_dialog, second_menu, 97);
        }
        else if(message=="Page 3")
        {
            llDialog(id, tuner_dialog, third_menu, 97);
        }
        else if(message=="Page 4")
        {
            llDialog(id, tuner_dialog, fourth_menu, 97);
        }
        else if(message=="Page 5")
        {
            llDialog(id, tuner_dialog, fifth_menu, 97);
        }
        else if(message=="Page 6")
        {
            llDialog(id, tuner_dialog, sixth_menu, 97);
        }
        else if(message=="Page 7")
        {
            llDialog(id, tuner_dialog, seventh_menu, 97);
        }
        else if(message=="Page 8")
        {
            llDialog(id, tuner_dialog, eigth_menu, 97);
        }
        else if(message=="Page 9")
        {
            llDialog(id, tuner_dialog, ninth_menu, 97);
        }
        else if(message=="main menu")
        {
            llDialog(id, tuner_dialog, MainMenu, 97);
        }
        else
        {
            llSay(0, "Sorry. I couldn't find a station or command with the ID: "+message);
        }
    }

// timer section is new for version 1.5

    timer()
    {
        //llHTTPRequest(nPlayingURL+"/7.html HTTP/1.0\nUser-Agent: XML Getter (Mozilla Compatible)\n\n",[],"");
        llHTTPRequest(nPlayingURL+"/7.html HTTP/1.1\nUser-Agent:Mozilla\n\n",[],"");
        
    }

// http_response section is new for version 1.5    
        
    http_response(key trackid, integer status, list metadata, string trackbody)
    {
        list TrackPullList = llParseString2List(trackbody,[","],[]); // takes the http result and turns it into a list
        string TrackElement = llList2String(TrackPullList,6); // takes the sixth item out of the http result list
        
        TrackElement = llDeleteSubString(TrackElement, -14, -1); // strips off the html junk text at the end

        if (nPlayingSHOW == TRUE)
        {
            if (TrackElementHold != TrackElement)
            {
                llSay(0, "Now playing: " + TrackElement + "."); // displays the result
                TrackElementHold = TrackElement;
            }
        }
    }

    dataserver(key query_id, string data)
    {
        if (populating_list == TRUE) // first pass through is to build up a list of Genre Names
        {
            if (data != EOF)
            {
                list StationList = llParseString2List(data,[","],[]);
                string GenreElement = llList2String(StationList,2);
                GenreElementList = GenreElementList + [llList2String(StationList,2)];
                ++gLine; // increase line count by 1
                gQueryID = llGetNotecardLine(gName, gLine); // request next line
            }
            else
            {
                populating_list = FALSE;
                llSetLinkColor(2, <1.0, 0.0, 0.0>, ALL_SIDES);
                llSay(0, "\n\nReady.\nTouch player to begin...\n\n");
            }
        }
        else
        {
            list StationList = llParseString2List(data,[","],[]); // converts the line taken into a list
            string URLElement = llList2String(StationList,0); // grab the URL
            llSetParcelMusicURL(URLElement);
            llSetLinkColor(2, <0.9, 0.9, 0.9>, ALL_SIDES);
            llSay(978, "blue");
            string StationElement = llList2String(StationList,1);
            llSay(0, "Now playing: "+StationElement+" ("+URLElement+").");
            if (FloatText == TRUE)
            {
                //llSay(0,"DIAGNOSTIC: FloatText is true");
                llSetText("Now playing: "+StationElement+".", <0.0,1.0,1.0>, .5);
            }
            nPlaying = StationElement; // this holds the station name for use in other sections
            nPlayingURL = URLElement; // this holds the station URL for use in other sections
        }
    }
}
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  script Opengrid - avatar key and name speaker trainz 1 1,200 12-14-2011, 05:21 AM
Last Post: Anarchist_Labs
Photo Script Opensim - Texture Carte Map trainz 1 1,225 12-14-2011, 05:18 AM
Last Post: Anarchist_Labs
Star Script OPENGRID - Paticle Fire Orange trainz 1 1,459 11-12-2011, 04:04 AM
Last Post: LordJames
  Script Opensim - Texture UUID trainz 0 1,081 11-05-2011, 08:59 PM
Last Post: trainz
Brick Script opengrid - sim info trainz 0 1,054 11-05-2011, 08:31 PM
Last Post: trainz



Users browsing this thread: 1 Guest(s)