Difference between revisions of "LlGetAgentList"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 24: Line 24:
* There is no guaranteed understandable order or randomness to the list returned.
* There is no guaranteed understandable order or randomness to the list returned.
* Will only return up to 100 agents.
* Will only return up to 100 agents.
|examples=<lsl>//Displays up to 100 avatar key: name pairs detected in the entire region
|examples=
list gaAgents;
<lsl>
// WARNING:
//      As of now, this function does not have a delimiter for its option list.
//      This means, the function MIGHT return up to a hundred avatar keys.
//      You'll need a lot of free memory to be able to store those keys, be warned of possible STACK_HEAD_COLLISION_ERRORs.
 
 
//Displays up to 100 avatar key: name pairs detected in the entire region


default
default
Line 31: Line 38:
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         integer  i;
         list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        integer  liCount;
         integer numOfAvatars = llGetListLength(avatarsInRegion);
 
        gaAgents = llGetAgentList(AGENT_LIST_REGION, []);
        // if no avatars, abort avatar listing process and give a short notice
         liCount = llGetListLength(gaAgents);
         if (!numOfAvatars)
         if (liCount > 0)
        {
             if (llGetListEntryType(gaAgents,0) == TYPE_STRING)
             // PUBLIC_CHANNEL has the integer value 0
                llOwnerSay("Error: "+llList2String(gaAgents,0));
            llSay(PUBLIC_CHANNEL, "No avatars found within the region!");
             else
             return;
                for (i=0; i < liCount; ++i)
        }
                    llOwnerSay(llList2String(gaAgents,i)+": "+llKey2Name(llList2String(gaAgents,i)));
 
  }
        integer index;
}</lsl>
        while (index < numOfAvatars)
        {
            key id = llList2Key(avatarsInRegion, index);
            string name = llKey2Name(id);
 
            llOwnerSay(name + " [ " + (string)id + " ]");
            ++index;
        }
    }
}
</lsl>
<lsl>
<lsl>
//Orders new list based off distance, and returns
//Orders new list based off distance, and returns

Revision as of 08:36, 23 September 2012

Summary

Function: list llGetAgentList( integer scope, list options );

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

• integer scope
AGENT_LIST_* flag specifies the selection scope
  • AGENT_LIST_PARCEL - returns only agents on the same parcel where the script is running.
  • AGENT_LIST_PARCEL_OWNER - returns only agents on any parcel in the region where the parcel owner is the same as the owner of the parcel under the scripted object.
  • AGENT_LIST_REGION - returns any/all agents in the region.
• list options Unused.

Caveats

  • There is no guaranteed understandable order or randomness to the list returned.
  • Will only return up to 100 agents.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> // WARNING: // As of now, this function does not have a delimiter for its option list. // This means, the function MIGHT return up to a hundred avatar keys. // You'll need a lot of free memory to be able to store those keys, be warned of possible STACK_HEAD_COLLISION_ERRORs.


//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)
       {
           // PUBLIC_CHANNEL has the integer value 0
           llSay(PUBLIC_CHANNEL, "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;
       }
   }

} </lsl> <lsl> //Orders new list based off distance, and returns //then on touch_start default {

touch_start(integer num){ list keys = llGetAgentList(AGENT_LIST_REGION,[]); list newkeys; integer i; for (i=0; i < llGetListLength(keys); ++i){ newkeys += llVecDist(llGetPos(), llList2Vector(llGetObjectDetails(llList2Key(keys,i), [OBJECT_POS]), 0)); newkeys += llList2Key(keys,i);

}

newkeys = llListSort(newkeys, 2, FALSE);

for (i=0; i < llGetListLength(newkeys); ++i){ llOwnerSay(llGetDisplayName(llList2Key(newkeys,i+1)) + " ["+(string)llRound(llList2Float(newkeys, i)) + "m]"); ++i; } }

}

</lsl>

See Also

Deep Notes

History

All Issues

~ Search JIRA for related Issues
   llGetAgentList() with scope AGENT_LIST_PARCEL or AGENT_LIST_PARCEL_OWNER returns empty list when attached to avatar
   llGetNumberOfAgents() function to return an integer count of agents
   AGENT_LIST_MAX_RESULTS option for llGetAgentList()

Signature

function list llGetAgentList( integer scope, list options );