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
Greeter Random_Greeter  

Random_Greeter

1. Put this script inside of the object you'd like to make a "random" greeter
2. Put a notecard called "SAYINGS" inside the script
* Each saying should be on one line and <= 255 characters in length
3. The script will initialise and then announce to its owner what command
channel it is listening on

Category: Greeter
By : Jamethiel Wickentower
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Random_Greeter
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Random_Greeter_1.lsl
1 // Copyright (c) 2009, David Lloyd (Jamethiel Wickentower)
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without modification,
5 // are permitted provided that the following conditions are met:
6 //
7 // Redistributions of source code must retain the above copyright notice, this list
8 // of conditions and the following disclaimer. Redistributions in binary form must
9 // reproduce the above copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided with the
11 // distribution.
12 //
13 //
14 // Neither the name of the the author nor the names of any contributor may be
15 // used to endorse or promote products derived from this software without specific
16 // prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 // *********************************************************************************
30 // Instructions:
31 //
32 // 1. Put this script inside of the object you'd like to make a "random" greeter
33 // 2. Put a notecard called "SAYINGS" inside the script
34 // * Each saying should be on one line and <= 255 characters in length
35 // 3. The script will initialise and then announce to its owner what command
36 // channel it is listening on
37 // 4. Commands are listed below
38 //
39 //
40 // Commands:
41 //
42 // "RESET"
43 //
44 // This comman causes the script to reset.
45 //
46 // "REREAD"
47 //
48 // This command causes the list of sayings to be read from the notecard again.
49 //
50 // "FIXED [number]"
51 //
52 // This command sets a fixed delay (i.e. the script will definitely delay this
53 // number of seconds). Note: you cannot set a fixed delay of less than 0.5
54 // seconds.
55 //
56 // "RANDOM [number]"
57 //
58 // This command sets a random delay; this is added to the fixed delay.
59 //
60 // "DELAYS"
61 //
62 // Reports what the current delays are.
63 //
64 // "ON" / "OFF"
65 //
66 // Turn the script on or off.
67 //
68 // "NOTECARD [name]"
69 //
70 // Sets the notecard to a notecard called "name". Make sure that notecard is in
71 // the object's inventory or the object might stop working.
72 //
73 // Known bugs:
74 //
75 // There are no known show stoppers. Do note that unless you stop and start the
76 // sayer manually, delay/random changes won't be picked up until the next timer()
77 // event.
78 //
79 // 1) User interface is a bit sparse - could do with a dialog
80 // 2) Notecard reading is quite slow - not much I can do about that though
81 //
82 // Feature Requests and Feedback:
83 //
84 // Please see my Google Code site:
85 //
86 // * http://code.google.com/p/linden-scripting-libraries/
87
88 key gOwner;
89 string gOwnerName;
90
91 integer CHANNEL = 0;
92 integer DEBUG = TRUE;
93
94 integer GOING = TRUE;
95
96 string gNotecard = "SAYINGS";
97 key gNotecardKey;
98
99 key gQueryID;
100 integer gLine = 0;
101
102 list gSayings;
103
104 float gFixedDelay = 5;
105 float gRandomDelay = 30;
106
107 // Trace
108 //
109 // If DEBUG is true, then trace it
110 trace(string msg) {
111 if(DEBUG == TRUE) {
112 llOwnerSay(msg);
113 }
114 }
115
116 // Clean Message
117 //
118 // Makes the message lower case and strips leading and trailing white space.
119 string clean_message(string message) {
120 return(llToUpper(llStringTrim(message, STRING_TRIM)));
121 }
122
123 // Discover Owner
124 //
125 // Gets detail about the item owner, such as KEY and NAME.
126 discover_owner() {
127 gOwner = llGetOwner();
128 gOwnerName = llKey2Name(gOwner);
129 llOwnerSay("Rezzed for " + gOwnerName);
130 }
131
132 // Setup the Public Listener
133 //
134 // This sets up the public listener.
135 setup_public_listener()
136 {
137 CHANNEL = llCeil(llFrand(99900)) + 100;
138 llOwnerSay("Listening on channel " + (string)CHANNEL);
139 llListen(CHANNEL, "", gOwner, "");
140 }
141
142 // Handle Public Message
143 //
144 // This handles public messages. This is a bit ham-fisted at the moment as it should
145 // start some type of IM with the avatar or open up a random chat channel. That will
146 // be implemented later.
147 handle_public_message(string message, string name, key id) {
148 string theMessage = clean_message(message);
149
150 if(id != gOwner) {
151 return;
152 }
153
154 // Here we start parsing commands that may have more than one word
155 list words = llParseString2List(theMessage, [" ", ","], []);
156 integer len = llGetListLength(words);
157 string command = clean_message(llList2String(words, 0));
158
159 if(command == "RESET") {
161 return;
162 }
163
164 if(command == "REREAD") {
165 gSayings = [];
166 gLine = 0;
167 read_sayings();
168 return;
169 }
170
171 if(command == "SAYINGS") {
172 string message = llDumpList2String(gSayings, "\n");
173 llOwnerSay(message);
174 return;
175 }
176
177 if(command == "FIXED") {
178 llOwnerSay("FIXED");
179 float fixed_delay = llList2Float(words, 1);
180 if(fixed_delay < 0.5) {
181 llOwnerSay("You cannot have a fixed delay of less than 1/2 a second!");
182 fixed_delay = 0.5;
183 }
184
185 gFixedDelay = fixed_delay;
186 trace("Fixed delay: " + (string)gFixedDelay);
187 return;
188 }
189
190 if(command == "RANDOM") {
191 float random_delay = llList2Float(words, 1);
192 if(random_delay == 0) {
193 llOwnerSay("Possible incorrect value - double check.");
194 }
195
196 gRandomDelay = random_delay;
197 trace("Random delay: " + (string)gRandomDelay);
198 return;
199 }
200
201 if(command == "DELAYS") {
202 llOwnerSay("Fixed delay: " + (string)gFixedDelay + "\nRandom delay: " + (string)gRandomDelay);
203 return;
204 }
205
206 if(command == "TOGGLE") {
207 if(GOING == TRUE) {
208 GOING = FALSE;
209 stop_sayer();
210 llOwnerSay("Going is now false.");
211 } else {
212 GOING = TRUE;
213 start_sayer();
214 llOwnerSay("Going is now true.");
215 }
216 return;
217 }
218
219 if(command == "ON") {
220 GOING = TRUE;
221 start_sayer();
222 return;
223 }
224
225 if(command == "OFF") {
226 GOING = FALSE;
227 stop_sayer();
228 return;
229 }
230
231 if(command == "NOTECARD" && len > 1) {
232 gNotecard = llList2String(words, 1);
233
234 trace("Setting notecard to " + (string)gNotecard);
235
236 stop_sayer();
237 read_sayings();
238 return;
239 }
240
241 llOwnerSay("None implemented yet...");
242 }
243
244 // Stop Sayer
245 //
246 // Simply suspends the timer event.
247 stop_sayer() {
248 GOING = FALSE;
250 }
251
252 // Start Sayer
253 //
254 // Starts up the timer event
255 start_sayer() {
256 GOING = TRUE;
257 float delay = gFixedDelay + llFrand(gRandomDelay);
258 llSetTimerEvent(delay);
259 trace("Initial timer event delay: " + (string)delay);
260 }
261
262 // Read Sayings
263 //
264 // Reads the sayings from the first note card contained in the inventory.
265 read_sayings() {
266 gLine = 0;
267 gSayings = [];
268
269 if(gNotecard == "") {
271 }
272
273 gNotecardKey = llGetInventoryKey(gNotecard);
274
275 if(gNotecardKey == NULL_KEY) {
276 llOwnerSay("Can't find the notecard for " + gNotecard);
277 return;
278 }
279
280 llOwnerSay("Reading notecard " + gNotecard);
281 gQueryID = llGetNotecardLine((string)gNotecardKey, gLine);
282 }
283
284 // Handle Notecard Response
285 //
286 // Reads the list of sayings from the notecard.
287 handle_notecard_response(string data) {
288 if(data != EOF) {
289 if(data != "") {
290 gSayings += data;
291 }
292 gLine++;
293 gQueryID = llGetNotecardLine((string)gNotecardKey, gLine);
294 stop_sayer();
295 } else {
296 llOwnerSay("Initiated " + (string)llGetListLength(gSayings) + " sayings.");
297 start_sayer();
298 }
299 }
300
301 default {
302 state_entry() {
303 discover_owner();
304 setup_public_listener();
305 read_sayings();
306 }
307
308 listen(integer channel, string name, key id, string message) {
309 if(channel == CHANNEL) {
310 handle_public_message(message, name, id);
311 return;
312 }
313 }
314
315 dataserver(key query_id, string data) {
316 if(gQueryID == query_id) {
317 handle_notecard_response(data);
318 }
319 }
320
321 touch_start(integer total_number) {
322 if(llDetectedKey(0) == gOwner) {
323 llOwnerSay("Listening on " + (string)CHANNEL);
324 }
325 }
326
327 timer() {
328 integer length = llGetListLength(gSayings);
329 string current_saying = llList2String(gSayings, llCeil(llFrand(length - 1)));
330 llSay(0, current_saying);
331
333 float delay = gFixedDelay + llFrand(gRandomDelay);
334 llSetTimerEvent(delay);
335 }
336 }

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