root/misc/avatar_key_getter.lsl

Revision 21, 3.5 kB (checked in by max.ca..@gmail.com, 2 years ago)

Avatar Key Getter. Scans for avatars, allows you to pick from buttons to get key

Line 
1 // Avatar Key Getter
2 // THIS SNIPPET WILL SCAN AREA FOR 12 AVATARS
3 // THROW UP BUTTON CHOICES
4 // TAKE NAME CHOICE AND PASS KEY TO VAR FOR USE (in this case, llOwnerSay)
5 // IN AVATAR SELECTION FOR SCRIPTS
6
7
8 //THIS IS MY DEFAULT DEBUG BIT - I THROW IT AT THE TOP OF EVERY SCRIPT...
9 integer DEBUG_FLAG = TRUE; //set to false to turn off debugmessages
10 DEBUG(list foo) { if(DEBUG_FLAG) llOwnerSay(llList2CSV(foo)) ; } 
11
12 //GVARS
13 float GI_RANGE = 256.0; // lets future proof this sucker! - caps at 96.0 anyhow.
14
15 integer GI_SELECT_AV_HANDLE; //So you can mix with other scripts.
16 integer GI_SELECT_AV_CHANNEL = -636; //So you can mix with other scripts. This is the channel to filter for in the listen.
17
18 list    GL_AV_NAME = []; //will hold names
19 list    GL_AV_KEY = []; //will hold keys
20
21 //THIS TAKES IN A KEY
22 //RETURNS TRUE if it's owner, false otherwise
23 integer fn_check_owner(key id)
24 {
25     if ( id != llGetOwner() )
26     {
27         return FALSE; //not owner
28     }
29     else
30     {
31         return TRUE;
32     }
33 }
34
35 // This one turn on the listen only when needed.
36 // seems a bit redundant maybe, but this will allow me easy changes.
37 fn_easyDialog( key id, string message, list buttons, integer channel )
38 {
39     GI_SELECT_AV_HANDLE = llListen(channel, "", id, "");  //now we can just switch it off when done.
40    
41     llDialog( id, message,     fn_validateLength(buttons), channel);
42 }
43
44 //This function returns the names list and returns it to twelve if larger. can be adapted to any number
45 list fn_validateLength( list foo)
46 {
47     integer li_return_length = 12;
48     if( llGetListLength(foo) > li_return_length)
49     {
50             return llDeleteSubList( foo, 12, -1);
51     }
52     return foo;
53 }
54
55 default    //
56 {
57     state_entry() {
58        
59     }
60    
61     listen(integer channel, string name, key id, string message) {   
62         //turn off listen  - you may not always want to use this on off method -
63         //ie, in case of script that listens for other things and needs an open channel
64         llListenRemove(GI_SELECT_AV_HANDLE);
65
66         if(id == llGetOwner()) { //to listen for owner - just some extra insurance. You can remove if you want device to listen to anyone.
67                         if(channel == GI_SELECT_AV_CHANNEL){
68                     integer index_av = llListFindList( GL_AV_NAME, [message] );
69            
70                     if (index_av != -1) {
71                         key av_key = llList2Key( GL_AV_KEY, index_av); //this is just longhand for others
72                         //now you do whatever you want with the key! link mesage it, say it, whatever...
73                         DEBUG(["av key is", av_key]);
74                     }
75                     else {
76                             DEBUG(["Oops! Key not found. Strange..."]);
77                     }
78                         }
79         }
80     }
81    
82     on_rez(integer num) {
83         llResetScript();
84     }
85    
86     sensor(integer num_detected) {
87         integer i;
88        
89         for (i = 0; i< num_detected; i++) { //lets load up lists with avatars
90             GL_AV_NAME +=  [ llDetectedName(i)] ;
91             GL_AV_KEY +=  [ llDetectedKey(i) ] ;
92         }
93                 //Present the list of names,
94         fn_easyDialog(  llGetOwner(), "Pick an av", fn_validateLength(GL_AV_NAME), GI_SELECT_AV_CHANNEL);
95     }
96                
97     no_sensor() {
98         llOwnerSay( "No one around..." );
99     }
100        
101     touch_start(integer num) {
102         if( fn_check_owner(llDetectedKey(0) ) ) { //is it the owner who touched??
103              llSensor( "", NULL_KEY, AGENT, GI_RANGE, TWO_PI ); //SENSOR TO FIND PEOPLE
104         }
105     } 
106 }
Note: See TracBrowser for help on using the browser.