aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/media/Test%20sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~props.lsl
diff options
context:
space:
mode:
Diffstat (limited to 'media/Test%20sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~props.lsl')
-rw-r--r--media/Test%20sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~props.lsl397
1 files changed, 397 insertions, 0 deletions
diff --git a/media/Test%20sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~props.lsl b/media/Test%20sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~props.lsl
new file mode 100644
index 0000000..a731d77
--- /dev/null
+++ b/media/Test%20sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~props.lsl
@@ -0,0 +1,397 @@
1//Imported by X-Avatar.de
2//MPLV2 Version 2.3 by Learjeff Innis, based on
3//MLP MULTI-LOVE-POSE V1.2 - Copyright (c) 2006, by Miffy Fluffy (BSD License)
4
5
6// v2.2 - rotate all props
7
8// This script handles props (object rezzed for a given pose)
9
10integer Checking = FALSE; // whether doing consistency check
11
12integer Line;
13integer PoseCount;
14list Poses; // name of each pose with a prop
15list Positions; // position of prop, indexed as Poses
16list Props; // name of each prop object, indexed as Poses
17
18string Pose; // current pose name
19
20integer ChatChan; // chan for talking to object
21
22init()
23{
24 ChatChan = - 1 - (integer)llFrand(-DEBUG_CHANNEL);
25 getRefPos();
26}
27
28vector RefPos;
29rotation RefRot;
30
31getRefPos() { //reference position
32 RefPos = llGetPos();
33 RefRot = llGetRot();
34 integer z = (integer)llGetObjectDesc();
35 RefPos.z += (float)z/100.0;
36}
37
38string plural(string singular, string plural, integer count) {
39 if (count != 1) {
40 return plural;
41 }
42 return singular;
43}
44
45announce()
46{
47 llOwnerSay((string)PoseCount
48 + plural(" pose", " poses", PoseCount)
49 + " with props ("
50 + llGetScriptName()
51 + ": "
52 + (string)llGetFreeMemory()
53 + " bytes free)");
54}
55
56string adjust(integer doOffset, vector pos, vector erot, vector amt) {
57 if (doOffset) {
58 pos += amt/100.;
59 return (vround(pos) + "/" + vround(erot));
60 }
61 rotation amount = llEuler2Rot(amt * DEG_TO_RAD);
62 erot *= DEG_TO_RAD;
63
64 rotation oldrot = llEuler2Rot(erot);
65 rotation newrot = oldrot / amount;
66
67 erot = llRot2Euler(newrot) * RAD_TO_DEG;
68 pos = pos / amount;
69 return(vround(pos) + "/" + vround(erot));
70}
71
72
73adjust_all(integer doOffset, vector amt) {
74 integer ix;
75 integer bx;
76 string data;
77 list ldata;
78 vector pos;
79 vector erot;
80
81
82 for (ix = 0; ix < llGetListLength(Poses); ++ix) {
83 data = llList2String(Positions, ix);
84 ldata = llParseString2List(data, ["/"], []);
85 pos = (vector)llList2String(ldata, 0);
86 erot = (vector)llList2String(ldata, 1);
87
88 data = adjust(doOffset, pos, erot, amt);
89 Positions = llListReplaceList(Positions, (list)data, ix, ix);
90 }
91 llOwnerSay("Prop rotation complete");
92}
93
94
95
96string roundData(string data) {
97 list ldata = llParseString2List(data, ["/"], []);
98 return (vround((vector)llList2String(ldata, 0)) + "/" + vround((vector)llList2String(ldata, 1)));
99}
100
101// round a vector's components and return as vector value string
102string vround(vector vec) {
103 return ("<"+round(vec.x, 3)+","+round(vec.y, 3)+","+round(vec.z, 3)+">");
104}
105
106string round(float number, integer places) {
107 float shifted;
108 integer rounded;
109 string s;
110 shifted = number * llPow(10.0,(float)places);
111 rounded = llRound(shifted);
112 s = (string)((float)rounded / llPow(10.0,(float)places));
113 s = llGetSubString(s,0,llSubStringIndex(s, ".")+places);
114 return s;
115}
116
117
118add_prop(string pose, string prop, string data) {
119 if (llListFindList(Props, (list)pose) != -1) {
120 llOwnerSay("Multiple *.PROPS* entries for pose '" + pose + "'");
121 }
122 if (llGetInventoryType(prop) != INVENTORY_OBJECT) {
123 llOwnerSay("Warning: can't find prop '" + prop + "' in inventory");
124 }
125 Poses = (list) pose;
126 Props = (list) prop;
127 Positions = (list) roundData(data);
128 ++PoseCount;
129}
130
131string get_pose_data(string pose)
132{
133 integer ix = llListFindList(Poses, (list)pose);
134
135 if (ix == -1) {
136 return "";
137 }
138
139 return llList2String(Positions, ix);
140}
141
142save_prop(string pose, string prop, string data) {
143 integer ix = llListFindList(Poses, [pose]);
144 if (ix == -1) {
145 // llSay(0, "new pose");
146 add_prop(pose, prop, data); // don't expect this to happen
147 return;
148 }
149
150 // if the prop object name doesn't match, ignore it -- assume it's noise
151 if (llList2String(Props, ix) != prop) {
152 return;
153 }
154
155 // Data is the change in position since we rezzed it, in global coords
156 // Convert delta to local axes
157
158 list ldata = llParseString2List(data, ["/"], []);
159 vector pos = (vector) llList2String(ldata, 0);
160 rotation rot = (rotation)llList2String(ldata, 1);
161
162 pos = pos / RefRot;
163 vector erot = llRot2Euler(rot/RefRot) * RAD_TO_DEG;
164
165 // Now add to saved data (since it was a delta)
166 ldata = llParseStringKeepNulls(llList2String(Positions, ix), ["/"], []);
167 vector oldpos = (vector)llList2String(ldata, 0);
168
169 pos += oldpos;
170 data = vround(pos) + "/" + vround(erot);
171
172 Props = llListReplaceList(Props, (list)prop, ix, ix);
173 Positions = llListReplaceList(Positions, (list)data, ix, ix);
174
175 string name = llGetObjectName();
176 llSetObjectName("");
177 llOwnerSay("| " + pose + " | " + prop + " | " + data);
178 llSetObjectName(name);
179}
180
181rez_prop(string pose) {
182 llSay(ChatChan, "DIE");
183 integer ix = -1; //(integer)llListFindList(Poses, [pose]);
184 integer ggt =0;
185 for (ggt=0; ggt < llGetListLength(Poses); ggt++)
186 {
187 if (llList2String(Poses,ggt) == pose)
188 {
189 ix = ggt;
190 ggt = llGetListLength(Poses);
191 }
192 }
193 if (ix == -1)
194 {
195 Pose = "";
196 llSetTimerEvent(0.0);
197 return;
198 }
199 string prop = llList2String(Props, ix);
200 string data = llList2String(Positions, ix);
201 list ldata = llParseString2List(data, ["/"], []);
202 vector pos = (vector)llList2String(ldata, 0);
203 vector erot = (vector)llList2String(ldata, 1);
204
205 pos = pos * RefRot + RefPos;
206 rotation rot = llEuler2Rot(erot*DEG_TO_RAD) * RefRot;
207
208 // llSay(0, "rezzing '" + prop + "' at " + (string) pos);
209 llRezAtRoot(prop, pos, <0.,0.,0.>, rot, ChatChan);
210 llSetTimerEvent(60.0);
211 Pose = pose;
212}
213
214
215dashes() {
216 llOwnerSay("_______________________________________________________________________________");
217 llOwnerSay("");
218}
219
220
221// Globals for reading card config
222integer ConfigLineIndex;
223list ConfigCards; // list of names of config cards
224string ConfigCardName; // name of card being read
225integer ConfigCardIndex; // index of next card to read
226key ConfigQueryId;
227
228integer next_card()
229{
230 if (ConfigCardIndex >= llGetListLength(ConfigCards)) {
231 ConfigCards = [];
232 return (FALSE);
233 }
234
235 ConfigLineIndex = 0;
236 ConfigCardName = llList2String(ConfigCards, ConfigCardIndex);
237 ConfigCardIndex++;
238 ConfigQueryId = llGetNotecardLine(ConfigCardName, ConfigLineIndex);
239 llOwnerSay("Reading " + ConfigCardName);
240 return (TRUE);
241}
242
243
244default {
245 state_entry() {
246 llSleep(0.25); // give ~run a chance to shut us down
247 string item;
248 ConfigCards = [];
249 integer n = llGetInventoryNumber(INVENTORY_NOTECARD);
250 while (n-- > 0) {
251 item = llGetInventoryName(INVENTORY_NOTECARD, n);
252 if (llSubStringIndex(item, ".PROPS") != -1) {
253 ConfigCards = (list) item;
254 }
255 }
256
257 ConfigCardIndex = 0;
258 ConfigCards = llListSort(ConfigCards, 1, TRUE);
259 next_card();
260 }
261
262 dataserver(key query_id, string data2) {
263 if (query_id != ConfigQueryId) {
264 return;
265 }
266 if (data2 == EOF) {
267 if (next_card()) {
268 return;
269 }
270 state on;
271 }
272
273 string data3 = llStringTrim(data2, STRING_TRIM);
274 if (llGetSubString(data3,0,0) != "/" && llStringLength(data3)) { // skip comments and blank lines
275
276 list ldata = llParseStringKeepNulls(data3, [" | "," | "," | "," | "," |","| ","|"], []);
277 if (llGetListLength(ldata) != 4) {
278 llOwnerSay(llGetScriptName() + ": error in " + ConfigCardName + ":" + (string)ConfigLineIndex
279 + " - need exactly 3 vertical bars - line ignored");
280 } else {
281 string pose = llList2String(ldata, 1);
282 string prop = llList2String(ldata, 2);
283 string data = llStringTrim(llList2String(ldata, 3), STRING_TRIM);
284 if (data3 == "") {
285 data3 = "<0,0,1>/<0,0,0>";
286 }
287 add_prop(pose, prop, data3);
288 }
289 }
290 ++ConfigLineIndex;
291 ConfigQueryId = llGetNotecardLine(ConfigCardName, ConfigLineIndex); //read next line of positions notecard
292 }
293
294 state_exit() {
295 // do one save to indicate actual amount of available memory
296 string position = llList2String(Positions, 0);
297 Positions = llListReplaceList(Positions, [position],0,0);
298
299 llMessageLinked(LINK_THIS, 2, "OK", (key)""); //msg to menu, in case it's waiting for loading
300 announce();
301 }
302}
303
304state re_on
305{
306 state_entry() {
307 state on;
308 }
309}
310
311state on {
312 state_entry() {
313 init();
314 llListen(ChatChan, "", NULL_KEY, "");
315 }
316
317 on_rez(integer arg) {
318 state re_on;
319 }
320
321 listen(integer chan, string name, key id, string msg) {
322 // llSay(0, name + ": " + msg);
323 if (Pose == "") {
324 return;
325 }
326 save_prop(Pose, name, msg);
327 announce();
328 }
329
330 link_message(integer from, integer num, string str, key dkey) {
331
332 if (str == "PRIMTOUCH" || num < 0) {
333 return;
334 }
335
336 if (num == 0) {
337 if (str == "POSEB") {
338 rez_prop((string)dkey);
339 return;
340 }
341 if (str == "REPOS") {
342 getRefPos();
343 return;
344 }
345 return;
346 }
347
348 if (num != 1) {
349 return;
350 }
351
352 if (str == "STOP") {
353 llSay(ChatChan, "DIE");
354 Pose = "";
355 llSetTimerEvent(0.0);
356 }
357
358 if (str == "DUMPPROPS") {
359 dashes();
360 llOwnerSay("Copy to .PROPS; delete any other *.PROPS* cards");
361 dashes();
362 string name = llGetObjectName();
363 llSetObjectName("");
364
365 integer ix;
366 for (ix = 0; ix < PoseCount; ++ix) {
367 string pose = llList2String(Poses, ix);
368 string prop = llList2String(Props, ix);
369 llOwnerSay("| " + pose + " | " + prop + " | " + get_pose_data(pose));
370 }
371 llSetObjectName(name);
372 dashes();
373 } else if (llSubStringIndex(str, "REORIENT=") == 0) {
374 // Reorient command (LINKMENU command from .MENUITEMS file)
375 // str format: REORIENT=OFF=<x,y,z> or REORIENT=ROT=<x,y,z> (in degrees)
376 list parms = llParseString2List(str, ["="], []);
377 vector amount = (vector)llList2String(parms, 2);
378 llWhisper(0, "Adjusting props, please wait");
379
380 if (llList2String(parms, 1) == "OFF") {
381 adjust_all(TRUE, amount);
382 } else {
383 adjust_all(FALSE, amount);
384 }
385 llMessageLinked(LINK_THIS, 0, "AGAIN", (key)"");
386 llWhisper(0, "Prop adjustment complete");
387 } else if (str == "SAVEPROP") {
388 llSay(ChatChan, "SAVE");
389 }
390 }
391
392 timer() {
393 llSay(ChatChan, "LIVE");
394 }
395
396}
397