teresasama Posted March 12, 2018 Share Posted March 12, 2018 Hello, I wanna make a list of usernames which checks if there's any matches with avatars in the same sim, I'm not good at scripting but I guess we can take advantage of llGetAgentSize(id), llSetTimerEvent(0.1) and timer() in order to keep checking the list every 0.1 ms. For example: list x = ["user A", "user B", "user C"]; If user A is present, it returns to me: llOwnerSay(user A); However if more than 1 username in the list are present, it must return just 1 username either A, B or C. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 12, 2018 Share Posted March 12, 2018 First, you don't need llGetAgentSize for anything. After all, if you detect a person, you already know he's there. Just gather your list with llGetAgentList. Those will be UUIDs, but unless you really need to know all names, that should be enough. If you do need names, you can always get them from the UUIDs with llKey2Name. Second, it's overkill to query the region every 0.1 seconds. The list of people there won't change that fast, so a rapid timer is a waste of server resources. You should be able to get by with a query every 5 seconds or so. Now, I don't quite understand what you want in the end. If you have list x = ["user A", "user B", "user C"]; and you want to know if user A is among them, you can get that information by asking if (~llListFindList(x,"user A") ) { llSay(0,"I found user A"); } If you are hoping for other information from the script, explain. 1 1 Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 Let me explain better. I need to know which avatar and index was found in my list, like it's gonna be a big list with 50 usernames, llGetAgentList will get all avatars keys in the sim right? So if it finds 1 or more usernames/keys which are in my list, it must return the username from the respective index which was found in my list, so i can know which avatar was found among the others. Get it? Link to comment Share on other sites More sharing options...
Innula Zenovka Posted March 13, 2018 Share Posted March 13, 2018 (edited) @teresasama Take a look at the userfunction ListXandY in the wiki: Quote This function examines two lists, and returns a new list composed of the elements that both lists have in common. Sounds like what you need. ETA: I would, though, make one small but important alteration to that example. Where it says for (x = 0; x < llGetListLength(ly); x++) { I would put integer n = llGetListLength(ly); for (x = 0; x < n; x++) { The reason is that the length of ly isn't going to change while the script is running through the loop checking its members, so it's a waste of resources (and it slows down the script) to keep on counting the number of items in list y every time you check an item from list x against it. Edited March 13, 2018 by Innula Zenovka 1 1 Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 16 minutes ago, Innula Zenovka said: @teresasama Take a look at the userfunction ListXandY in the wiki: Sounds like what you need. ETA: I would, though, make one small but important alteration to that example. Where it says for (x = 0; x < llGetListLength(ly); x++) { I would put integer n = llGetListLength(ly); for (x = 0; x < n; x++) { The reason is that the length of ly isn't going to change while the script is running through the loop checking its members, so it's a waste of resources (and it slows down the script) to keep on counting the number of items in list y every time you check an item from list x against it. That's what I'm looking for! Thanks Innula Zenovka. Just a final touch to get this done. ListXandY returns me a new list right? I wanna get the first index with the avatar username/key of that list. How to get like the first avatar/key from a list? For example if there're 10 usernames in common, I just want the first username no matter how it is sorted by. So I need to get the first index + username from that list. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 13, 2018 Share Posted March 13, 2018 The first element in any list is always element 0. So, string strName = llList2String(my_list_of_names,0); 1 Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 (edited) @Rolig Loon 1 hour ago, Rolig Loon said: The first element in any list is always element 0. So, string strName = llList2String(my_list_of_names,0); Thanks Rolig Loon. I'm gonna use llKey2Name(llList2Key(my_list, 0)); so I can get the first element which is a key then convert it to a username. Edited March 13, 2018 by teresasama Link to comment Share on other sites More sharing options...
Innula Zenovka Posted March 13, 2018 Share Posted March 13, 2018 If you want the username it's llGetUsername, not llKey2Name. llGetUsername will return "teresasama" and "Innula.zenovka". llKey2Name will return "teresasama resident" or "Innula Zenovka". 1 Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 @Innula Zenovka 13 minutes ago, Innula Zenovka said: If you want the username it's llGetUsername, not llKey2Name. llGetUsername will return "teresasama" and "Innula.zenovka". llKey2Name will return "teresasama resident" or "Innula Zenovka". I was about to make a method to strip the "Resident" out of it, I'm glad you told me about the llGetUsername, thanks a lot Innula Zenovka. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 13, 2018 Share Posted March 13, 2018 Well, for completeness, you can also request llGetDisplayName(). Which one of the functions you use depends on exactly what you need the name for. (Also, there are the functions llRequestUsername() and llRequestDisplayName(), which you would need to use if the person you are considering is not in the same region.) 2 Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 @Innula Zenovka @Rolig Loon This code compiles but for some reason it doesn't work. The avatar keys from my_list they were present in the same sim, so I expected a message coming from llOwnerSay() but nothing happened. list my_list = ["43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "369fac38-c0e6-4c65-b7ca-ff6da91c3d94"]; list ListXandY(list lx, list ly) { // return a list of elements common to both lists list lz = []; integer x; integer n = llGetListLength(ly); for (x = 0; x < n; x++) { if (~llListFindList(lx,llList2List(ly,x,x))) { lz = lz + llList2List(ly,x,x); } else { ; } } return lz; } default { touch_start(integer total_number) { list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); list result = ListXandY(avatarsInRegion, my_list); llOwnerSay(llGetUsername(llList2Key(result, 0))); } } Link to comment Share on other sites More sharing options...
Xiija Posted March 13, 2018 Share Posted March 13, 2018 (edited) anyhoo, this seems to be workin for me? ( my key is the one ... 06451596-818c-4975-8bc0-058ab2fe8274) list my_list = [ "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "369fac38-c0e6-4c65-b7ca-ff6da91c3d94", "06451596-818c-4975-8bc0-058ab2fe8274", // ME "be7f208e-a4ac-4073-b4eb-277d8581b13e" ]; list ListXandY(list myList, list scanList ) { // return a list of elements common to both lists list lz = []; integer x; integer n = llGetListLength( scanList ); for (x = 0; x < n; x++) { if (~llListFindList( myList, llList2List( scanList, x, x))) { lz += llList2List( scanList, x, x); } } return lz; } default { touch_start(integer total_number) // used "scan" to test { list scan = [ "369fac38-c0e6-4c65-b7ca-ff6da91c3d94", "06451596-818c-4975-8bc0-058ab2fe8274", // ME "be7f208e-a4ac-4073-b4eb-277d8581b13e"]; list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); list result = ListXandY( my_list, scan ); // REPLACE scan WITH avatarsInRegion list names ; integer y; for(; y < llGetListLength(result) ; ++y) { key currKEY = llList2Key(result,y); names += llGetUsername( currKEY ) ; } string tmp = llDumpList2String( names, "\n"); llOwnerSay( "\nFound: \n" + tmp ); } } Edited March 13, 2018 by Xiija Link to comment Share on other sites More sharing options...
Love Zhaoying Posted March 13, 2018 Share Posted March 13, 2018 28 minutes ago, Xiija said: anyhoo, this seems to be workin for me? ( my key is the one ... 06451596-818c-4975-8bc0-058ab2fe8274) list my_list = [ "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "369fac38-c0e6-4c65-b7ca-ff6da91c3d94", "06451596-818c-4975-8bc0-058ab2fe8274", // ME "be7f208e-a4ac-4073-b4eb-277d8581b13e" ]; list ListXandY(list myList, list scanList ) { // return a list of elements common to both lists list lz = []; integer x; integer n = llGetListLength( scanList ); for (x = 0; x < n; x++) { if (~llListFindList( myList, llList2List( scanList, x, x))) { lz += llList2List( scanList, x, x); } } return lz; } default { touch_start(integer total_number) // used "scan" to test { list scan = [ "369fac38-c0e6-4c65-b7ca-ff6da91c3d94", "06451596-818c-4975-8bc0-058ab2fe8274", // ME "be7f208e-a4ac-4073-b4eb-277d8581b13e"]; list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); list result = ListXandY( my_list, scan ); // REPLACE scan WITH avatarsInRegion list names ; integer y; for(; y < llGetListLength(result) ; ++y) { key currKEY = llList2Key(result,y); names += llGetUsername( currKEY ) ; } string tmp = llDumpList2String( names, "\n"); llOwnerSay( "\nFound: \n" + tmp ); } } Whoo-Hoo, Free Keys!! Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 @Xiija It's not working with llGetAgentList(). Well looks like it's complex, you can try this code in world it won't work, but if you're gonna try it don't forget to change the keys for the avatar keys in the same region you're in. list my_list = [ "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "7a6b9c04-b610-4017-9982-80962eda2619" ]; list ListXandY(list myList, list scanList ) { // return a list of elements common to both lists list lz = []; integer x; integer n = llGetListLength( scanList ); for (x = 0; x < n; x++) { if (~llListFindList( myList, llList2List( scanList, x, x))) { lz += llList2List( scanList, x, x); } } return lz; } default { touch_start(integer total_number) { list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); list result = ListXandY(my_list, avatarsInRegion); list names; integer y; for(; y < llGetListLength(result) ; ++y) { key currKEY = llList2Key(result,y); names += llGetUsername( currKEY ); } string tmp = llDumpList2String( names, "\n"); llOwnerSay( "\nFound: \n" + tmp ); } } Link to comment Share on other sites More sharing options...
Love Zhaoying Posted March 13, 2018 Share Posted March 13, 2018 I suggest that you say the result of llGetAgentList to chat so you can see if it is getting the info or not. After the call to llGetAgentList, add this line to debug it: llOwnerSay(“List result=“ + llList2CSV(result)); This will show you what is in the list after llGetAgentList. Also, in your touch_start event I noticed you are not initializing y to zero. 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 13, 2018 Share Posted March 13, 2018 2 hours ago, Love Zhaoying said: Also, in your touch_start event I noticed you are not initializing y to zero. No need. The variable y is local to touch_start, so it's a brand new variable each time execution enters that event, automatically set = 0. 1 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted March 13, 2018 Share Posted March 13, 2018 4 minutes ago, Rolig Loon said: No need. The variable y is local to touch_start, so it's a brand new variable each time execution enters that event, automatically set = 0. C’mon, at least agree it’s a bad habit! Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 13, 2018 Share Posted March 13, 2018 Nah. Not in LSL. In fact, it takes more memory to deliberately initialize a variable like that. It's redundant, unless you are dealing with global variables. 1 Link to comment Share on other sites More sharing options...
Xiija Posted March 13, 2018 Share Posted March 13, 2018 (edited) It's the old ...list functions don't like Humans ( or other lists )... trick! changed the string stuff in the.... 'for' statement in the user function . list my_list = [ "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "7a6b9c04-b610-4017-9982-80962eda2619", "06451596-818c-4975-8bc0-058ab2fe8274" // Xiija ]; list ListXandY(list myList, list scanList ) { list lz = []; integer x; integer n = llGetListLength( scanList ); for (x = 0; x < n; x++) { string new = llList2String(scanList, x); if (~llListFindList( myList,[new] ) ) { string avi = llList2String( llList2List( scanList, x, x) , 0 ); lz += avi; } } return lz; } default { touch_start(integer total_number) { list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); list result = ListXandY(my_list, avatarsInRegion); list names; integer y; for(; y < llGetListLength(result) ; ++y) { key currKEY = llList2Key(result,y); names += llGetUsername( currKEY ); } if( names != [] ) { string tmp = llDumpList2String( names, "\n"); llOwnerSay( "\nAvatar Found: \n" + tmp ); } else llOwnerSay( "\nNO Avatars Found" ); } } Edited March 13, 2018 by Xiija 1 Link to comment Share on other sites More sharing options...
teresasama Posted March 13, 2018 Author Share Posted March 13, 2018 @Xiija 1 hour ago, Xiija said: It's the old ...list functions don't like Humans ( or other lists )... trick! changed the string stuff in the.... 'for' statement in the user function . list my_list = [ "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "7a6b9c04-b610-4017-9982-80962eda2619", "06451596-818c-4975-8bc0-058ab2fe8274" // Xiija ]; list ListXandY(list myList, list scanList ) { list lz = []; integer x; integer n = llGetListLength( scanList ); for (x = 0; x < n; x++) { string new = llList2String(scanList, x); if (~llListFindList( myList,[new] ) ) { string avi = llList2String( llList2List( scanList, x, x) , 0 ); lz += avi; } } return lz; } default { touch_start(integer total_number) { list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []); list result = ListXandY(my_list, avatarsInRegion); list names; integer y; for(; y < llGetListLength(result) ; ++y) { key currKEY = llList2Key(result,y); names += llGetUsername( currKEY ); } if( names != [] ) { string tmp = llDumpList2String( names, "\n"); llOwnerSay( "\nAvatar Found: \n" + tmp ); } else llOwnerSay( "\nNO Avatars Found" ); } } Thank you very much Xiija, everything is working as intended. Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now