Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help! I NEED A COLOR CHANGE SCRIPT ASAP!

Camie Cooper
loves you!
Join date: 20 Nov 2004
Posts: 737
03-02-2005 11:20
I have not messed with scripts unless they were given to me, so I dont know where to find somthing i need oh so badly, i also dont do forums that often so dont kill me if this is posted in the wrong place, anyway I am looking for a color change script, for some shoes I made, If you have one I can purchace or know where I can get one, please lemme know here or in game :) thanks so much...


<3 Camie :)
Chrischun Fassbinder
k-rad!
Join date: 19 Feb 2005
Posts: 154
03-02-2005 15:21
Sorry Camie, think you best get a better example from someone else.

(reply to below) Cross, you're right they do. I was using strings for the initial variable type then typecasting them as integers to x,y,z in the vector which works up to a value of 100. Doing that while thinking before checking that things worked as RGB for colors. Glad I learned it's easy as just using float types. That along with my inability to check if this worked for a linked multi-prim object, which it doesn't, makes me realize I shouldn't have posted the script to begin with. Back to reading and writting basic scripts for me.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
03-02-2005 16:51
We can specify colours in RGB now? I thought colour vector components had to be floats in the range of 0.0 -> 1.0.
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
03-02-2005 18:43
I only tested this a little so let me know if anything seems screwy.

Usage:
/1color #RRGGB
Set color by hex code.
Example: /1color #00ccff

