llGetAgentList: Telling NPCs from Avatars
- Mike Lorrey
- Posts: 367
- Joined: Sun Sep 04, 2016 5:40 pm
- Has thanked: 72 times
- Been thanked: 276 times
llGetAgentList: Telling NPCs from Avatars
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?
- Ilan Tochner
- Posts: 6542
- Joined: Sun Dec 23, 2012 8:44 am
- Has thanked: 5009 times
- Been thanked: 4481 times
- Contact:
Re: llGetAgentList: Telling NPCs from Avatars
Hi Mike,
You can see the list of supported NPC-related functions here: https://www.kitely.com/virtual-world-ne ... functions/
You can see the list of supported NPC-related functions here: https://www.kitely.com/virtual-world-ne ... functions/
-
- Posts: 1314
- Joined: Sun Dec 23, 2012 2:26 pm
- Has thanked: 1134 times
- Been thanked: 1142 times
Re: llGetAgentList: Telling NPCs from Avatars
The OpenSimWorld NPC toolkit creates NPCs with (NPC) as the last name/suffix. That makes it pretty easy to identify them.
- Mike Lorrey
- Posts: 367
- Joined: Sun Sep 04, 2016 5:40 pm
- Has thanked: 72 times
- Been thanked: 276 times
Re: llGetAgentList: Telling NPCs from Avatars
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.
<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.
- skindup truk
- Posts: 46
- Joined: Fri Aug 29, 2014 8:39 pm
- Location: Australia
- Has thanked: 7 times
- Been thanked: 36 times
- Contact:
Re: llGetAgentList: Telling NPCs from Avatars
(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 )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.
It is throwing up the following output: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]"); }
[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.
- skindup truk
- Posts: 46
- Joined: Fri Aug 29, 2014 8:39 pm
- Location: Australia
- Has thanked: 7 times
- Been thanked: 36 times
- Contact:
Re: llGetAgentList: Telling NPCs from Avatars
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╚╔╩Ì▀ÓßÔ▬õÕµþþÞÛ↨ý♂♀☻±±‗‗‗¾³¾¶§÷¸°¨¨·¹³²■ ☺☻☻♥♦♣♠•◘○◙♂♀↔♫☼►◄↕‼¶§ +
- Kurtis Anatine
- Posts: 23
- Joined: Thu Jun 30, 2016 10:33 pm
- Has thanked: 3 times
- Been thanked: 32 times
Re: llGetAgentList: Telling NPCs from Avatars
Man I cant believe I didn't see that on the wiki, ive been using osNpcGetPos to validate npcs!
Thanks for the snippet!
Thanks for the snippet!
- These users thanked the author Kurtis Anatine for the post:
- Mike Lorrey
- Mike Lorrey
- Posts: 367
- Joined: Sun Sep 04, 2016 5:40 pm
- Has thanked: 72 times
- Been thanked: 276 times
Re: llGetAgentList: Telling NPCs from Avatars
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.skindup truk wrote:(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 )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.
It is throwing up the following output: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]"); }
[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.
- skindup truk
- Posts: 46
- Joined: Fri Aug 29, 2014 8:39 pm
- Location: Australia
- Has thanked: 7 times
- Been thanked: 36 times
- Contact:
-
- Posts: 1314
- Joined: Sun Dec 23, 2012 2:26 pm
- Has thanked: 1134 times
- Been thanked: 1142 times
Re: llGetAgentList: Telling NPCs from Avatars
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");
}
}
}
}
- These users thanked the author Graham Mills for the post:
- Ilan Tochner