// Link Color Changer (except link 5)
// This script changes the color of a linkset, but leaves one unchanged
// 8/31/05 by Numa Herbst
// this script dedicated to Bunny

// Let's set up the variables that we will use
integer chan = 0; // the channel to listen for commands (0 is chat)
integer link = ALL_SIDES; // llSetLinkColor() can set the color of a particular side, but we want all sides changed
vector color; // this variable contains the color values that the procedure colorChange() will use

// Let's make some code called a 'procedure' that lets us change the color
// of links 1-4, but not 5
// A procedure is like a little program within a program, and it keeps the programmer
// from having to type out the same code over and over again (makes it faster and use less memory)
colorChange()
{
//llWhisper(0, "DEBUG: " + (string) color); // For testing purposes, whispers the color vector that links 1-4 will be set
llSetLinkColor(1, color, ALL_SIDES); // Change link #1, the root (or parent) prim
llSetLinkColor(2, color, ALL_SIDES); // Change link #2
//llSetLinkColor(3, color, ALL_SIDES); // Change link #3
//llSetLinkColor(4, color, ALL_SIDES); // Change link #4
}

// This is where the actual program starts, hang on tight!
default
{

// In *any* script that is tied to an owner, this has to be used.
// Emrah's wing script didn't have this part, so his clients weren't
// accurately identified as the proper owner of the script. Because
// of that, the wings wouldn't listen lol...
on_rez(integer i)
{
llResetScript(); // Reset the script to blow out any 'junk'
}

// This bit of code is run whenever a state change happens (like right after
// rezzing)
state_entry()
{
llListen(chan, "", llGetOwner(), ""); // Sets up a listener on channel 'chan'
llWhisper(0, " Say 'help' for details"); // Whispers a helpful hint
llSetTouchText("Random"); // Sets the text seen in the pie menu for 'touch'
}

// This bit of code happens when the listener hears something
listen (integer channel, string name, key id, string message)
{
if (id == llGetOwner()) // Are you the owner? if not, then don't run all this code below
{

if (message == "help") // Did the owner ask for help? if so, whisper the instructions
{
llWhisper(0, " This fashion accessory changes colors based on the owner's input.");
llWhisper(0, " Color can be changed by saying 'color {colorname}' in chat.");
llWhisper(0, " Available colors are:");
llWhisper(0, " Black, white, light grey, grey, dark grey, red, bright red, dark red,");
llWhisper(0, " Pink, bright pink, dark pink, orange, bright orange, dark orange, yellow,");
llWhisper(0, " Bright yellow, dark yellow, green, bright green, dark green, mint green,");
llWhisper(0, " Blue, bright blue, dark blue, and light blue.");
}

if (message == "color random") // Did the owner ask for a random color?
{
color = <llFrand(1),llFrand(1),llFrand(1)>; // Make a random color based on random Red, Green, and Blue values
colorChange(); // Go to the procedure 'colorChange()' to change the colors of links 1-4
llWhisper(0, " Color randomized, say again if this is putrid (which it probably will be.");
}

if (message == "color white") // Did the owner ask for a specific color?
{
color = <1, 1, 1>; // Set the variable 'color' to wide open (all white)
colorChange(); // Go to the procedure 'colorChange()' to change the colors of links 1-4
}
if (message == "color light grey") // Lather. Rinse. Repeat.
{
color = <0.66, 0.66, 0.66>;
colorChange();
}
if (message == "color grey")
{
color = <0.5, 0.5, 0.5>;
colorChange();
}
if (message == "color dark grey")
{
color = <0.33, 0.33, 0.33>;
colorChange();
}
if (message == "color black")
{
color = <0.0, 0.0, 0.0>;
colorChange();
}

if (message == "color red")
{
color = <0.66, 0.0, 0.0>;
colorChange();
}
if (message == "color bright red")
{
color = <1.0, 0.0, 0.0>;
colorChange();
}
if (message == "color dark red")
{
color = <0.33, 0.0, 0.0>;
colorChange();
}
if (message == "color pink")
{
color = <1.0, 0.5, 0.5>;
colorChange();
}
if (message == "color dark pink")
{
color = <1.0, 0.33, 0.33>;
colorChange();
}
if (message == "color bright pink")
{
color = <1.0, 0.66, 0.66>;
colorChange();
}
if (message == "color bright orange")
{
color = <1.0, 0.66, 0.0>;
colorChange();
}
if (message == "color orange")
{
color = <1.0, 0.5, 0.0>;
colorChange();
}
if (message == "color dark orange")
{
color = <1.0, 0.33, 0.0>;
colorChange();
}
if (message == "color bright yellow")
{
color = <1.0, 1.0, 0.0>;
colorChange();
}
if (message == "color yellow")
{
color = <0.75, 0.75, 0.0>;
colorChange();
}
if (message == "color dark yellow")
{
color = <0.5, 0.5, 0.0>;
colorChange();
}

if (message == "color bright green")
{
color = <0.0, 1.0, 0.0>;
colorChange();
}
if (message == "color green")
{
color = <0.0, 0.66, 0.0>;
colorChange();
}
if (message == "color dark green")
{
color = <0.0, 0.5, 0.0>;
colorChange();
}
if (message == "color mint green")
{
color = <0.5, 0.5, 1.0>;
colorChange();
}
if (message == "color blue")
{
color = <0.0, 0.0, 0.66>;
colorChange();
}
if (message == "color bright blue")
{
color = <0.0, 0.0, 1.0>;
colorChange();
}
if (message == "color dark blue")
{
color = <0.0, 0.0, 0.5>;
colorChange();
}
if (message == "color light blue")
{
color = <0.5, 0.5, 1.0>;
colorChange();
}
}
}

// This code is run anytime someone touches the item (not just the link holding the script, but the whole linkset
// This is pretty much the same code as the 'color random' listener code, it does the same thing except
// when someone touches it
touch(integer num_detected)
{
color = <llFrand(1), llFrand(1), llFrand(1)>;
colorChange();
llSleep(1);
llWhisper(0, " Color randomized, touch again if you want another color.");
}
}