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_Automator  

NPC_Automator

From http://opensimulator.org/wiki/OSSLNPC
//This is a rough example script for most of the current NPC functionality. One of its major current deficiencies is that it doesn't track more than one created avatar at a time. Please feel free to improve it.

Category: OpenSim NPC
By : justi
Created: 2013-07-30 Edited: 2013-07-30
Worlds: OpenSim

the Zip file

Download all files for NPC_Automator
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. NPC_Automator_1.lsl
1
2 key npc;
3 integer listenChannel = 10;
4
5 default
6 {
7 // NPC manipulator adapted by justincc 0.0.3 released 20121025
9 {
10 llListen(listenChannel,"",NULL_KEY,"");
11 llSetText("Listening on " + listenChannel, <0, 255, 0>, 1);
12 llOwnerSay("Say /" + (string)listenChannel + " help for commands");
13 }
14
15 listen(integer channel, string name, key id, string msg)
16 {
17 if(msg != "")
18 {
19 list commands = llParseString2List(msg, [ " " ], []);
20 string msg0 = llList2String(commands, 0);
21 string msg1 = llList2String(commands, 1);
22 string msg2 = llList2String(commands, 2);
23 string msg3 = llList2String(commands, 3);
24
25 if(msg0 == "create")
26 {
27 if(msg1 != "")
28 {
29 string notecardName = msg1;
30
31 npc = osNpcCreate("Jane", "Doe", llGetPos() + <5, 5, 0>, notecardName);
32
33 llOwnerSay("Created npc from notecard " + notecardName);
34 }
35 else
36 {
37 llOwnerSay("Usage: create <notecard-name>");
38 }
39 }
40 else if(msg0 =="createm" && msg1 != "")
41 {
42 osOwnerSaveAppearance("appearance");
43 vector pos = llGetPos();
44 integer i;
45 for (i = 0; i < (integer)msg1; i++)
46 {
47 osNpcCreate("John", "Doe", pos + <8, 0, 0>, "appearance");
48 llSleep(1);
49 }
50 }
51 else if(msg0 == "remove" && npc != NULL_KEY)
52 {
53 osNpcSay(npc, "You will pay for this with your liiiiiivvveeessss!!!.....");
54 osNpcRemove(npc);
55 }
56 else if(msg0 == "say" && npc != NULL_KEY)
57 {
58 osNpcSay(npc, "I am your worst Nightmare!!!!");
59 }
60 else if(msg0 == "move")
61 {
62 if(msg1 != "" && msg2 != "" && npc != NULL_KEY)
63 {
64 vector delta = <(integer)msg1, (integer)msg2, 0>;
65
66 if(msg3 != "")
67 {
68 delta.z = (integer)msg3;
69 }
70
71 osNpcMoveTo(npc, osNpcGetPos(npc) + delta);
72 }
73 else
74 {
75 llOwnerSay("Usage: move <x> <y> [<z>]");
76 }
77 }
78 else if(msg0 == "moveto")
79 {
80 if(msg1 != "" && msg2 != "" && npc != NULL_KEY)
81 {
82 vector pos = <(integer)msg1, (integer)msg2, 0>;
83
84 if(msg3 != "")
85 {
86 pos.z = (integer)msg3;
87 }
88
89 osNpcMoveTo(npc, pos);
90 }
91 else
92 {
93 llOwnerSay("Usage: move <x> <y> [<z>]");
94 }
95 }
96 else if(msg0 == "movetarget" && npc != NULL_KEY)
97 {
98 osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY|OS_NPC_LAND_AT_TARGET);
99 }
100 else if(msg0 == "movetargetnoland" && npc != NULL_KEY)
101 {
102 osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY);
103 }
104 else if(msg0 == "movetargetwalk" && npc != NULL_KEY)
105 {
106 osNpcMoveToTarget(npc, llGetPos() + <9,9,0>, OS_NPC_NO_FLY);
107 }
108 else if(msg0 == "rot" && npc != NULL_KEY)
109 {
110 vector xyz_angles = <0,0,90>; // This is to define a 1 degree change
111 vector angles_in_radians = xyz_angles * DEG_TO_RAD; // Change to Radians
112 rotation rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
113 rotation rot = osNpcGetRot(npc);
114 osNpcSetRot(npc, rot * rot_xyzq);
115 }
116 else if(msg0 == "rotabs" && msg1 != "")
117 {
118 vector xyz_angles = <0, 0, (integer)msg1>;
119 vector angles_in_radians = xyz_angles * DEG_TO_RAD; // Change to Radians
120 rotation rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
121 osNpcSetRot(npc, rot_xyzq);
122 }
123 else if(msg0 == "animate" && npc != NULL_KEY)
124 {
125 osAvatarPlayAnimation(npc, "stabbed+die_2");
126 llSleep(3);
127 osAvatarStopAnimation(npc, "stabbed+die_2");
128 }
129 else if(msg0 == "save" && msg1 != "" && npc != NULL_KEY)
130 {
131 osNpcSaveAppearance(npc, msg1);
132 llOwnerSay("Saved appearance " + msg1 + " to " + npc);
133 }
134 else if(msg0 == "load" && msg1 != "" && npc != NULL_KEY)
135 {
136 osNpcLoadAppearance(npc, msg1);
137 llOwnerSay("Loaded appearance " + msg1 + " to " + npc);
138 }
139 else if(msg0 == "clone")
140 {
141 if(msg1 != "")
142 {
144 llOwnerSay("Cloned your appearance to " + msg1);
145 }
146 else
147 {
148 llOwnerSay("Usage: clone <notecard-name-to-save>");
149 }
150 }
151 else if(msg0 == "stop" && npc != NULL_KEY)
152 {
154 }
155 else if(msg0 == "sit" && msg1 != "" && npc != NULL_KEY)
156 {
157 osNpcSit(npc, msg1, OS_NPC_SIT_NOW);
158 }
159 else if(msg0 == "stand" && npc != NULL_KEY)
160 {
161 osNpcStand(npc);
162 }
163 else if(msg0 == "help")
164 {
165 llOwnerSay("Commands are:");
166 llOwnerSay("create <notecard-name> - Create NPC from a stored notecard");
167 llOwnerSay("createm");
168 llOwnerSay("remove - Remove current NPC");
169 llOwnerSay("clone <notecard-name> - Clone own appearance to a notecard");
170 llOwnerSay("load <notecard-name> - Load appearance on notecard to current npc");
171 llOwnerSay("save <notecard-name> - Save appearance of current NPC to notecard");
172 llOwnerSay("animate");
173 llOwnerSay("move");
174 llOwnerSay("moveto <x> <y> <z> - move to absolute position");
175 llOwnerSay("movetarget");
176 llOwnerSay("movetargetnoland");
177 llOwnerSay("movetargetwalk");
178 llOwnerSay("rot");
179 llOwnerSay("say");
180 llOwnerSay("sit <target-uuid>");
181 llOwnerSay("stop");
182 llOwnerSay("stand");
183 }
184 else
185 {
186 llOwnerSay("I don't understand [" + msg + "]");
187 }
188 }
189 }
190 }

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