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 Opensim_NPC_Recorder  

Opensim_NPC_Recorder

OpenSim only.
This NPC script is used to make the 'appearance' notecard and 'Script' notecard for the Wizardry and Steamworks NPC controller script.
Put the script into a prim, and wear it as a HUD. When you first wear it, a menu will appear. You may touch the prim to bring up the menu.

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

the Zip file

Download all files for Opensim_NPC_Recorder
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Opensim_NPC_Recorder_1.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // Author: Ferd Frederiz
2 // 7-28-2013 Rev 1
3 // Mods: none
4
5 // This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
6 // http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
7 // You may use this for sanything as long as you do not sell the script.
8 // Please support Open source by crediting any authors of these scripts and sharing any improvement with the community.
9
10 // Dialog menu that appears:
11 // Help: Brings you to a help web page.
12 // Erase: Deletes the memory of the recorder so you can start over. It does not delete any notecards.
13 // Stop NPC: Prompts you for the name of a NPC to stop. If located, it will be removed from the world. This script does not create NPC's or control them. The W&S Controller script does that. But if you have used this to create an NPC and are testing it, this can be used to remove the NPC.
14 // Appearance: This button records your appearance into an 'appearance' notecard. This card is used by the W&S scripts to make the NPC appear exactly as you are. An NPC is not exactly the same as an Avatar. For example, if you are wearing a AO, the AO will be able to animate the NPC. You must use the recorder to move the NPC and to animate it.
15 // Save: Will ask you to stand where you want the NPC to appear and will prompt you for a name of the NPC. The name does not have to be an OpenSim avatar name, and thus can be any name. The notecard "Script" will be created with all recordings saved in it.
16 // Recording: Brings up a menu of NPC actions you can make.
17
18 // Recording Menu:
19 // @walk records the current position of your avatar for the NPC to walk to.
20 // @wander will prompt for a radius to wander, and a length of time to wander
21 // @say will prompt for something for the NPC to say in chat
22 // @pause will prompt for a number of seconds to pause in one place
23 // @rotate will prompt for a rotation in degrees. Negative degrees, such as '-90', will rotate to the left.
24 // @sit will prompt you for the name of a prim to sit on. The prim must be with 96 meters of the NPC.
25 // @stand will make the NPC stand up after sitting.
26 // @animate will prompt for the name of an animation and a time for the animation to play. The animation must be stored in the same object that holds the W&S controller script
27
28
29 // Typical 'Script' notecard
30 //@spawn=Digit Gorilla|<645, 128, 25>
31 //@walk=<645, 120, 25>
32 //@wander=3|1
33 //@say=omg, walking is so tiresome...
34 //@pause=2
35 //@rotate|degrees
36 //@sit|object
37 //@stand
38 //@animate|animation
39
40
41 // comment these lines out for Opensim, leave uncommented for testing in LSLEditor
42 osAgentSaveAppearance(key avatar, string notecard) {}
43 osNpcRemove (key target) {llOwnerSay("NPC removed");}
44 list osGetAvatarList () { return ["1234"];}
45 osMakeNotecard(string notecardName, string contents) {llOwnerSay("Notecard::" + (string) contents);}
46
47
48 // globals
49 integer channel;
50 integer handle;
51
52 // NPC
53
54 string NPCName; // the name of the NPC that may be in world. So we can remove it.
55 integer NPC_STOP = FALSE; // boolean to reuse a listener
56
57 // menus
58 list lCmdButtons = ["Appearance","Recording","Save","Help","Erase","Stop NPC"];
59 list lGoButtons = ["Menu","@say","@walk","@wander","@pause","@rotate","@sit","@stand","@animate"];
60
61
62 // the commands
63 list lCommands; // commands are stored here
64 string notecard; // commands are stored here temporarily for dumping
65 string command; // place to stor a command for two-prompted ones
66 string Param2; // place to stor a primpt for two-prompted ones
67
68 // Kill a NPC by Name
69
70 Kill(string NPCName)
71 {
72 list avatars = osGetAvatarList(); // Returns a strided list of the UUID, position, and name of each avatar in the region except the owner.
73 integer i;
74 integer count;
75 integer j = llGetListLength(avatars)/3;
76 for (; i < j; i+=3) // stride of 3
77 {
78 if(llList2String(avatars,i+2) == NPCName)
79 {
80 vector v = llList2Vector(avatars,i+1);
81 key target = llList2Key(avatars,i); // get the UUID of the avatar
82 osNpcRemove(target);
83 llOwnerSay("Rmoved " + NPCName + " at location " + (string) v);
84 count++;
85 }
86 }
87 if(! count)
88 llOwnerSay("Could not locate " + NPCName);
89 }
90
91
92 // return the position we are at, less half the avatar heght as this is worn as a HUD.
93 string Pos()
94 {
96 float h = size.z;
97 vector where = llGetPos();
98 where.z -= h/2;
99 return (string) where;
100 }
101
102 // make a text box
103 makeText(string Param)
104 {
105 llListenRemove(handle);
106 channel = llCeil(llFrand(100000) + 20000);
107 handle = llListen(channel,"","","");
108 llTextBox(llGetOwner(), Param, channel);
109 }
110
111 // make a menu
112 makeMenu(list buttons)
113 {
114 llListenRemove(handle);
115 channel = llCeil(llFrand(100000) + 20000);
116 handle = llListen(channel,"","","");
117 llDialog(llGetOwner(),"Choose a command",buttons,channel);
118 }
119
120 // make one or two text boxes with prompts
121 Text(string cmd, string p1, string p2)
122 {
123 command = cmd;
124 Param2 = "";
126 Param2 = p2;
127
128 makeText(p1);
129 }
130
131
132 default
133 {
135 {
136 makeMenu(lCmdButtons);
137 }
138
139 on_rez(integer param)
140 {
141 makeMenu(lCmdButtons);
142 }
143
145 {
147 {
148 makeMenu(lCmdButtons);
149 }
150 }
151
152 listen(integer channel, string name, key id, string message)
153 {
154 if(message == "Stop NPC")
155 {
156 if(llStringLength(NPCName))
157 {
158 Kill(NPCName);
159 }
160 else
161 {
162 NPC_STOP = TRUE;
163 makeText("Enter name of an NPC to stop");
164 }
165 }
166 else if(message == "Recording")
167 {
168 state Commands;
169 }
170 else if(message == "Appearance")
171 {
172 osAgentSaveAppearance(llGetOwner(), "appearance");
173 llOwnerSay("Appearance recorded in notecard 'appearance'");
174 makeMenu(lCmdButtons);
175 }
176 else if(message == "Save")
177 {
178 state Run;
179 }
180 else if(message == "Erase")
181 {
182 lCommands = [];
183 makeMenu(lCmdButtons);
184 }
185 else if(message == "Help")
186 {
187 llLoadURL(llGetOwner(),"Click to view help","http://www.free-lsl-scripts.com/opensim/posts/NPC/");
188 }
189 else if(NPC_STOP == TRUE)
190 {
191 NPC_STOP = FALSE;
192 Kill(NPCName);
193 makeMenu(lCmdButtons);
194 }
195
196 }
197
198 }
199
200
201 state Run
202 {
204 {
205 makeText("Stand where you want the NPC to appear and enter the NPC Name");
207 }
208
209 listen(integer channel, string name, key id, string message)
210 {
212
213 NPCName = message;
214 notecard = "@spawn=" + message + "|" + Pos() + "\n";
215 integer i;
216 integer j = llGetListLength(lCommands);
217 for (; i < j; i++)
218 {
219 notecard += llList2String(lCommands,i);
220 }
221 osMakeNotecard("Script",notecard); //Makes the notecard.
222 llOwnerSay("'Script' notecard has been written");
223 makeMenu(lCmdButtons);
224 state default;
225
226 }
227 timer()
228 {
229 llOwnerSay("Menu expired");
230 makeMenu(lCmdButtons);
232 state default;
233 }
234
235 }
236
237 state Commands
238 {
240 {
241 makeMenu(lGoButtons);
242 }
243 listen(integer channel, string name, key id, string message)
244 {
246
247 if(message == "Menu")
248 {
249 state default;
250 }
251 else if(message == "@say")
252 {
253 Text("@say=","Enter what the NPC will say","");
254 }
255 else if(message == "@walk")
256 {
257 lCommands += "@walk=" + Pos() + "\n";
258 llOwnerSay("Recorded");
259 makeMenu(lGoButtons);
260 }
261 else if(message == "@wander")
262 {
263 Text("@wander=","Enter radius to wander","Enter Time to wander");
264 }
265 else if(message == "@pause")
266 {
267 Text("@pause=","Enter time to pause","");
268 }
269 else if(message == "@rotate")
270 {
271 Text("@rotate=","Enter degrees to rotate","");
272 }
273 else if(message == "@sit")
274 {
275 Text("@sit=","Enter name of object to sit on","");
276 }
277 else if(message == "@stand")
278 {
279 lCommands += "@stand\n";
280 llOwnerSay("Recorded");
281 makeMenu(lGoButtons);
282 }
283 else if(message == "@animate")
284 {
285 Text("@animate=","Enter animation name to play","Enter time to play the animation");
286 }
287 else if(! llStringLength(Param2))
288 {
289 lCommands += command + message + "\n";
290 llOwnerSay("Recorded");
291 makeMenu(lGoButtons);
292 }
293 else if(llStringLength(Param2))
294 {
295 command = command + message + "|";
296 llOwnerSay("Recorded");
297 makeText(Param2);
298 Param2 = "";
299 }
300
301 }
302 timer()
303 {
304 llOwnerSay("Menu expired");
305 makeMenu(lGoButtons);
307 }
308
309 }

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