Page 1 of 2
llGetAgentList: Telling NPCs from Avatars
Posted: Tue Oct 04, 2016 3:31 pm
by Mike Lorrey
I'm scripting a gun turret and need it to distinguish NPCs from avatars. Currently using the llGetAgentList function, but that doesn't seem to be able to tell the difference. Is there an OSSL function that works better?
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Tue Oct 04, 2016 3:39 pm
by Ilan Tochner
Hi Mike,
You can see the list of supported NPC-related functions here:
https://www.kitely.com/virtual-world-ne ... functions/
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Tue Oct 04, 2016 3:42 pm
by Graham Mills
The OpenSimWorld NPC toolkit creates NPCs with (NPC) as the last name/suffix. That makes it pretty easy to identify them.
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Tue Oct 04, 2016 4:14 pm
by Mike Lorrey
Okay, I may be screwing this up but I don't think so. Here's a snippet of my threat detection list code at present.
<php>
timer()
{
list keys = llGetAgentList(AGENT_LIST_REGION, []);
integer numberOfKeys = llGetListLength(keys);
vector currentPos = llGetPos();
list newkeys;
key thisAvKey;
integer i;
for (i = 0; i < numberOfKeys; ++i) {
thisAvKey = llList2Key(keys,i);
integer isNPC = osIsNpc(thisAvKey);
if (isNPC == FALSE)
{
newkeys += [llRound(llVecDist(currentPos,
llList2Vector(llGetObjectDetails(thisAvKey, [OBJECT_POS]), 0))),
thisAvKey];
}
llDeleteSubList(keys,i,i);
numberOfKeys = llGetListLength(keys);
}
newkeys = llListSort(newkeys, 2, FALSE); // sort strided list by descending distance
for (i = 0; i < (numberOfKeys * 2); i += 2) {
llOwnerSay(llGetDisplayName(llList2Key(newkeys, i+1))
+" ["+ (string) llList2Integer(newkeys, i) + "m]");
}
}
</php>
It is throwing up the following output:
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
So it looks like its removing the NPC's name from the list, but is still reporting on that as an entry in the list... I'd like to have it remove it entirely, but not exactly sure whats wrong. List management is not my forte in SL/OS scripting yet.
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Wed Oct 05, 2016 6:33 pm
by skindup truk
Mike Lorrey wrote:Okay, I may be screwing this up but I don't think so. Here's a snippet of my threat detection list code at present.
Code: Select all
integer numberOfKeys = llGetListLength(keys);
...
for (i = 0; i < (numberOfKeys * 2); i += 2) {
llOwnerSay(llGetDisplayName(llList2Key(newkeys, i+1))
+" ["+ (string) llList2Integer(newkeys, i) + "m]");
}
It is throwing up the following output:
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
So it looks like its removing the NPC's name from the list, but is still reporting on that as an entry in the list... I'd like to have it remove it entirely, but not exactly sure whats wrong. List management is not my forte in SL/OS scripting yet.
(int) numberOfKeys was based on the length of "keys" but your list of "newkeys" is only a subset of "keys" - despite you popping in a distance measurement as your so called strided array. so it appears your newkeys is fine, but your loop condition is based on the larger sized array "keys" so it's overshooting. when you print from memory that is outside of your "newkeys" array it just prints a zero length string or the number zero etc. which is why you get that second line. i think your output log was just repeating this pair of lines over and over, so i'm guessing you had just yourself as 1x non-NPC and then 1x NPC only (but im not sure

)
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Wed Oct 05, 2016 6:46 pm
by skindup truk
PS. i was going to say sometimes it's easier to spot this when the memory values are something funny you get weird strings... then i got carried away mashing random alt+numpad values lol...
Code: Select all
à +*+Ã▒M║╣«»ª░▒╝¢╚╚╚╔╩╦─ÍÎÏ┘┌█õ¯ÚþÌÞÚÙýݯ´LWwxydz╚╔╩Ì▀ÓßÔ▬õÕµþþÞÛ↨ý♂♀☻±±‗‗‗¾³¾¶§÷¸°¨¨·¹³²■ ☺☻☻♥♦♣♠•◘○◙♂♀↔♫☼►◄↕‼¶§ +
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Tue Oct 11, 2016 6:37 am
by Kurtis Anatine
Man I cant believe I didn't see that on the wiki, ive been using osNpcGetPos to validate npcs!
Thanks for the snippet!
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Mon Nov 07, 2016 4:17 am
by Mike Lorrey
skindup truk wrote:Mike Lorrey wrote:Okay, I may be screwing this up but I don't think so. Here's a snippet of my threat detection list code at present.
Code: Select all
integer numberOfKeys = llGetListLength(keys);
...
for (i = 0; i < (numberOfKeys * 2); i += 2) {
llOwnerSay(llGetDisplayName(llList2Key(newkeys, i+1))
+" ["+ (string) llList2Integer(newkeys, i) + "m]");
}
It is throwing up the following output:
[09:12] Laser Turret - 2bbl- Ball: Mike Lorrey [6m]
[09:12] Laser Turret - 2bbl- Ball: [0m]
So it looks like its removing the NPC's name from the list, but is still reporting on that as an entry in the list... I'd like to have it remove it entirely, but not exactly sure whats wrong. List management is not my forte in SL/OS scripting yet.
(int) numberOfKeys was based on the length of "keys" but your list of "newkeys" is only a subset of "keys" - despite you popping in a distance measurement as your so called strided array. so it appears your newkeys is fine, but your loop condition is based on the larger sized array "keys" so it's overshooting. when you print from memory that is outside of your "newkeys" array it just prints a zero length string or the number zero etc. which is why you get that second line. i think your output log was just repeating this pair of lines over and over, so i'm guessing you had just yourself as 1x non-NPC and then 1x NPC only (but im not sure

)
the second line is detecting my NPC cat, actually. I got it to remove the cats name from the list, but its still reporting it as a detected av. Like I said, I'm not great with lists in LSL, so I'd appreciate some feedback on fixing that code.
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Mon Sep 04, 2017 8:44 am
by skindup truk
i have been away for awhile...! did u ever fix this?
Re: llGetAgentList: Telling NPCs from Avatars
Posted: Tue Sep 05, 2017 9:33 pm
by Graham Mills
The following seems to work as expected:
Code: Select all
default
{
state_entry()
{
list agents = llGetAgentList(AGENT_LIST_REGION, []);
integer i;
key id;
for (i=0; i<llGetListLength(agents); i++)
{
id = llList2String(agents, i);
if (osIsNpc(id) == 1)
{
llOwnerSay("NPC "+ llList2String(agents, i)+"\n\r");
}
else
{
llOwnerSay("avatar "+ llList2String(agents, i)+"\n\r");
}
}
}
}