AthenaStarfire Posted July 8, 2017 Share Posted July 8, 2017 (edited) How do I detect an avatar has entered my 1024 size parcel in LSL? Cheers Edited July 8, 2017 by AthenaStarfire Link to comment Share on other sites More sharing options...
mikka Luik Posted July 8, 2017 Share Posted July 8, 2017 Try the LSL wiki for 'visitor counter' or similar heres one http://wiki.secondlife.com/wiki/Visit_Monitor or use llGetAgentList with AGENT_LIST_PARCEL and a trigger or timer. 3 Link to comment Share on other sites More sharing options...
Ivanova Shostakovich Posted July 8, 2017 Share Posted July 8, 2017 (edited) With this function, llGetAgentList(), you can get a list of the avatars on a parcel. If you don't care who is there, or how many are there, just have it alert you, or whatever, when the list is not empty. Oh, Mikka wins. Edited July 8, 2017 by Ivanova Shostakovich Because I was slow. Link to comment Share on other sites More sharing options...
Innula Zenovka Posted July 8, 2017 Share Posted July 8, 2017 Since some people find processing and comparing lists a bit daunting (and it took me some time to learn how to do it),here's an example of how I'd approach the problem (I've just written it now and not tested it). Note that the scanner needs to be on the parcel it's checking and also that it will notify you each time an avatar enters the parcel (so if the avatar keeps on stepping on the parcel, then off it and then back on, you will be notified each time). If that's not the desired behaviour, you will need to do something more complex with strided lists, to keep track of how long the avatar has been away from the parcel, but I don't want to complicate the example unnecessarily. key kThisParcel; key k; list lOld; integer max; float fTimer = 1.0; default { state_entry() { kThisParcel = llList2Key(llGetParcelDetails(llGetPos(),[PARCEL_DETAILS_ID]),0); llSetTimerEvent(fTimer); } on_rez(integer start_param) { llResetScript(); } timer() { llSetTimerEvent(0.0);//it's my habit to turn off the timer event when processing lists in case I need to do something that sleeps the script (e.g. have the script send instant messages or emails) if(lOld != []){//if there was anyone on the list last time I looked max = llGetListLength(lOld); do{ //loop backwards through lOld, starting at the end k = llList2Key(lOld, max); if(llGetAgentSize(k) == ZERO_VECTOR){ // this av is no longer on the region lOld = llDeleteSubList(lOld, max,max);//so remove the av from the list } else if (llList2Key(llGetParcelDetails(llList2Vector(llGetObjectDetails(k, [OBJECT_POS]), 0),[PARCEL_DETAILS_ID]),0) != kThisParcel){ //get the avatar's position and check the parcel UUID for where that is. If it's not the same as this parcel's uuid lOld = llDeleteSubList(lOld, max,max); } } while(--max > -1); } list lNew = llGetAgentList(AGENT_LIST_PARCEL, []);//get uuids of avatars currently on parcel if(lNew !=[]){//if there's anyone on the parcel max = -llGetListLength(lNew); do{ //loop through lNew k = llList2Key(lNew, max); if(!~llListFindList(lOld, [k])){//k is not on lOld, so must have just arrived llOwnerSay(llGetUsername(k)+" has just arrived on the parcel."); lOld +=[k];//add k to the list of people already on the parcel } } while(++max); } llSetTimerEvent(fTimer);//turn the timer back on } } 1 Link to comment Share on other sites More sharing options...
Berksey Posted July 8, 2017 Share Posted July 8, 2017 (edited) Innula, that's kind of you. I know the usual "not going to do the work for you" etiquette is standard practice, but when it's something that tedious to learn it's really nice to have a little something to work with. *adds it to her "Utilities & Educational" folder* That's going to come in very handy someday, I know it. ^-^ Edited July 8, 2017 by Berksey Link to comment Share on other sites More sharing options...
Innula Zenovka Posted July 8, 2017 Share Posted July 8, 2017 (edited) I'm never too sure about where to draw the line with "not going to do the work for you." The general idea, at least as I understand it, is that we don't want to encourage people to ask for scripts here for free when they should be posting in Employment or Wanted or somewhere and offering to pay for the scripts. We also want to encourage people to learn, and you learn best by working it out for yourself, and it's certainly a great feeling when you manage to put it together. However, having said all that, when it's something that I regard as an important technique to know and it's something I know from experience is tricky and -- as you rightly say -- "tedious" to learn by working it out for yourself, I don't mind posting a full example in the hope it proves useful and that some people, at least, will take the time to look at the comments and learn how it works. Edited July 8, 2017 by Innula Zenovka 3 Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 8, 2017 Share Posted July 8, 2017 (edited) I agree. The early denizens of this forum established the practice of providing only partial scripts or illustrative examples, and we have kept on with it for as long as SL has been around. As you say, it's meant to keep us from undercutting other scripters who might like a chance to write a script for pay. It's a logical companion to the community standard that forbids advertizing in the forums. As you say, too, the practice makes good sense from an education point of view. I spent long enough teaching to know that it's usually poor form to tell a student the answer to a question he ought to be figuring out for himself. It robs the student of the joy of discovery and usually means that the student won't have the tools to solve similar problems in the future. I prefer to offer a couple of pointers -- maybe a snippet of code -- and shove the student in the right direction, hands off. If I have a full-blown example to share, I post it in the Library. There's no "rule" here, but this understanding among us has served the Scripting forum well for a long time. Circumstances vary, so we are neither rigid nor consistent about how much free scripting we post here. I'm sure we each have different feelings about how important it is to maintain the norm, too. There are certainly other forums where it's common to post complete scripts, so there's nothing to say that our approach is necessarily the best. Personally, though, it served me well when I was starting out with LSL, so I'll stick with it. Edited July 8, 2017 by Rolig Loon 3 Link to comment Share on other sites More sharing options...
Berksey Posted July 9, 2017 Share Posted July 9, 2017 Yeah, it's like if there's a link to it, give them the link. If it's already free somewhere for the public, give them the link. Even if it's just a helping hand with the right thing to look up on the wiki. I've learned an awful lot just following suggestions given in past questions before I ever thought to ask a question here, and often it was simply a link to the page with the function I needed to learn about to do the job. And if they say hey, I need a script that does this that and the other and I can't find one free on the marketplace, give me one, having the employment forum to refer them to is an awesomely polite way of dealing with it, and might even help people get a few scripting jobs, too, who knows? ^-^ I think it's great we have the Library too, because I wouldn't feel like I was cheating anyone of a chance to learn by directing them there. Even if the script they find already works, they're probably going to end up wanting to change it to suit themselves anyway, I know I always have. I tend to see the library as a collection of examples to learn from too. But yeah, digging in and learning it from the guts out is the best. I can't even install a simple light bulb without it turning into some sort of Rube Goldberg Frankenstein's monster contraption and finally devolving into something practical and usable again. ^-^; I'm just happy you guys are here to share some of what you know and help some of the rest of us learn. It makes a huge difference. Link to comment Share on other sites More sharing options...
Rachel1206 Posted July 10, 2017 Share Posted July 10, 2017 (edited) Is there any speed advantage using: if(lOld != []) Else code as below is clearer: max = llGetListLength(lOld); if (max > 0 ) { do { } while(--max > -1); } Edited July 10, 2017 by Rachel1206 Link to comment Share on other sites More sharing options...
mikka Luik Posted July 10, 2017 Share Posted July 10, 2017 You would have to run tests to see how much faster as a lot of other factors involved (amount of data to process etc). In this case as its a one second timer my gut instinct as ever would be to go with the clearer version - but my LSL ninja skills are no match for others (I did all that back in my Mcode days ta=^^= ) so I prefer to make it easier for me to read later. YKMV Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 10, 2017 Share Posted July 10, 2017 (edited) 8 hours ago, Rachel1206 said: Is there any speed advantage using: if(lOld != []) There used to be, in pre-Mono days. When I started with LSL, back in 2007, I learned that form from Void Singer along with several hacks that were widely-used at the time. A year or two ago, the question came up in the SLU scripting forum and the general opinion was that there's no speed advantage now. You'll still find many of of us who still use it out of habit (and because it doesn't take as long to type). Edited July 10, 2017 by Rolig Loon 1 Link to comment Share on other sites More sharing options...
Rachel1206 Posted July 10, 2017 Share Posted July 10, 2017 2 hours ago, Rolig Loon said: There used to be, in pre-Mono days. When I started with LSL, back in 2007, I learned that form from Void Singer along with several hacks that were widely-used at the time. A year or two ago, the question came up in the SLU scripting forum and the general opinion was that there's no speed advantage now. You'll still find many of of us who still use it out of habit (and because it doesn't take as long to type). OK, thank you for giving insight on history behind. Link to comment Share on other sites More sharing options...
Lucia Nightfire Posted July 11, 2017 Share Posted July 11, 2017 You can also compare list hashes and replace the list if the hashes don't match. Saves you from having to loop through the list checking for agents that left the parcel every timer event. list AGENTS; string md5; default { state_entry() { llSetTimerEvent(2.0); } on_rez(integer i) { llResetScript(); } timer() { list GAL; if ((md5 = llMD5String(llDumpList2String(GAL = llGetAgentList(AGENT_LIST_PARCEL,[])," "),111)) != md5) { key k = NULL_KEY; integer i = -llGetListLength(GAL); for (; i < 0; i++) { //ghost detection: certain ghosts are seen by llGetAgentList(), one returns NULL_KEY, others a correct agent key, but none are seen by llGetAgentSize() if ((llGetAgentSize(k) != ZERO_VECTOR) && (llListFindList(AGENTS,[k = llList2Key(GAL,i)]) == -1)) { llOwnerSay(llKey2Name(k) + " has just arrived on the parcel."); } } AGENTS = GAL; } } } 3 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