Skip to content
lsl.devlsl.devLSL Dev

LlGetAgentList

Looking for the current API? Open the llGetAgentList reference →

Wiki description

Requests a list of agents currently in the region, limited by the scope parameter.

Return value notes

Returns a list [key id0, key id1, ..., key idn] or [string error_msg] - returns avatar keys for all agents in the region limited to the area(s) specified by scope

Caveats

  • There is no guaranteed understandable order or randomness to the list returned.
  • Will only return up to 100 agents.
  • Ghosts, agents that leave behind a corrupted presence and agents in God Mode depending on the level will have NULL_KEY returned instead of their real key with llGetAgentList(). There is also an issue with a certain type of ghosted agent still returning a key too. Perhaps check each key against llGetAgentSize() to verify if they're really in the sim or not; none of the above anomalies affect llGetAgentSize().

Examples

//Displays up to 100 avatar key: name pairs detected in the entire region

default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        integer numOfAvatars = llGetListLength(avatarsInRegion);

        // if no avatars, abort avatar listing process and give a short notice
        if (!numOfAvatars)
        {
            llOwnerSay("No avatars found within the region!");
            return;
        }

        integer index;
        while (index < numOfAvatars)
        {
            key id = llList2Key(avatarsInRegion, index);
            string name = llKey2Name(id);

            llOwnerSay(name + " [ " + (string)id + " ]");
            ++index;
        }
    }
}
//  Orders new list based on distance
//  and returns names and distances on touch

default
{
    touch_start(integer num_detected)
    {
        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);
            newkeys += [llRound(llVecDist(currentPos,
                            llList2Vector(llGetObjectDetails(thisAvKey, [OBJECT_POS]), 0))),
                        thisAvKey];
        }
  
        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]");
        }
    }
}

See also: functions

History

Shared wiki helpers

The original page also injects shared parameter notes, caveats or issue information through these helpers. Their conditional MediaWiki logic is not reproduced here; inspect the preserved helper source for additional material.

Template:Issues/SCR-311

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|SCR-311|type=bug|[[llGetAgentList]]() with scope [[AGENT_LIST_PARCEL]] or [[AGENT_LIST_PARCEL_OWNER]] returns {{HoverText|empty list|[]}} when [[attach]]ed to avatar|status=vfix|resolution=fixed}}

Template:Issues/SVC-5488

Template:Issues/MISC-243

Template:Issues/BUG-40680

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|BUG-40680|'''AGENT_LIST_LIMIT''' option for [[llGetAgentList]]()|type=nf}}

Template:Issues/BUG-40681

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|BUG-40681|'''llGetNumberOfAgents'''() - companion to [[llGetAgentList]]() for retrieving count only.|type=nf}}

Template:Issues/BUG-227045

Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.