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
Scanner Language Scanner  

Language Scanner

HUD to show the language and name of any nearby avatars

Category: Scanner
By : Ferd Fredderix
Created: 2013-09-06 Edited: 2013-09-04
Worlds: Second Life

the Zip file

Download all files for Language Scanner
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.

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
2 integer SENSOR_CHANNEL = -71; // the sensor channel
3 list Avatar_List = []; // list of names we detected and info we need later
4 // distance, name, language, abbreviataion, key
5 // Distance is first, so we can sort by it
6
7 //integer AVATAR_DISTANCE = 0; // not needed Avatar_List += distance; (float)
8 integer AVATAR_NAME = 1; // Avatar_List += name; (string)
9 integer AVATAR_LANG = 2; // Avatar_List += lang; (string)
10 integer AVATAR_ABBR = 3; // Avatar_List += abbr; (string)
11 integer STRIDE = 4; // size of data we store to keep track of languages and distances
12
13 string MENU_ShowAll = "Show All"; // Menu Items
14 string MENU_scanning_on_off = "Scanner On";
15 string MENU_range = "Short Range";
16 string abbreviation; // temp storage
17
18 integer listener ;
19 integer listening = FALSE;
20
21 string OwnerLang = "en"; // viewer language at startup = english.
22 string MyAvatarName ; //place to ghold this, once, to save the system calls in a loop
23 integer channel;
24
25
26
27 DEBUG(string msg)
28 {
29 if(FALSE)
30 llOwnerSay(msg);
31 }
32
33
34 string left(string src, string divider) {
35 integer index = llSubStringIndex( src, divider );
36 if(~index)
37 return llDeleteSubString( src, index , -1);
38 return src;
39 }
40
41 string right(string src, string divider) {
42 integer index = llSubStringIndex( src, divider );
43 if(~index)
44 return llDeleteSubString( src, 0, index + llStringLength(divider) - 1);
45 return src;
46 }
47
48 // from the wiki, deletes one item in a strided list
49 list ListStridedRemove(list src, integer start, integer end, integer stride)
50 {
51 return llDeleteSubList(src, start * stride, (stride * (end + 1)) - 1);
52 }
53
54 // Add language to the list
55 SetLang(string name, string abbr, integer distance, key avikey, integer UpdateLang)
56 {
57 ////DEBUG("name:" + name + "abbr:" + abbr + " dist:" + (string) distance );
58
59 string lang = ConvertLanguage(abbr);
60
61
62 ////DEBUG("name:" + name + "abbr:" + abbr + " lang:" + lang );
63 // find it in the list, update the language distance if they speak
64
65 integer placeinlist = llListFindList(Avatar_List, [name]);
66 if(placeinlist > 0 )
67 {
68 //////DEBUG(name + " was located at " + (string) ( placeinlist + 1) + " speaking " + lang);
69
70 if(llStringLength(lang) > 0 && UpdateLang)
71 Avatar_List = llListReplaceList(Avatar_List, [lang], placeinlist + 1 , placeinlist + 1); // replace lang, +1 offset from name
72
73 if(llStringLength(abbreviation) > 0 && UpdateLang)
74 Avatar_List = llListReplaceList(Avatar_List, [abbreviation], placeinlist + 2 , placeinlist + 2); // replace abbr, +2 offset from name
75
76 if(distance > 0 )
77 {
78 Avatar_List = llListReplaceList(Avatar_List, [distance], placeinlist -1 , placeinlist -1); // replace abbr, +2 offset from name
79 }
80 }
81 else
82 {
83 if(avikey != NULL_KEY) // only add scanned avatars
84 {
85 Avatar_List += distance;
86 Avatar_List += name;
87 Avatar_List += lang; // +1 from name
88 Avatar_List += abbreviation;// +2 from name
89 Avatar_List += avikey;
90 }
91 }
92 }
93
94
95
96 ClearDisplay()
97 {
98 Avatar_List = [];
99 UpdateDisplay();
100 }
101
102
103
104 string ConvertLanguage(string abbr)
105 {
106 abbr = llToLower(abbr);
107
108 abbreviation = abbr; // stash the original, we will override it in some case
109
110
111 string lang;
112
113 if(abbr=="???")
114 lang = "?"; // unknown
115
116 if(abbr != "zh-CN" && abbr != "zh-TW") // V2
117 {
118 abbr = llGetSubString( abbr, 0, 1); // use 2 digits for all but chinese
119
120 if(abbr=="al" || abbr=="sq")
121 {
122 lang = "Albanian";
123 }
124 else if(abbr=="am") lang = "Amharic"; // detect
125 else if(abbr=="af") lang = "Afrikaans"; // V2 detect MSFT
126 else if(abbr=="hy") lang = "Armenian"; // detect
127 else if(abbr=="ar") lang = "Arabic"; // detect
128 else if(abbr=="az") lang = "Azerbaijania"; // detect
129 else if(abbr=="eu") lang = "Basque"; // detect
130 else if(abbr=="be") lang = "Belarusian"; // V2 detect
131 else if(abbr=="bn") lang = "Bengali"; // detect
132 else if(abbr=="bh") lang = "Bihari"; // detect
133 else if(abbr=="bg") lang = "Bulgarian"; // V2 PAIR
134 else if(abbr=="my") lang = "Burmese"; // detect
135 else if(abbr=="ca") lang = "Catalan"; // V2 PAIR
136 else if(abbr=="ch") lang = "Cherokee"; // detect
137 else if(abbr=="hr") lang = "Croatian"; // V2 PAIR
138 else if(abbr=="cs") lang = "Czech"; // V2 PAIR
139 else if(abbr=="da") lang = "Danish"; // V2 PAIR
140 else if(abbr=="nl") lang = "Dutch"; // V2 PAIR
141 else if(abbr=="en") lang = "English"; // V2 PAIR
142 else if(abbr=="dv") lang = "Dhiveli"; // detect
143 else if(abbr=="eo") lang = "Esperanto"; // detect
144 else if(abbr=="et") lang = "Estonian"; // V2 PAIR
145 else if(abbr=="fo") lang = "Faeroese"; // detect
146 else if(abbr=="fa") lang = "Persian"; // V2 detect
147 else if(abbr=="tl")
148 {
149 lang = "Tagalog";
150 } // V2 PAIR ODD
151 else if(abbr=="fi") lang = "Finnish"; // V2 PAIR
152 else if(abbr=="fr") lang = "French"; // V2 PAIR
153 else if(abbr=="gd") lang = "Gaelic"; // V2 detect
154 else if(abbr=="gl") lang = "Irish"; // V2 PAIR
155 else if(abbr=="ka") lang = "Georgian"; // detect
156 else if(abbr=="de") lang = "German"; // V2 PAIR
157 else if(abbr=="el") lang = "Greek"; // V2 PAIR
158 else if(abbr=="gn") lang = "Guarani"; // PAIR
159 else if(abbr=="gu") lang = "Guajarati"; // V2 detect
160 else if(abbr=="iw" || abbr=="he" )
161 {
162 lang = "Hebrew";
163 } // PAIR takes IW, s/l takes iw
164 else if(abbr=="hi") lang = "Hindi"; // V2 PAIR
165 else if(abbr=="hu") lang = "Hungarian"; // V2 PAIR
166 else if(abbr=="is") lang = "Icelandic"; // V2 PAIR
167 else if(abbr=="id") lang = "Indonesian"; // V2 PAIR
168 else if(abbr=="iu") lang = "Inuktitut"; // detect
169 else if(abbr=="it") lang = "Italian"; // V2 PAIR
170 else if(abbr=="ja") lang = "Japanese"; // V2 PAIR
171 else if(abbr=="kn") lang = "Kannada"; // detect
172 else if(abbr=="kk") lang = "Kazakh"; // detect
173 else if(abbr=="km") lang = "Khmer"; // detect
174 else if(abbr=="ko") lang = "Korean"; // V2 PAIR
175 else if(abbr=="ku") lang = "Kurdish"; // detect
176 else if(abbr=="ky") lang = "Kyrgyz"; // detect
177 else if(abbr=="lo") lang = "Laotian"; // detect
178 else if(abbr=="lv") lang = "Latvian"; // V2 PAIR
179 else if(abbr=="lt") lang = "Lithuanian"; // V2 PAIR
180 else if(abbr=="mk") lang = "Macedonian"; // V2 detect
181 else if(abbr=="ms") lang = "Malay"; // V2 detect
182 else if(abbr=="ml") lang = "Malayalam"; // detect
183 else if(abbr=="mt") lang = "Maltese"; // V2 PAIR
184 else if(abbr=="mr") lang = "Marathi"; // detect
185 else if(abbr=="mn") lang = "Mongolian"; // detect
186 else if(abbr=="ne") lang = "Nepali"; // detect
187 else if(abbr=="nb" || abbr == "no" )
188 {
189 lang = "Norwegian";
190 } // V2 PAIR 'no' = google
191 else if(abbr=="or") lang = "Oriya"; // detect
192 else if(abbr=="ps") lang = "Pashto"; // detect
193 else if(abbr=="pl") lang = "Polish"; // V2 PAIR
194 else if(abbr=="pt")
195 {
196 lang = "Portugese";
197 } // PAIR V2 google uses pt-PT
198 else if(abbr=="pa") lang = "Punjabi"; // detect
199 else if(abbr=="ro") lang = "Romanian"; // V2 PAIR
200 else if(abbr=="rm") lang = "Romanic"; // PAIR
201 else if(abbr=="ru") lang = "Russian"; // V2 PAIR
202 else if(abbr=="sa") lang = "Sanskrit"; // detect
203 else if(abbr=="sr") lang = "Serbian"; // V2 PAIR
204 else if(abbr=="sb") lang = "Sorbian"; // detect
205 else if(abbr=="sd") lang = "Sindhi"; // detect
206 else if(abbr=="si") lang = "SinHalese"; // detect
207 else if(abbr=="sk") lang = "Slovak"; // V2 PAIR
208 else if(abbr=="sl") lang = "Slovenian"; // V2 PAIR
209 else if(abbr=="es") lang = "Spanish"; // V2 PAIR
210 else if(abbr=="sw") lang = "Swahili"; // V2 detect
211 else if(abbr=="sv") lang = "Swedish"; // V2 detect
212 else if(abbr=="sx") lang = "Sutu"; // detect
213 else if(abbr=="sz") lang = "Sami"; // detect
214 else if(abbr=="tg") lang = "Tajik"; // detect
215 else if(abbr=="ta") lang = "Tamil"; // detect
216 else if(abbr=="tl") lang = "Tagalog"; // V2 PAIR
217 else if(abbr=="ts") lang = "Tsonga"; // detect
218 else if(abbr=="te") lang = "Telugu"; // detect
219 else if(abbr=="th") lang = "Thai"; // V2 PAIR
220 else if(abbr=="tn") lang = "Tswana"; // detect
221 else if(abbr=="bo") lang = "Tibetan"; // detect
222 else if(abbr=="uk") lang = "Ukranian"; // V2 detect
223 else if(abbr=="uz") lang = "Uzbek"; // detect
224 else if(abbr=="ug") lang = "Uighur"; // detect
225 else if(abbr=="bo") lang = "Tibetan"; // detect
226 else if(abbr=="tr") lang = "Turkish"; // V2 PAIR
227 else if(abbr=="ur") lang = "Urdu"; // detect
228 else if(abbr=="ve") lang = "Venda"; // detect
229 else if(abbr=="vi") lang = "Vietnamese"; // V2 PAIR
230 else if(abbr=="ji") lang = "Yiddish"; // V2 PAIR
231 else if(abbr=="cy") lang = "Welsh"; // V2 PAIR
232 else if(abbr=="zu") lang = "Zulu"; // PAIR
233 else
234 {
235 lang = abbr;
236 }
237 }
238
239 return lang;
240 }
241
242
243 // Display the scanner
244 UpdateDisplay()
245 {
246 Avatar_List = llListSort(Avatar_List,STRIDE,TRUE); // sort by range from near to far
247 integer listLength = llGetListLength(Avatar_List);
248
249 string result;
250 integer i;
251 integer count;
252
253
254
255 for( i=0;i<listLength;i+=STRIDE)
256 {
257 integer distance = llList2Integer(Avatar_List,i);
258 string name = llList2String(Avatar_List,i+AVATAR_NAME);
259
260 string abbr = llList2String(Avatar_List,i+AVATAR_ABBR);
261
262 name = left(name," "); // show first name only
263
264 // some abbreviations need to be commonized
265 string language = ConvertLanguage(abbr);
266 string ToAdd = name + " [" + (string)distance + "m] [" + language + "]\n";
267
268 if(llStringLength(ToAdd) + llStringLength(result) < 240 ) // 254 is the max length of hover text
269 {
270 if( MENU_ShowAll == "Show All" )
271 {
272 result += ToAdd;
273 count++;
274 }
275 else
276 {
277 if( abbr != OwnerLang && abbr != "???" )
278 {
279 result += ToAdd;
280 count++;
281 }
282 }
283 }
284 }
285
286 if(MENU_scanning_on_off == "Scanner On")
287 {
288 result = (string) (count) + " Avatars\n" + result;
289 llSetText(result,<1,1,1>,1.0);
290 }
291 }
292
293
294 Menu()
295 {
296
297 if(! listening)
298 {
299 listener = llListen(channel,"",llGetOwner(),"");
300 }
301 listening = TRUE;
302
303 list menu = [MENU_ShowAll] + [MENU_scanning_on_off] + [MENU_range] ;
304 llDialog(llGetOwner(),"Free Memory:" + (string) llGetFreeMemory() + "\nAll Language/Other Languages\nOn/Off\nLong/Short range",menu,channel);
306 }
307
308
309 default
310 {
312 {
313 channel = (integer) llFrand((10000) + 20000);
314 MyAvatarName = llKey2Name(llGetOwner());
315 Menu();
316 llSensorRepeat("", "",AGENT, 20, PI,1);
317 }
318
319
321 {
322 Menu();
323 }
324
325 timer()
326 {
327 listening = FALSE;
328 llListenRemove(listener);
330 }
331
332 listen(integer sender_number, string name, key id, string message)
333 {
334 if(message == "Scanner Off")
335 {
336 llSetText("Scanning",<1,1,1>,1.0);
337 {
338 if(MENU_range == "Short Range")
339 {
340 llSensorRepeat("", "",AGENT, 20, PI,1);
341 }
342 else
343 {
344 llSensorRepeat("", "",AGENT, 96, PI,1);
345 }
346 }
347 MENU_scanning_on_off = "Scanner On";
348 llOwnerSay("Scanning...");
349 }
350 else if(message == "Scanner On")
351 {
352 MENU_scanning_on_off = "Scanner Off";
353 ClearDisplay();
354 llSetText("Off",<1,1,1>,1.0);
356 }
357 else if(message == "Long Range")
358 {
359 MENU_range = "Short Range";
360 llSensorRepeat("", "",AGENT, 20, PI,1);
361 llOwnerSay("Scanning 20 meters (chat range)");
362 }
363 else if(message == "Short Range")
364 {
365 MENU_range = "Long Range";
366 llSensorRepeat("", "",AGENT, 96, PI,1);
367 llOwnerSay("Scanning 96 meters");
368 }
369 else if(message == "Show Other")
370 {
371 MENU_ShowAll = "Show All";
372 llOwnerSay("Showing all languages");
373 }
374 else if(message == "Show All")
375 {
376 MENU_ShowAll = "Show Other";
377 llOwnerSay("Showing other languages");
378 }
379
380
381 Menu();
382
383 }
384
385
386 sensor(integer num_detected)
387 {
388 integer i;
389 string name;
390 integer distance;
391
392 //DEBUG("Detected:" + (string) num_detected);
393
394 vector pos = llGetPos();
395
396 list present = []; // people that are here
397
398 for(i=0;i<num_detected;i++)
399 {
400 name = llKey2Name(llDetectedKey(i));
401 if(llStringLength(name) > 0) // some ghosted avatars show up on scanner with NO NAME
402 {
403 if(name != MyAvatarName )
404 {
406
407 ////DEBUG( name + "[" + lang + "]");
408
409
410 if(lang == "" )
411 lang = "???";
412
413
414 vector detPos = llDetectedPos(i);
415 distance = (integer)llVecDist(pos, detPos);
416
417
418 ////DEBUG("Sensed:" + name);
419 //SetLang(string name, string abbr, integer distance, key avikey)
420
421
422 SetLang(name,lang,distance,llDetectedKey(i), FALSE); //
423 present += name;
424
425
426 }
427 }
428 // else is me
429 }
430
431 // remove anybody out of range
432
433 for(i=0; i < llGetListLength(Avatar_List) ;i+= STRIDE)
434 {
435 name = llList2String(Avatar_List,i+1);
436
437 if( llListFindList(present, [name]) == -1 )
438 {
439 ////DEBUG("Removing:" + name + " index: " + (string) i); /// ******
440
441 Avatar_List = ListStridedRemove(Avatar_List, i/ STRIDE, i/STRIDE, STRIDE);
442 i -= STRIDE; // redo over the one we just removed
443 }
444 }
445
446
447
448 if(num_detected == 0)
449 llSetText("0 Avatars",<1,1,1>,1.0);
450
451 UpdateDisplay();
452 llSleep(1.0);
453 llSensorRepeat("", "",AGENT, 96, PI,1);
454
455 }
456
457 on_rez(integer start_param)
458 {
459
461 }
462
463
464 no_sensor()
465 {
466
467 //DEBUG("0");
468 ClearDisplay();
469 llSetText("0 Avatars",<1,1,1>,1.0);
470 }
471
472
473
474 }

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