llGetAgentList: Telling NPCs from Avatars

Creating scripts
User avatar
Mike Lorrey
Posts: 361
Joined: Sun Sep 04, 2016 5:40 pm
Has thanked: 71 times
Been thanked: 270 times

llGetAgentList: Telling NPCs from Avatars

Post 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?
User avatar
Ilan Tochner
Posts: 6504
Joined: Sun Dec 23, 2012 8:44 am
Has thanked: 4943 times
Been thanked: 4455 times
Contact:

Re: llGetAgentList: Telling NPCs from Avatars

Post by Ilan Tochner »

Hi Mike,

You can see the list of supported NPC-related functions here: https://www.kitely.com/virtual-world-ne ... functions/
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: llGetAgentList: Telling NPCs from Avatars

Post by Graham Mills »

The OpenSimWorld NPC toolkit creates NPCs with (NPC) as the last name/suffix. That makes it pretty easy to identify them.
User avatar
Mike Lorrey
Posts: 361
Joined: Sun Sep 04, 2016 5:40 pm
Has thanked: 71 times
Been thanked: 270 times

Re: llGetAgentList: Telling NPCs from Avatars

Post 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.
User avatar
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

Post 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 ;))
User avatar
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

Post 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╚╔╩Ì▀ÓßÔ▬õÕµþþÞÛ↨ý♂♀☻­­±±‗‗‗¾³¾¶§÷¸°¨¨·¹³²■ ☺☻☻♥♦♣♠•◘○◙♂♀↔♫☼►◄↕‼¶§ +
User avatar
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

Post 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!
These users thanked the author Kurtis Anatine for the post:
Mike Lorrey
User avatar
Mike Lorrey
Posts: 361
Joined: Sun Sep 04, 2016 5:40 pm
Has thanked: 71 times
Been thanked: 270 times

Re: llGetAgentList: Telling NPCs from Avatars

Post 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.
User avatar
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

Post by skindup truk »

i have been away for awhile...! did u ever fix this?
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: llGetAgentList: Telling NPCs from Avatars

Post 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");
            }
        }
    }
}
These users thanked the author Graham Mills for the post:
Ilan Tochner
Post Reply