/1color <R,G,B>
Set color by vector. Can be 0.0 - 1.0 or 0 - 255. Only the opening bracket really matters. Note that <1,1,1> will be treated as white (#ffffff), not almost black (#010101).
Example: /1color < 255 128 192

/1color name
Set color by name. Spaces and capitalization don't matter.
Example: /1color Carnation Pink

/1listcolors
List known color names. (slow)

CODE
// This code is public domain.
// masa was here 20050302

integer CHANNEL = 1; // channel to listen for commands on
integer OWNER_ONLY = TRUE; // only owner can control
integer USE_IMS = TRUE; // send IMs instead of using chat
string COMMAND_CHANGE_COLOR = "color"; // command to change color
string COMMAND_LIST_COLORS = "listcolors"; // command to list colors
integer MAX_CHAT_LENGTH = 255; // max size for one message
string PREFIX_HEX = "#"; // prefix to specify hex code
string PREFIX_VECTOR = "<"; // prefix to specify vector code
list LINKS_TO_SET = [LINK_SET, ALL_SIDES]; // [link number, link face, ...]

list COLORS;

// the list is too big to set at once :o
// note that you may get syntax errors and need to rearrange this list
// if you change the script much.
set_colors() {
COLORS = [
// http://halflife.ukrpack.net/csfiles/help/colors.shtml
"steelblue", "#4682B4", "royalblue", "#041690", "cornflowerblue", "#6495ED",
"lightsteelblue", "#B0C4DE", "mediumslateblue", "#7B68EE", "slateblue", "#6A5ACD",
"darkslateblue", "#483D8B", "midnightblue", "#191970", "navy", "#000080",
"darkblue", "#00008B", "mediumblue", "#0000CD", "blue", "#0000FF",
"dodgerblue", "#1E90FF", "deepskyblue", "#00BFFF", "lightskyblue", "#87CEFA",
"skyblue", "#87CEEB", "lightblue", "#ADD8E6", "powderblue", "#B0E0E6",
"azure", "#F0FFFF", "lightcyan", "#E0FFFF", "paleturquoise", "#AFEEEE",
"mediumturquoise", "#48D1CC", "lightseagreen", "#20B2AA", "darkcyan", "#008B8B",
"teal", "#008080", "cadetblue", "#5F9EA0", "darkturquoise", "#00CED1",
"aqua", "#00FFFF", "cyan", "#00FFFF", "turquoise", "#40E0D0",
"aquamarine", "#7FFFD4", "mediumaquamarine", "#66CDAA", "darkseagreen", "#8FBC8F"
] + [
"mediumseagreen", "#3CB371", "seagreen", "#2E8B57", "darkgreen", "#006400",
"green", "#008000", "forestgreen", "#228B22", "limegreen", "#32CD32",
"lime", "#00FF00", "chartreuse", "#7FFF00", "lawngreen", "#7CFC00",
"greenyellow", "#ADFF2F", "yellowgreen", "#9ACD32", "palegreen", "#98FB98",
"lightgreen", "#90EE90", "springgreen", "#00FF7F", "mediumspringgreen", "#00FA9A",
"darkolivegreen", "#556B2F", "olivedrab", "#6B8E23", "olive", "#808000",
"darkkhaki", "#BDB76B", "darkgoldenrod", "#B8860B", "goldenrod", "#DAA520",
"gold", "#FFD700", "yellow", "#FFFF00", "khaki", "#F0E68C", "palegoldenrod", "#EEE8AA",
"blanchedalmond", "#FFEBCD", "moccasin", "#FFE4B5", "wheat", "#F5DEB3",
"navajowhite", "#FFDEAD", "burlywood", "#DEB887", "tan", "#D2B48C"
] + [
"rosybrown", "#BC8F8F", "sienna", "#A0522D", "saddlebrown", "#8B4513",
"chocolate", "#D2691E", "peru", "#CD853F", "sandybrown", "#F4A460",
"darkred", "#8B0000", "maroon", "#800000", "brown", "#A52A2A",
"firebrick", "#B22222", "indianred", "#CD5C5C", "lightcoral", "#F08080",
"salmon", "#FA8072", "darksalmon", "#E9967A", "lightsalmon", "#FFA07A",
"coral", "#FF7F50", "tomato", "#FF6347", "darkorange", "#FF8C00",
"orange", "#FFA500", "orangered", "#FF4500", "crimson", "#DC143C",
"red", "#FF0000", "deeppink", "#FF1493", "fuchsia", "#FF00FF",
"magenta", "#FF00FF", "hotpink", "#FF69B4", "lightpink", "#FFB6C1",
"pink", "#FFC0CB", "palevioletred", "#DB7093", "mediumvioletred", "#C71585"
] + [
"purple", "#800080", "darkmagenta", "#8B008B", "mediumpurple", "#9370DB",
"blueviolet", "#8A2BE2", "indigo", "#4B0082", "darkviolet", "#9400D3",
"darkorchid", "#9932CC", "mediumorchid", "#BA55D3", "orchid", "#DA70D6",
"violet", "#EE82EE", "plum", "#DDA0DD", "thistle", "#D8BFD8",
"lavender", "#E6E6FA", "ghostwhite", "#F8F8FF", "aliceblue", "#F0F8FF",
"mintcream", "#F5FFFA", "honeydew", "#F0FFF0", "lightgoldenrodyellow", "#FAFAD2",
"lemonchiffon", "#FFFACD", "cornsilk", "#FFF8DC", "lightyellow", "#FFFFE0",
"ivory", "#FFFFF0", "floralwhite", "#FFFAF0", "linen", "#FAF0E6",
"oldlace", "#FDF5E6", "antiquewhite", "#FAEBD7", "bisque", "#FFE4C4 ",
"peachpuff", "#FFDAB9", "papayawhip", "#FFEFD5", "beige", "#F5F5DC"
] + [
"seashell", "#FFF5EE", "lavenderblush", "#FFF0F5", "mistyrose", "#FFE4E1",
"snow", "#FFFAFA", "white", "#FFFFFF", "whitesmoke", "#F5F5F5",
"gainsboro", "#DCDCDC", "lightgrey", "#D3D3D3", "silver", "#C0C0C0",
"darkgray", "#A9A9A9", "gray", "#808080", "lightslategray", "#778899",
"slategray", "#708090", "dimgray", "#696969", "darkslategray", "#2F4F4F",
"black", "#000000"
] + [
// :o
"carnationpink", "#FA7FC1"
];
}

say(key id, string str) {
if ( USE_IMS ) llInstantMessage( id, str );
else llWhisper(0, str);
}

vector color_from_hex(string str) {
return <(integer)("0x" + llGetSubString(str,1,2)),
(integer)("0x" + llGetSubString(str,3,4)),
(integer)("0x" + llGetSubString(str,5,6))> / 255;
}

vector color_from_vector(string vec) {
// caveat: 1,1,1 will be treated as #ffffff, not #010101
list l = llParseString2List(vec, [" ", ",", "<", ">"], []);
vector v;

v.x = (float)llList2String(l, 0);
v.y = (float)llList2String(l, 1);
v.z = (float)llList2String(l, 2);

if ( v.x > 1 || v.y > 1 || v.z > 1 ) v /= 255;

return v;
}

vector color_from_name(string name) {
// vv strip spaces and force lowercase vv
integer x = llListFindList(COLORS, [ llToLower(llDumpList2String(llParseString2List(name, [" "], []), "")) ]);
if ( x == -1 ) return <-1,-1,-1>;
return color_from_hex( llList2String(COLORS, x+1) );
}

set_color(key id, string str) {
vector color;
integer i;
if ( llGetSubString(str, 0, 0) == PREFIX_HEX ) // hex code
color = color_from_hex( str );
else if ( llGetSubString(str, 0, 0) == PREFIX_VECTOR ) // vector
color = color_from_vector( str );
else
color = color_from_name( str );

if ( color.x < 0 || color.x > 1 || color.y < 0 || color.y > 1 || color.z < 0 || color.z > 1 ) {
say( id, "Invalid color specified: " + str );
return;
}

for ( i = 0; i < llGetListLength( LINKS_TO_SET ); i += 2 )
llSetLinkColor( llList2Integer(LINKS_TO_SET, i), color, llList2Integer(LINKS_TO_SET, i+1) );
}

list_colors(key id) {
string str = "";
string nstr = "";
integer i;

for ( i = 0; i < llGetListLength( COLORS ); i += 2 ) {
nstr = str + llList2String(COLORS, i) + ", ";

if ( llStringLength(nstr) > MAX_CHAT_LENGTH ) {
say(id, str);
str = llList2String(COLORS, i);
} else {
str = nstr;
}
}
if ( str != "" ) say(id, str);
}

default {
state_entry() {
set_colors();
llListen( CHANNEL, "", NULL_KEY, "" );
}

listen(integer channel, string name, key id, string msg) {
string command;
string argument;
list l;

if (OWNER_ONLY && id != llGetOwner()) return;

l = llParseStringKeepNulls( msg, [" "], [] );
command = llList2String(l, 0);
argument = llDumpList2String( llList2List(l, 1, -1), " " );

if ( command == COMMAND_CHANGE_COLOR )
set_color(id, argument);
else if ( command == COMMAND_LIST_COLORS )
list_colors(id);

}
}
Preciosa Monde
Registered User
Join date: 10 Mar 2004
Posts: 6
03-03-2005 13:36
How much strain does a script like this add to the server?
Hiro Pendragon
bye bye f0rums!
Join date: 22 Jan 2004
Posts: 5,905
03-04-2005 00:09
From: Masakazu Kojima
llListen( CHANNEL, "", NULL_KEY, "" );

For the love of Content Linden, PLEASE change this to:
llListen( CHANNEL, "", llGetOwner(), "" );

Else your color changer will be listening to everyone in the sim = laaaaaaaaag.

Also, you can have a simple set color script and use the command:
llSetColor

llSetColor(vector color, integer face);

the most common use of "face" being "ALL_SIDES".

you can also do a simple translation from 0-255 color format (like your normal SL editor) by dividing by 255:

CODE
vector input = <100,255,60>;
vector color;
color.x = input.x / 255;
color.x = input.y / 255;
color.x = input.z / 255;
llSetColor(color,ALL_SIDES);
_____________________
Hiro Pendragon
------------------
http://www.involve3d.com - Involve - Metaverse / Emerging Media Studio

Visit my SL blog: http://secondtense.blogspot.com
Jack Lambert
Registered User
Join date: 4 Jun 2004
Posts: 265
03-04-2005 01:19
Not sure if anyone has mentioned this but here we go...

Some popular color choices for those who don't get the vector RGBs and/or are too lazy to figure it out:

Red = <255, 0, 0>
Green = <0, 255, 0>
Blue = <0, 0, 255>
Yellow = <255, 255, 0>
White = <255, 255, 255>
Black = <0, 0, 0>

It's obvious to a lot of us scripters but some people just don't know yet.

--Jack Lambert
Torley Linden
Enlightenment!
Join date: 15 Sep 2004
Posts: 16,530
03-04-2005 01:32
Neon Pink = <255,0,128>

:D
_____________________
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
03-04-2005 02:28
From: Hiro Pendragon
Else your color changer will be listening to everyone in the sim = laaaaaaaaag.

It is my understanding that specific criteria in the llListen call causes more load on the sim, while checking the criteria yourself causes more load on the script. I think load on the script is more acceptable than load on the entire sim, since scripts are allocated a fixed amount of time every frame already anyway.

/invalid_link.html

If you have any evidence to the contrary I would love to see it, as I have been designing scripts with this in mind for quite some time. In my own tests the effects of both have been equally negligible.
Jack Lambert
Registered User
Join date: 4 Jun 2004
Posts: 265
03-04-2005 02:36
Yup I tested exactly the same thing under "heavy loads" in Isabel...

I couldn't tell one bit of difference between the two methods, though admittedly I didn't have a very scientific tool for measuring the difference (see the Elapsed function in the wiki scripting library)

--Jack Lambert
cell Neutra
That's L$50k please
Join date: 26 Sep 2004
Posts: 28
03-04-2005 16:39
From: Masakazu Kojima
It is my understanding that specific criteria in the llListen call causes more load on the sim, while checking the criteria yourself causes more load on the script. I think load on the script is more acceptable than load on the entire sim, since scripts are allocated a fixed amount of time every frame already anyway.


I may be completely wrong (I AM a newb). But I believe Cory's point was that TWO listens will cause more load on the sim, which makes sense. I think the fact that it is more than one listen that causes the extra load, not the fact that it is more specific. From all of my readings in my 2 weeks or so in SL, I've taken in that it is definitely less burdensome on the sim to be specific in the listen call and from a logical standpoint I would need a very good reason not to believe that. Best example I could give would be TDMA cellphone usage, but I don't think that would be useful to most :P.