Skip to content
lsl.devlsl.devLSL Dev

llGetAgentList

function
Function syntax
list llGetAgentList(
  1. integer scope,// Scope flag (AGENT_LIST_PARCEL, AGENT_LIST_PARCEL_OWNER, or AGENT_LIST_REGION) to filter the returned agents. Values: AgentListScope
  2. list options// A list of options to apply (currently unused).
);
Returns
list
Energy
10

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

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

How to use
list result = llGetAgentList(0, []);
  • 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().
Example 1
//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);
18 collapsed lines
// 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;
}
}
}
Example 2
5 collapsed lines
// 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);
20 collapsed lines
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]");
}
}
}

From the issue templates included by the wiki article:

  • SCR-311 (bug): llGetAgentList() with scope AGENT_LIST_PARCEL or AGENT_LIST_PARCEL_OWNER returns empty list when attached to avatar (fixed)
  • BUG-40680 (nf): AGENT_LIST_LIMIT option for llGetAgentList()
  • BUG-40681 (nf): llGetNumberOfAgents() - companion to llGetAgentList() for retrieving count only.

The wiki article also includes shared templates whose conditional content is not reproduced here: Template:Issues/SVC-5488, Template:Issues/MISC-243, 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.