User/Digit Ditko/find group key of avatar

From Second Life Wiki
< User
Revision as of 13:53, 6 July 2016 by Digit Ditko (talk | contribs) (Created page with "{{TOCright}} == Get Group Key for an Avatar's current group == This script demonstrates how to retrieve an avatar's active group key. By retrieving the a actual key, a scrip...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Get Group Key for an Avatar's current group

This script demonstrates how to retrieve an avatar's active group key. By retrieving the a actual key, a script can test for membership on one or more groups.

To get the active group of an avatar, get the attachment list of the avatar and then get the group for one of the attachments. Obviously this will fail if the avatar has no attachments, but how many avatars walk around with nothing attached (they would have to wear all system clothes and system hair).


// Get the active group from the avatar specified by inAvatar.
// return the group key, a NULL_KEY is returned if the group 
// cannot be determined
key
getAvatarGroup (key inAvatar)
{
    key result = NULL_KEY;
    
    // get the the list of attachments for the avatar 
    list parts = llGetAttachedList (inAvatar);
    if (llGetListLength (parts) > 0)
    {
         // If the avatar has any attachments then just get the 
         // group key for the first attachment.
         list parts2 = llGetObjectDetails (llList2Key (parts, 0), [OBJECT_GROUP]);  
         result = llList2Key (parts2, 0);
    }
    
    return (result);
}


// ------------------------------------------

default
{
    
    touch_start (integer total_number)
    {
        key av = llDetectedKey (0);
        key groupId = getAvatarGroup (av);
        
        llInstantMessage (av, "group = " + (string) groupId);
    }
}