Difference between revisions of "LlSameGroup"

From Second Life Wiki
Jump to navigation Jump to search
(If you revert an edit without comment, that reverted edit needs to be obviously wrong. If you disagree with an edit, produce a superior edit and leave a comment; do not just revert it.)
(Replaced <source> with <syntaxhighlight>; added a LOT of links. modified things here and there to improve running time)
 
Line 8: Line 8:
|p1_type=key|p1_name=uuid
|p1_type=key|p1_name=uuid
|func_desc
|func_desc
|return_text=that is [[TRUE]] if {{LSLP|uuid}} and the prim the script is in are of the same group, otherwise [[FALSE]].
|return_text=that is [[TRUE]] if {{LSLP|uuid}} and the [[prim]] the [[script]] is in are of the same [[group]], otherwise [[FALSE]].
|func_footnote=This function compares the group-uuid of the prim containing the script to that of the group-uuid of what {{LSLP|uuid}} describes.
|func_footnote=This function compares the {{mono|group-uuid}} of the [[prim]] containing the script to that of the {{mono|group-uuid}} of what {{LSLP|uuid}} describes.
It answers these two questions:
It answers these two questions:
*"Is the script's prim in the same group as {{LSLP|uuid}}?"
*"Is the script's prim in the same [[group]] as {{LSLP|uuid}}?"
*"Is the group-uuid of the script's prim equal to {{LSLP|uuid}}?"
*"Is the {{mono|group-uuid}} of the script's prim equal to {{LSLP|uuid}}?"
|spec=
|spec=
The group of the prim the script is in is...
The group of the prim the script is in is...
* The group the prim is set-to
* The group the prim is set-to
* The group the prim is deeded-to  
* The group the prim is deeded-to  
* The group the prim is otherwise owned by
* The group the prim is otherwise [[Owner|owned by]]
* If no group information is set, the group-uuid used for this is [[NULL_KEY]].
* If no group information is set, the {{mono|group-uuid}} used for this is [[NULL_KEY]].


The group of the {{LSLP|uuid}} is...
The group of the {{LSLP|uuid}} is...
* If {{LSLP|uuid}} is a prim (known to the region)...
* If {{LSLP|uuid}} is a prim (known to the [[region]])...
** and it is an attachment, the active group of the owner*
** and it is an [[attachment]], the active group of the owner*
** The group the prim is set-to
** The group the prim is set-to
** The group the prim is deeded-to  
** The group the prim is deeded-to  
** The group the prim is otherwise owned by
** The group the prim is otherwise owned by
** If no group information is set, the group-uuid used for this is [[NULL_KEY]].
** If no group information is set, the {{mono|group-uuid}} used for this is [[NULL_KEY]].
* If {{LSLP|uuid}} is an avatar (known to the region)...
* If {{LSLP|uuid}} is an [[avatar]] (known to the [[region]])...
** The active group of the avatar.
** The active group of the avatar.
** If no group information is set, the group-uuid used for this is [[NULL_KEY]].
** If no group information is set, the {{mono|group-uuid}} used for this is [[NULL_KEY]].
* Otherwise, treat {{LSLP|uuid}} AS the group-uuid.
* Otherwise, treat {{LSLP|uuid}} AS the {{mono|group-uuid}}.
** This means that instead of doing "Is the script's prim in the same group as {{LSLP|uuid}}?", it becomes "Is the group-uuid of the script's prim equal to {{LSLP|uuid}}?"
** This means that instead of doing "Is the script's prim in the same group as {{LSLP|uuid}}?", it becomes "Is the {{mono|group-uuid}} of the script's prim equal to {{LSLP|uuid}}?"
Note: No group, prim, or avatar share the same uuid.
'''Note:''' No group, prim, or avatar share the same {{LSLP|uuid}}.


