Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
OpenSim NPC NPC_Pupetteer  

NPC_Pupetteer

Bug fixes by Ferd Frederix 7-30-2013//
Note: @wander will only wander around the rez point.

Category: OpenSim NPC
By : Wizardy and Steamworks
Created: 2013-07-30 Edited: 2013-07-30
Worlds: OpenSim

the Zip file

Download all files for NPC_Pupetteer
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. NPC_Pupetteer_1.lsl
1 // original from http://was.fm/opensim:npc
2 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
4 ///////////////////////////////////////////////////////////////////////////
5
6
7 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
8 // rights of fair usage, the disclaimer and warranty conditions. //
9 ///////////////////////////////////////////////////////////////////////////
10
11 // Mods by Ferd Frederix
12
13 // 7-29-2013
14 // llSensor had two params swapped
15 // There was no 'no_sensor' event in sit, so if a @sit failed, the NPC got stuck
16 // The animation and walks always stopped old, then started new. It should be start new, then stop old so the default stand would be suppressed
17 // Added OS_NPC_SENSE_AS_AGENT so NPCs can be sensed as avatars by other scripts.
18
19 //////////////////////////////////////////////////////////
20 // CONFIGURATION //
21 //////////////////////////////////////////////////////////
22
23 // How much time, in seconds, does a standing animation
24 // cycle take?
25 float ANIMATION_CYCLE_TIME = 10;
26
27 ///////////////////////////////////////////////////////////////////////////
28 // INTERNALS //
29 ///////////////////////////////////////////////////////////////////////////
30
31
32 vector wasCirclePoint(float radius) {
33 float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
34 float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
35 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2))
36 return <x, y, 0>;
37 return wasCirclePoint(radius);
38 }
39
40 ///////////////////////////////////////////////////////////////////////////
41 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
42 ///////////////////////////////////////////////////////////////////////////
43 string wasKeyValueGet(string var, string kvp) {
44 list dVars = llParseString2List(kvp, ["&"], []);
45 do {
46 list data = llParseString2List(llList2String(dVars, 0), ["="], []);
47 string k = llList2String(data, 0);
48 if(k != var) jump continue;
49 return llList2String(data, 1);
50 @continue;
51 dVars = llDeleteSubList(dVars, 0, 0);
52 } while(llGetListLength(dVars));
53 return "";
54 }
55
56 ///////////////////////////////////////////////////////////////////////////
57 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
58 ///////////////////////////////////////////////////////////////////////////
59 string wasKeyValueSet(string var, string val, string kvp) {
60 list dVars = llParseString2List(kvp, ["&"], []);
61 if(llGetListLength(dVars) == 0) return var + "=" + val;
62 list result = [];
63 do {
64 list data = llParseString2List(llList2String(dVars, 0), ["="], []);
65 string k = llList2String(data, 0);
66 if(k == "") jump continue;
67 if(k == var && val == "") jump continue;
68 if(k == var) {
69 result += k + "=" + val;
70 val = "";
71 jump continue;
72 }
73 string v = llList2String(data, 1);
74 if(v == "") jump continue;
75 result += k + "=" + v;
76 @continue;
77 dVars = llDeleteSubList(dVars, 0, 0);
78 } while(llGetListLength(dVars));
79 if(val != "") result += var + "=" + val;
80 return llDumpList2String(result, "&");
81 }
82
83 ///////////////////////////////////////////////////////////////////////////
84 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
85 ///////////////////////////////////////////////////////////////////////////
86 string wasKeyValueDelete(string var, string kvp) {
87 list dVars = llParseString2List(kvp, ["&"], []);
88 list result = [];
89 list added = [];
90 do {
91 list data = llParseString2List(llList2String(dVars, 0), ["="], []);
92 string k = llList2String(data, 0);
93 if(k == var) jump continue;
94 string v = llList2String(data, 1);
95 if(v == "") jump continue;
96 if(llListFindList(added, (list)k) != -1) jump continue;
97 result += k + "=" + v;
98 added += k;
99 @continue;
100 dVars = llDeleteSubList(dVars, 0 ,0);
101 } while(llGetListLength(dVars));
102 return llDumpList2String(result, "&");
103 }
104
105 // Vector that will be filled by the script with
106 // the initial starting position in region coordinates.
107 vector iPos = ZERO_VECTOR;
108 // Storage for destination position.
109 vector dPos = ZERO_VECTOR;
110 // Storage for the NPC script.
111 list npcScript = [];
112 // Storage for the next action.
113 string npcAction = "";
114 string npcParams = "";
115 // Storage for talking on local chat.
116 string npcSay = "";
117
118
119 stop()
120 {
121 osNpcRemove(wasKeyValueGet("key", llGetObjectDesc())) ;
122 }
123
124 default {
125 state_entry() {
126 osNpcRemove(wasKeyValueGet("key", llGetObjectDesc()));
128 }
129 timer() {
130 npcScript = llParseString2List(osGetNotecard("Script"), ["\n"], []);
131 if(llGetListLength(npcScript) == 0) {
132 llSay(DEBUG_CHANNEL, "No script notecard found.");
134 return;
135 }
137 state script;
138 }
139 changed(integer change) {
140 if(change & CHANGED_REGION_START) llResetScript();
141 }
142 on_rez(integer num) {
144 }
145 }
146
147 state script
148 {
149 state_entry() {
150 @ignore;
151 string next = llList2String(npcScript, 0);
152 npcScript = llDeleteSubList(npcScript, 0, 0);
153 npcScript += next;
154 if(llGetSubString(next, 0, 0) != "@") jump ignore;
155 list data = llParseString2List(next, ["="], []);
156 npcAction = llToLower(llStringTrim(llList2String(data, 0), STRING_TRIM));
157 npcParams = llStringTrim(llList2String(data, 1), STRING_TRIM);
159 }
160 timer() {
162 @commands;
163 if(npcAction == "@spawn") {
164 integer lastIdx = llGetListLength(npcScript)-1;
165 npcScript = llDeleteSubList(npcScript, lastIdx, lastIdx);
166 list spawnData = llParseString2List(npcParams, ["|"], []);
167 llSetObjectDesc(wasKeyValueSet("name", llList2String(spawnData, 0), llGetObjectDesc()));
168 list spawnDest = llParseString2List(llList2String(spawnData, 1), ["<", ",", ">"], []);
169 iPos.x = llList2Float(spawnDest, 0);
170 iPos.y = llList2Float(spawnDest, 1);
171 iPos.z = llList2Float(spawnDest, 2);
172 state spawn;
173 }
174 if(npcAction == "@goto") {
175 integer lastIdx = llGetListLength(npcScript)-1;
176 npcScript = llDeleteSubList(npcScript, lastIdx, lastIdx);
177 // Wind commands till goto label.
178 @wind;
179 string next = llList2String(npcScript, 0);
180 npcScript = llDeleteSubList(npcScript, 0, 0);
181 npcScript += next;
182 if(next != npcParams) jump wind;
183 // Wind the label too.
184 next = llList2String(npcScript, 0);
185 npcScript = llDeleteSubList(npcScript, 0, 0);
186 npcScript += next;
187 // Get next command.
188 list data = llParseString2List(next, ["="], []);
189 npcAction = llToLower(llStringTrim(llList2String(data, 0), STRING_TRIM));
190 npcParams = llStringTrim(llList2String(data, 1), STRING_TRIM);
191 // Reschedule.
192 jump commands;
193 }
194 if(npcAction == "@walk") {
195 list dest = llParseString2List(npcParams, ["<", ",", ">"], []);
196 dPos.x = llList2Float(dest, 0);
197 dPos.y = llList2Float(dest, 1);
198 dPos.z = llList2Float(dest, 2);
199 state walk;
200 }
201 if(npcAction == "@say") {
202 npcSay = npcParams;
203 state say;
204 }
205 if(npcAction == "@pause") {
206 llSetObjectDesc(wasKeyValueSet("pause", npcParams, llGetObjectDesc()));
207 state pause;
208 }
209 if(npcAction == "@wander") {
210 list wanderData = llParseString2List(npcParams, ["|"], []);
211 llSetObjectDesc(wasKeyValueSet("wd", llList2String(wanderData, 0), llGetObjectDesc()));
212 llSetObjectDesc(wasKeyValueSet("wc", llList2String(wanderData, 1), llGetObjectDesc()));
213 iPos = llGetPos();
214 state wander;
215 }
216 if(npcAction == "@rotate") {
217 llSetObjectDesc(wasKeyValueSet("rot", npcParams, llGetObjectDesc()));
218 state rotate;
219 }
220 if(npcAction == "@sit") {
221 llSetObjectDesc(wasKeyValueSet("sit", npcParams, llGetObjectDesc()));
222 state sit;
223 }
224 if(npcAction == "@stand") {
225 state stand;
226 }
227 if(npcAction == "@stop") {
228 state stop;
229 }
230 if(npcAction == "@delete") {
231 state delete;
232 }
233 if(npcAction == "@animate") {
234 list animateData = llParseString2List(npcParams, ["|"], []);
235 llSetObjectDesc(wasKeyValueSet("an", llList2String(animateData, 0), llGetObjectDesc()));
236 llSetObjectDesc(wasKeyValueSet("at", llList2String(animateData, 1), llGetObjectDesc()));
237 state animate;
238 }
239 llSay(DEBUG_CHANNEL, "ERROR: Unrecognized script line: " + npcAction + "=" + npcParams);
240 }
241 changed(integer change) {
242 if(change & CHANGED_REGION_START) llResetScript();
243 }
244 on_rez(integer num) {
246 }
247 }
248
249 state rotate {
250 state_entry() {
251 osNpcSetRot(wasKeyValueGet("key", llGetObjectDesc()), llEuler2Rot(<0,0,(float)wasKeyValueGet("rot", llGetObjectDesc())> * DEG_TO_RAD));
253 }
254 link_message(integer sender, integer num, string str, key id) {
255 if(id == "@npc_say")
256 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
257 else if(id == "@npc_stop")
258 {
259 stop();
260 state stopped;
261 }
262 }
263 timer() {
264 llSetObjectDesc(wasKeyValueDelete("rot", llGetObjectDesc()));
265 state script;
266 }
267 changed(integer change) {
268 if(change & CHANGED_REGION_START)
270 }
271 on_rez(integer num) {
273 }
274 }
275
276 state sit {
277 state_entry() {
278 llSensorRepeat(wasKeyValueGet("sit", llGetObjectDesc()), "", PASSIVE|ACTIVE, 96, TWO_PI, 1);
279 }
280 sensor(integer num) {
282 osNpcSit(wasKeyValueGet("key", llGetObjectDesc()), llDetectedKey(0), OS_NPC_SIT_NOW);
284 }
285 no_sensor()
286 {
287 llSetObjectDesc(wasKeyValueDelete("sit", llGetObjectDesc()));
288 state script;
289
290 }
291 timer() {
292 llSetObjectDesc(wasKeyValueDelete("sit", llGetObjectDesc()));
293 state script;
294 }
295 link_message(integer sender, integer num, string str, key id) {
296 if(id == "@npc_say")
297 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
298 else if(id == "@npc_stop")
299 {
300 stop();
301 state stopped;
302 }
303 }
304 changed(integer change) {
305 if(change & CHANGED_REGION_START) llResetScript();
306 }
307 on_rez(integer num) {
309 }
310 }
311
312 state stand {
313 state_entry() {
314 osNpcStand(wasKeyValueGet("key", llGetObjectDesc()));
315 state script;
316 }
317 link_message(integer sender, integer num, string str, key id) {
318 if(id == "@npc_say")
319 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
320 else if(id == "@npc_stop")
321 {
322 stop();
323 state stopped;
324 }
325 }
326 changed(integer change) {
327 if(change & CHANGED_REGION_START) llResetScript();
328 }
329 on_rez(integer num) {
331 }
332 }
333
334 state animate {
335 state_entry() {
336 if(llGetInventoryType(wasKeyValueGet("an", llGetObjectDesc())) == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), wasKeyValueGet("an", llGetObjectDesc()));
337 llSetTimerEvent((integer)wasKeyValueGet("at", llGetObjectDesc()));
338 }
339 link_message(integer sender, integer num, string str, key id) {
340 if(id == "@npc_say")
341 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
342 else if(id == "@npc_stop")
343 {
344 stop();
345 state stopped;
346 }
347 }
348 timer() {
349 if(llGetInventoryType(wasKeyValueGet("an", llGetObjectDesc())) == INVENTORY_ANIMATION) osNpcStopAnimation(wasKeyValueGet("key", llGetObjectDesc()), wasKeyValueGet("an", llGetObjectDesc()));
350 llSetObjectDesc(wasKeyValueDelete("an", llGetObjectDesc()));
351 llSetObjectDesc(wasKeyValueDelete("at", llGetObjectDesc()));
352 state script;
353 }
354 changed(integer change) {
355 if(change & CHANGED_REGION_START) llResetScript();
356 }
357 on_rez(integer num) {
359 }
360 }
361
362 state spawn
363 {
364 state_entry() {
365 list name = llParseString2List(wasKeyValueGet("name", llGetObjectDesc()), [" "], []);
366 llSetObjectDesc(wasKeyValueSet("key", osNpcCreate(llList2String(name, 0), llList2String(name, 1), iPos, "appearance",OS_NPC_SENSE_AS_AGENT), llGetObjectDesc()));
367 osNpcLoadAppearance(wasKeyValueGet("key", llGetObjectDesc()), "appearance");
368 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
370 }
371 link_message(integer sender, integer num, string str, key id) {
372 if(id == "@npc_say")
373 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
374 else if(id == "@npc_stop")
375 {
376 stop();
377 state stopped;
378 }
379 }
380 timer() {
382 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcStopAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
383 llSetObjectDesc(wasKeyValueDelete("name", llGetObjectDesc()));
384 state script;
385 }
386 changed(integer change) {
387 if(change & CHANGED_REGION_START) llResetScript();
388 }
389 on_rez(integer num) {
391 }
392
393 }
394
395 state delete {
396 state_entry() {
399 }
400 changed(integer change) {
401 if(change & CHANGED_REGION_START) llResetScript();
402 }
403 on_rez(integer num) {
405 }
406 }
407
408 state stop {
409 state_entry() {
410 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
411 }
412 link_message(integer sender, integer num, string str, key id) {
413 if(id == "@npc_say")
414 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
415 else if(id == "@npc_stop")
416 {
417 stop();
418 state stopped;
419 }
420 }
421 changed(integer change) {
422 if(change & CHANGED_REGION_START) llResetScript();
423 }
424 on_rez(integer num) {
426 }
427 }
428
429 state walk {
430 state_entry() {
431 if(llGetInventoryType("Walk") == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Walk");
432 osNpcMoveToTarget(wasKeyValueGet("key", llGetObjectDesc()), dPos, OS_NPC_NO_FLY);
434 }
435 link_message(integer sender, integer num, string str, key id) {
436 if(id == "@npc_say")
437 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
438 else if(id == "@npc_stop")
439 {
440 stop();
441 state stopped;
442 }
443 }
444 timer() {
445 if(llVecDist(osNpcGetPos(wasKeyValueGet("key", llGetObjectDesc())), dPos) > 2) return;
447 if(llGetInventoryType("Walk") == INVENTORY_ANIMATION) osNpcStopAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Walk");
448 state script;
449 }
450 changed(integer change) {
451 if(change & CHANGED_REGION_START) llResetScript();
452 }
453 on_rez(integer num) {
455 }
456 }
457
458 state say {
459 state_entry() {
460 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), npcSay);
461 npcSay = "";
462 state script;
463 }
464
465 link_message(integer sender, integer num, string str, key id) {
466 if(id == "@npc_say")
467 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
468 else if(id == "@npc_stop")
469 {
470 stop();
471 state stopped;
472 }
473 }
474 changed(integer change) {
475 if(change & CHANGED_REGION_START) llResetScript();
476 }
477 on_rez(integer num) {
479 }
480 }
481
482 state wander
483 {
484 state_entry() {
485 dPos = iPos + wasCirclePoint((integer)wasKeyValueGet("wd", llGetObjectDesc()));
486 if(llGetInventoryType("Walk") == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Walk");
487 osNpcMoveToTarget(wasKeyValueGet("key", llGetObjectDesc()), dPos, OS_NPC_NO_FLY);
488 llSetTimerEvent(0.1);
489 }
490 link_message(integer sender, integer num, string str, key id) {
491 if(id == "@npc_say")
492 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
493 else if(id == "@npc_stop")
494 {
495 stop();
496 state stopped;
497 }
498 }
499 timer() {
500 if(llVecDist(osNpcGetPos(wasKeyValueGet("key", llGetObjectDesc())), dPos) > 2) return;
502 if(llGetInventoryType("Walk") == INVENTORY_ANIMATION) osNpcStopAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Walk");
503 if(wasKeyValueGet("wc", llGetObjectDesc()) == "0") {
504 llSetObjectDesc(wasKeyValueDelete("wc", llGetObjectDesc()));
505 llSetObjectDesc(wasKeyValueDelete("wd", llGetObjectDesc()));
506 state script;
507 }
508 llSetObjectDesc(wasKeyValueSet("wc", (string)((integer)wasKeyValueGet("wc", llGetObjectDesc())-1), llGetObjectDesc()));
509 state wait;
510 }
511 changed(integer change) {
512 if(change & CHANGED_REGION_START) llResetScript();
513 }
514 on_rez(integer num) {
516 }
517 }
518
519 state wait {
520 state_entry() {
521 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
522 llSetTimerEvent(ANIMATION_CYCLE_TIME);
523 }
524 link_message(integer sender, integer num, string str, key id) {
525 if(id == "@npc_say")
526 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
527 else if(id == "@npc_stop")
528 {
529 stop();
530 state stopped;
531 }
532 }
533 timer() {
535 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcStopAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
536 state wander;
537 }
538 changed(integer change) {
539 if(change & CHANGED_REGION_START) llResetScript();
540 }
541 on_rez(integer num) {
543 }
544 }
545
546 state pause {
547 state_entry() {
548 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcPlayAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
549 llSetTimerEvent(ANIMATION_CYCLE_TIME * 1+llFrand((integer)wasKeyValueGet("pause", llGetObjectDesc())-1));
550 }
551 link_message(integer sender, integer num, string str, key id) {
552 if(id == "@npc_say")
553 osNpcSay(wasKeyValueGet("key", llGetObjectDesc()), str);
554 else if(id == "@npc_stop")
555 {
556 stop();
557 state stopped;
558 }
559 }
560 timer() {
562 if(llGetInventoryType("Stand") == INVENTORY_ANIMATION) osNpcStopAnimation(wasKeyValueGet("key", llGetObjectDesc()), "Stand");
563 llSetObjectDesc(wasKeyValueDelete("pause", llGetObjectDesc()));
564 state script;
565 }
566 changed(integer change) {
567 if(change & CHANGED_REGION_START) llResetScript();
568 }
569 on_rez(integer num) {
571 }
572 }
573
574
575 state stopped {
577 osNpcRemove(wasKeyValueGet("key", llGetObjectDesc())) ;
578 }
579
580 link_message(integer sender, integer num, string str, key id) {
581 if(id == "@npc_start")
582 {
584 }
585 }
586 }

Back to the Best Free Tools in Second Life and OpenSim.