This is designed for my own personal use, but I set it up so that another user could easily add their own stations and use it on their parcel (at least I hope I set it up that way
)It could probably use a lot of optimization, but as it's one of my first scripting attempts, I'll just be happy if it works.
I've always been very comment happy in my code (again, bad memory).
CODE
//Creating global variables, station URLs which can be set by owner in script.
string StrStation01;
string StrStation02;
string StrStation03;
string StrStation04;
string StrStation05;
string StrStation06;
//This script lets the user say 'radio #' to change the Parcel Music URL
//for a piece of land they own. This allows the owner to quickly switch
//between saved stations for their parcel without requiring them to open
//the UI and manually enter a new station URL each time they change music.
default {
state_entry()
{
//Turn the radio off when the tuner is rezzed--just in case it was left
//playing from a previous setting or previous copy of the tuner.
llSetParcelMusicURL("");
//Load the stations entered by the user in SetStations for tuning.
SetStations;
//When the owner speaks the word radio # on channel 1, switch the radio
//station being streamed by the parcel to a saved radio preset matching
//that number. Only the parcel's owner may do this.
llListen(1, "", llGetOwner(), "");
}
//This listens for input on channel 1 from the owner and changes the
//radio station when the user says "radio #" with # being the number
//of the station to which the parcel should change.
//
//Radio station URLs are stored in the function SetStations which is
//fired when the tuner is first rezzed. This way the owner may change
//all station presets in one area of the script.
listen ( integer channel, string name, key id, string message )
{
if (message == "radio off")
{
llSetParcelMusicURL("");
llWhisper("Your radio is now off.");
}
if (message == "radio 1")
{
llSetParcelMusicURL(StrStation01);
llWhisper("You are now listening to Station 1.");
}
if (message == "radio 2")
{
llSetParcelMusicURL(StrStation02);
llWhisper("You are now listening to Station 2.");
}
if (message == "radio 3")
{
llSetParcelMusicURL(StrStation03);
llWhisper("You are now listening to Station 3.");
}
if (message == "radio 4")
{
llSetParcelMusicURL(StrStation04);
llWhisper("You are now listening to Station 4.");
}
if (message == "radio 5")
{
llSetParcelMusicURL(StrStation05);
llWhisper("You are now listening to Station 5.");
}
if (message == "radio 6")
{
llSetParcelMusicURL(StrStation06);
llWhisper("You are now listening to Station 6.");
}
}
//Tuner explains to owner how to switch stations if owner touches it.
touch_start()
{
if ( llDetectedKey(0) == llGetOwner() )
{
llOwnerSay("Say radio 1, radio 2, etc on channel 1 to listen to that station. Channels available are 1-6. To turn the radio off, say radio off on channel 1.");
}
}
}
//---------------------------------------------------------------------------
//Initialize URLs for all available stations. This is the only section of
//the code an owner needs to change. Replace the station URL (in quotes) with
//the URL of the station you would like on that channel.
//---------------------------------------------------------------------------
SetStations () {
StrStation01=("http://www.shoutcast.com/");
StrStation02=("http://www.shoutcast.com/");
StrStation03=("http://www.shoutcast.com/");
StrStation04=("http://www.shoutcast.com/");
StrStation05=("http://www.shoutcast.com/");
StrStation06=("http://www.shoutcast.com/");
llOwnerSay("Radio Tuner Initialized.");
}
Any comments and suggestions for improvement are welcome. Note that I haven't actually tested this script in game, so it could contain errors (I plan to test tonight).