In pseudocode:
In pseudocode:
<source lang="lsl2">integer llSameGroup(key uuid){
<syntaxhighlight lang="lsl2">integer llSameGroup(key uuid){
     key group = getGroupKey(llGetKey());
     key group = getGroupKey(llGetKey());
     if(uuid == group)
     if(uuid == group)
Line 42: Line 42:
         return TRUE;
         return TRUE;
     return FALSE;
     return FALSE;
}</source>
}</syntaxhighlight>
|caveats=
|caveats=
*Not so obvious is that it returns [[TRUE]] if the object is not set to a group (i.e. "(none)") and either the AV with the given key has no group active or the function is called with a [[NULL_KEY]].
*Not so obvious is that it returns [[TRUE]] if the [[object]] is not set to a group (i.e. "(none)") and either the [[avatar|AV]] with the given [[key]] has no group active or the function is called with a [[NULL_KEY]].
|constants
|constants
|examples=
|examples=
<source lang="lsl2">
<syntaxhighlight lang="lsl2">
// Gives inventory object only to agents with the same active group
// Gives inventory object only to agents with the same active group


Line 72: Line 72:
     }
     }
}
}
</source>
</syntaxhighlight>
|helpers=
|helpers=
To determine if an avatar is an object's owner when deeded to group, you should use a function similar to that provided for [[LlGetOwner#Useful_Snippets|llGetOwner]]().
To determine if an avatar is an object's owner when deeded to group, you should use a function similar to that provided for [[LlGetOwner#Useful_Snippets|llGetOwner]]().


The following uses llSameGroup() to determine if a parcel is rezzable based on the object's active group and parcel details. Useful for preventing unnecessary rez failure notices from various types of attached objects (e.g. guns, water/skywalk HUDs, etc).
The following uses llSameGroup() to determine if a [[parcel]] is [[Rez|rezzable]] based on the object's active group and parcel details. Useful for preventing unnecessary rez failure notices from various types of attached objects (e.g. guns, water/skywalk [[HUD]]s, etc).
<source lang="lsl2">
<syntaxhighlight lang="lsl2">
/*
/*
   By Aryn Gellner
   By Aryn Gellner
Line 87: Line 87:
{
{
     integer parcel_flags = llGetParcelFlags(pos);
     integer parcel_flags = llGetParcelFlags(pos);
     if(parcel_flags & PARCEL_FLAG_ALLOW_CREATE_OBJECTS)
     if (parcel_flags & PARCEL_FLAG_ALLOW_CREATE_OBJECTS)
     {
     {
         return true;//Anyone can rez. No further checks are needed.
         return true; //Anyone can rez. No further checks are needed.
     }
     }


     //Ok, not just anyone can rez. Maybe they share an owner or the land allows for group rezzing.
     //Ok, not just anyone can rez. Maybe they share an owner or the land allows for group rezzing.
     //So lets get the parcel owner_id and group_id
     //So let's get the parcel owner_id and group_id


     list details = llGetParcelDetails(pos, [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]);
     list details = llGetParcelDetails(pos, [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]);


     if(llList2Key(details, 0) == llGetOwner())
     if (llList2Key(details, 0) == llGetOwner())
     {
     {
         return TRUE;//Owner can always rez.
         return TRUE; //Owner can always rez.
     }
     }


Line 105: Line 105:
     return (parcel_flags & PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS) && llSameGroup(llList2Key(details, 1));
     return (parcel_flags & PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS) && llSameGroup(llList2Key(details, 1));
}
}
</source>
</syntaxhighlight>
|also_functions={{LSL DefineRow||[[llDetectedGroup]]|Used in conjunction with {{LSLGC|Detected|detection}} events}}
|also_functions={{LSL DefineRow||[[llDetectedGroup]]|Used in conjunction with {{LSLGC|Detected|detection}} events}}
{{LSL DefineRow||[[llGetAttachedList]]|Together with [[llGetObjectDetails]] and [[OBJECT_GROUP]], it can be used to determine the active group of an avatar that is wearing at least one non-HUD attachment.}}
{{LSL DefineRow||[[llGetAttachedList]]|Together with [[llGetObjectDetails]] and [[OBJECT_GROUP]], it can be used to determine the active group of an avatar that is wearing at least one non-HUD attachment.}}

Latest revision as of 20:52, 3 February 2023

Summary

Function: integer llSameGroup( key uuid );
0.0 Forced Delay
10.0 Energy

Returns a boolean (an integer) that is TRUE if uuid and the prim the script is in are of the same group, otherwise FALSE.

• key uuid group, avatar or prim UUID that is in the same region

This function compares the group-uuid of the prim containing the script to that of the group-uuid of what uuid describes. It answers these two questions:

  • "Is the script's prim in the same group as uuid?"
  • "Is the group-uuid of the script's prim equal to uuid?"

Specification

The group of the prim the script is in is...

  • The group the prim is set-to
  • The group the prim is deeded-to
  • The group the prim is otherwise owned by
  • If no group information is set, the group-uuid used for this is NULL_KEY.

The group of the uuid is...

  • If uuid is a prim (known to the region)...
    • and it is an attachment, the active group of the owner*
    • The group the prim is set-to
    • The group the prim is deeded-to
    • The group the prim is otherwise owned by
    • If no group information is set, the group-uuid used for this is NULL_KEY.
  • If uuid is an avatar (known to the region)...
    • The active group of the avatar.
    • If no group information is set, the group-uuid used for this is NULL_KEY.
  • Otherwise, treat uuid AS the group-uuid.
    • This means that instead of doing "Is the script's prim in the same group as uuid?", it becomes "Is the group-uuid of the script's prim equal to uuid?"

Note: No group, prim, or avatar share the same uuid.

In pseudocode:

integer llSameGroup(key uuid){
    key group = getGroupKey(llGetKey());
    if(uuid == group)
        return TRUE;
    if(getGroupKey(uuid) == group)
        return TRUE;
    return FALSE;
}

Caveats

  • Not so obvious is that it returns TRUE if the object is not set to a group (i.e. "(none)") and either the AV with the given key has no group active or the function is called with a NULL_KEY.

Examples

// Gives inventory object only to agents with the same active group

default
{
    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);

        integer sameGroup = llSameGroup(id);
//      same as llDetectedGroup(i) (with llDetectedGroup, detected does not need to be in the sim)

        if (sameGroup)
        {
            integer numberOfObjectsInPrim = llGetInventoryNumber(INVENTORY_OBJECT);

            if (numberOfObjectsInPrim)
                llGiveInventory(id, llGetInventoryName(INVENTORY_OBJECT, 0));
        }
        else
        {
            llRegionSayTo(id, 0, "Wrong active group!");
        }
    }
}

Useful Snippets

To determine if an avatar is an object's owner when deeded to group, you should use a function similar to that provided for llGetOwner().

The following uses llSameGroup() to determine if a parcel is rezzable based on the object's active group and parcel details. Useful for preventing unnecessary rez failure notices from various types of attached objects (e.g. guns, water/skywalk HUDs, etc).

/*
  By Aryn Gellner
  pos - position (in region coordinates) to check against.
  * Additional Land Owner Test added by Ruthven Willenov, simplified by Strife
*/
 
