forked from Ociidii-Works/ZenAxeColorChanger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccng v2.lsl
232 lines (211 loc) · 8.12 KB
/
ccng v2.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
// For better readability, extend the size of the editor until this comment fits fully on one line.
//////// How to use ///////////
// See https://github.com/Ociidii-Works/ZenAxeColorChanger/blob/master/README.md
// user preferences //
float glowAmount = 0.08; // How much glow, negative for no change
integer colorRoot = TRUE; // Needed for checking if we want to recolor the root prim
integer MessagesLevel = 0; // Verbosity.
///////////////////////////////////////////////////////////////////
// internal variables, LEAVE THEM ALONE!! D:
key owner; // Owner, set in state_entry
list primsToRecolor = []; // Internal use, don't touch.
integer primListLen; // Length of the prim list. used for checks
///////////////////////////////////////////////////////////////////
////////////////////// Custom Functions /////////////////////////
////// Debug system /////////
ErrorMessage(string message) { if (MessagesLevel >= 1) llOwnerSay("E: " + message); }
InfoMessage(string message) { if (MessagesLevel >= 2) llOwnerSay("I: " + message); }
DebugMessage(string message) { if (MessagesLevel >= 3) llOwnerSay("D: " + message); }
vector random_color() { return <llFrand(1.0), llFrand(1.0), llFrand(1.0)>; }
vector translateColor(string message)
{
message = llToLower(message);
if (llGetSubString(message, 0, 4) != "glow ") // Invalid message, only way to abort is to give bad color vector.
return <9,9,9>;
if (message == "glow red")
return <1.00000, 0.00000, 0.00000>;
if (message == "glow dkred")
return <0.31373, 0.00000, 0.00000>;
if (message == "glow orange")
return <1.00000, 0.50196, 0.00000>;
if (message == "glow ltorange")
return <1.00000, 0.80000, 0.40000>;
if (message == "glow dkorange")
return <0.70588, 0.25098, 0.00000>;
if (message == "glow pink")
return <1.00000, 0.40000, 0.40000>;
if (message == "glow blue")
return <0.00000, 0.00000, 1.00000>;
if (message == "glow ltblue")
return <0.40000, 1.00000, 1.00000>;
if (message == "glow dkblue")
return <0.00000, 0.00000, 0.31373>;
if (message == "glow yellow")
return <1.00000, 0.81961, 0.00000>;
if (message == "glow ltyellow")
return <1.00000, 1.00000, 0.40000>;
if (message == "glow dkyellow")
return <0.84314, 0.84314, 0.00000>;
if (message == "glow white")
return <1.00000, 1.00000, 1.00000>;
if (message == "glow purple")
return <0.50196, 0.00000, 0.50196>;
if (message == "glow ltpurple")
return <0.80000, 0.40000, 1.00000>;
if (message == "glow dkpurple")
return <0.25098, 0.00000, 0.50196>;
if (message == "glow green")
return <0.00000, 1.00000, 0.00000>;
if (message == "glow ltgreen")
return <0.50196, 1.00000, 0.00000>;
if (message == "glow dkgreen")
return <0.00000, 0.50196, 0.00000>;
if (message == "glow black")
return <0.00000, 0.00000, 0.00000>;
if (message == "glow ltgray")
return <0.60000, 0.60000, 0.60000>;
if (message == "glow gray")
return <0.40000, 0.40000, 0.40000>;
if (message == "glow dkgray")
return <0.20000, 0.20000, 0.20000>;
if (message == "glow reactor")
return <0.65490, 0.96863, 0.24314>;
if (message == "glow tron")
return <0.60784, 0.97255, 1.00000>;
if (message == "glow corrupt")
return <1.00000, 0.25098, 0.00000>;
if (message == "glow viral")
return <0.75294, 1.00000, 0.00000>;
if (message == "glow violet")
return <0.58431, 0.52549, 0.86667>;
if (message == "glow singularity")
return <1, 0.4705882352941176, 0.280392156862745>;
if (message == "glow smoothblue")
return <0.1803921568627451,0.3333333333333333,0.8823529411764706>;
if (message == "glow arc")
return <0.607843137254902,0.972549019607843,1>;
if (message == "glow hotpink")
return <0.9803921568627451,0.3019607843137255,0.6862745098039216>;
if (message == "glow redhead")
return <0.7725490196078431,0.3568627450980392,0.1725490196078431>;
if (message == "glow random")
return random_color();
return <9, 9, 9>;
}
listPrims()
{
primListLen = 0;
list recolorNames = ["ColorPrim"]; // Name all recolorable prims here, case sensitive!
integer fp = 0; // counter
for(; fp <= llGetNumberOfPrims(); ++fp)
{
if (llListFindList(recolorNames, [llGetLinkName(fp)]) != -1)
{
primsToRecolor += fp;
++primListLen;
}
}
if (colorRoot && (primListLen == 0 || llListFindList(primsToRecolor, [LINK_ROOT]) == -1)) // User wants root, but not in the list
{
primsToRecolor += LINK_ROOT;
++primListLen;
}
InfoMessage("List Length: " + (string)primListLen);
}
setColor(vector color)
{
if (color == <9,9,9>) return; // Minor hack
integer i = 0;
for(; i < primListLen; ++i)
{
integer link = llList2Integer(primsToRecolor, i);
// Set color
if (link == LINK_ROOT || glowAmount < 0) // Don't glow root, negative glow is no change
{
if (link == LINK_ROOT) InfoMessage("Setting Root Color to: " + (string)color);
llSetLinkColor(link, color, ALL_SIDES);
}
else
{
llSetLinkPrimitiveParamsFast(link,
[PRIM_COLOR,ALL_SIDES,color,1.0,
PRIM_GLOW,ALL_SIDES,glowAmount
]);
}
}
}
/////////////////////////// Script Starts Here ///////////////////////////
default
{
state_entry()
{
owner = llGetOwner();
listPrims();
llListen(9, "", owner, "");
// llSetMemoryLimit(llGetUsedMemory() + 4096);
llSetTimerEvent(0.5);
}
// We re-use the listener system from what we are replacing,
listen(integer channel, string name, key is, string message)
{
setColor(translateColor(message));
InfoMessage(message);
}
changed(integer change)
{
if (change & CHANGED_LINK)
{
primsToRecolor = [];
listPrims();
}
}
timer()
{
if (llGetAgentInfo(owner) & AGENT_TYPING)
{
list originalColors;
integer rootfaces = 0;
list rootlist;
integer i = 0;
for (; i < primListLen; ++i)
{
integer link = llList2Integer(primsToRecolor, i);
if (LINK_ROOT == link)
{
rootfaces = llGetNumberOfSides();
integer i = 0;
while (; i < faces; ++i)
rootlist += llGetColor(i);
}
else
{
originalColors += [PRIM_LINK_TARGET, link];
list mew = llGetLinkPrimitiveParams(link, [PRIM_COLOR,ALL_SIDES]);
integer mewlen = llGetListLength(mew);
integer j = 0;
for (; j < mewlen; j+=2) // mew is strided by two
originalColors += [PRIM_COLOR, j/2] + llList2List(mew, j, j+1);
}
}
do
{
setColor(random_color());
llSleep(0.01); // Liru Note: Should we even bother, Forced Delay from above call could be enough
} while(llGetAgentInfo(owner) & AGENT_TYPING);
DebugMessage(llDumpList2String(originalColors, " | "));
for(--rootfaces; rootfaces >= 0; --rootfaces)
llSetColor(llList2Float(rootlist, rootfaces), rootface);
llSetLinkPrimitiveParamsFast(LINK_ROOT, originalColors);
}
}
}