llGetAgentList
list llGetAgentList(integer Scope, list Options)Requests a list of agents currently in the region, limited by the scope parameter.
Returns a list [key UUID-0, key UUID-1, ..., key UUID-n] or [string error_msg] - returns avatar keys for all agents in the region limited to the area(s) specified by scope
Parameters
-
Scope(integer) - The scope (region, parcel, parcel same owner) to return agents for.
-
Options(list) - List of options to apply. Current unused.
List All Avatars in Region
Section titled “List All Avatars in Region”Displays up to 100 avatar key-name pairs detected in the entire region:
//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; } }}Sort Avatars by Distance
Section titled “Sort Avatars by Distance”Orders a new list based on distance and returns names and distances on touch:
// 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]"); } }}Caveats
Section titled “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. There is also an issue with a certain type of ghosted agent still returning a key. You can check each key against
llGetAgentSize()to verify if they’re really in the sim or not; these anomalies do not affectllGetAgentSize().
- To check if an avatar is in the same sim, check whether
llGetAgentSize()does NOT returnZERO_VECTOR. It’s much faster and easier than callingllGetAgentList()and running through the list to compare a given key with each list item. - This function does not have a delimiter for its option list. This means the function might return up to 100 avatar keys. You’ll need a lot of free memory to store those keys; be warned of possible stack-heap collisions.