integer is_rezzable(vector pos)
{
    integer parcel_flags = llGetParcelFlags(pos);
    if (parcel_flags & PARCEL_FLAG_ALLOW_CREATE_OBJECTS)
    {
        return true; //Anyone can rez. No further checks are needed.
    }

    //Ok, not just anyone can rez. Maybe they share an owner or the land allows for group rezzing.
    //So let's get the parcel owner_id and group_id

    list details = llGetParcelDetails(pos, [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]);

    if (llList2Key(details, 0) == llGetOwner())
    {
        return TRUE; //Owner can always rez.
    }

    //Since what we are going to return is a boolean just return the result of the boolean expression.
    return (parcel_flags & PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS) && llSameGroup(llList2Key(details, 1));
}

Notes

Child Prims

It is possible for the group of a child prim to differ from that of the root prim. To build such an object it must first be unlinked, the groups set, and then relinked. Rezzing an object resets the group of the object to that of the group that the user currently has activated. Changing the group of an object changes the group for the entire object. This may only be an artifact or manifestation of VWR-5044.

See Also

Functions

•  llDetectedGroup Used in conjunction with detection events
•  llGetAttachedList Together with llGetObjectDetails and OBJECT_GROUP, it can be used to determine the active group of an avatar that is wearing at least one non-HUD attachment.

Deep Notes

Tests

•  llSameGroup Test

Signature

function integer llSameGroup( key uuid );

Haiku

Do you belong or
Are you alien, unknown
To us, unwanted?