LlAttachToAvatarTemp

From Second Life Wiki

Jump to: navigation, search

Contents

Summary

Function: llAttachToAvatarTemp( integer attach_point );

Follows the same convention as llAttachToAvatar, with the exception that the object will not create new inventory for the user, and will disappear on detach or disconnect.

• integer attach_point ATTACH_* constant or valid value (see the tables below)

To run this function the script must request the PERMISSION_ATTACH permission with llRequestPermissions. It should be noted that when an object is attached temporarily, a user cannot 'take' or 'drop' the object that is attached to them.

  • Note that the user DOES NOT have to be the owner of the object for it to attach properly. In fact giving the object, or having the user take the object in order to transfer ownership, negates most of the usefulness of this function.
Constant Comment
ATTACH_CHEST 1 chest/sternum
ATTACH_HEAD 2 head
ATTACH_LSHOULDER 3 left shoulder
ATTACH_RSHOULDER 4 right shoulder
ATTACH_LHAND 5 left hand
ATTACH_RHAND 6 right hand
ATTACH_LFOOT 7 left foot
ATTACH_RFOOT 8 right foot
ATTACH_BACK 9 back
ATTACH_PELVIS 10 pelvis
ATTACH_MOUTH 11 mouth
ATTACH_CHIN 12 chin
ATTACH_LEAR 13 left ear
Constant Comment
ATTACH_REAR 14 right ear
ATTACH_LEYE 15 left eye
ATTACH_REYE 16 right eye
ATTACH_NOSE 17 nose
ATTACH_RUARM 18 right upper arm
ATTACH_RLARM 19 right lower arm
ATTACH_LUARM 20 left upper arm
ATTACH_LLARM 21 left lower arm
ATTACH_RHIP 22 right hip
ATTACH_RULEG 23 right upper leg
ATTACH_RLLEG 24 right lower leg
ATTACH_LHIP 25 left hip
ATTACH_LULEG 26 left upper leg
ATTACH_LLLEG 27 left lower leg
Constant Comment
ATTACH_BELLY 28 belly/stomach/tummy
ATTACH_LEFT_PEC 29 left pectoral
ATTACH_RIGHT_PEC 30 right pectoral
ATTACH_HUD_CENTER_2 31 HUD Center 2
ATTACH_HUD_TOP_RIGHT 32 HUD Top Right
ATTACH_HUD_TOP_CENTER 33 HUD Top
ATTACH_HUD_TOP_LEFT 34 HUD Top Left
ATTACH_HUD_CENTER_1 35 HUD Center
ATTACH_HUD_BOTTOM_LEFT 36 HUD Bottom Left
ATTACH_HUD_BOTTOM 37 HUD Bottom
ATTACH_HUD_BOTTOM_RIGHT 38 HUD Bottom Right
ATTACH_NECK 39 neck
ATTACH_AVATAR_CENTER 40 avatar center/root

Caveats

Permissions
  • Do not depend upon the auto-grant status of permissions. Always use the run_time_permissions event.
  • If the script lacks the permission PERMISSION_ATTACH, the script will shout an error on DEBUG_CHANNEL and the operation fails (but the script continues to run).
  • Once the PERMISSION_ATTACH permission is granted there is no way to revoke it except from inside the script (for example, with a new llRequestPermissions call). The script will only lose the permission if it is reset or the object is derezzed (deleted, detached, or taken).
  • All permissions granted prior to actually attaching appear to dumped when successfully attached via this method, including PERMISSION_ATTACH (possible security measure).
    • Until successful attachment via this method, previously granted permissions are retain as normal.
  • If you use llAttachToAvatarTemp in an object that you do not have permission to transfer, the function will fail with a script error No permission to transfer, even if you are trying to attach it to yourself.
  • Attach points can be occupied by multiple attachments.[1]
    • This was not always the case, previously if attach_point was occupied, the existing object was detached and the new attachment took it's place.
  • Objects attached to the head (and any attachment position within the head) will not be visible in First Person view (aka Mouselook) if "show attachments in mouselook" is disabled.
  • If attach_point is zero but the object was never previously attached, it defaults to the right hand (ATTACH_RHAND).
  • If the object is already attached the function fails silently, regardless if the attach_point is a different attach point.
All Issues ~ Search JIRA for related Bugs

Examples

//-- rez object on ground, drop in this script, it will request permissions to attach,
//-- and then attach to the left hand if permission is granted. if permission is denied,
//-- then the script complains.
default
{
    state_entry()
    {
        llRequestPermissions( llGetOwner(), PERMISSION_ATTACH );
    }
 
    run_time_permissions( integer vBitPermissions )
    {
        if( vBitPermissions & PERMISSION_ATTACH )
        {
            llAttachToAvatarTemp( ATTACH_LHAND );
        }
        else
        {
            llOwnerSay( "Permission to attach denied" );
        }
    }
 
    on_rez(integer rez)
    {
        if(!llGetAttached())
        { //reset the script if it's not attached.
            llResetScript();
        }
    }
 
    attach(key AvatarKey)
    {
        if(AvatarKey)
        {//event is called on both attach and detach, but Key is only valid on attach
            integer test = llGetAttached();
            if (test) {
                llOwnerSay( "The object is attached" );
            } else {
                llOwnerSay( "The object is not attached");
            }
        }
    }
}
//-- This example can demonstrate ownership transfer of an object on a temporary basis using llAttachToAvatarTemp()
//-- Whoever touches will be asked for permission to attach, and upon granting permission will have the item attach,
//-- But not appear in Inventory.
default
{
    touch_start(integer num_touches)
    {
        llRequestPermissions( llDetectedKey(0), PERMISSION_ATTACH );
    }
 
    run_time_permissions( integer vBitPermissions )
    {
        if( vBitPermissions & PERMISSION_ATTACH )
        {
            llAttachToAvatarTemp( ATTACH_LHAND );
        }
        else
        {
            llOwnerSay( "Permission to attach denied" );
        }
    }
 
    on_rez(integer rez)
    {
        if(!llGetAttached())
        { //reset the script if it's not attached.
            llResetScript();
        }
    }
}
// This example illustrates how to handle permissions before and after llAttachToAvatarTemp has been called. Because ownership
// changes when the object is attached, the initial PERMISSION_ATTACH is revoked and new permissions need to be requested.
 
integer gAttach = TRUE;
 
default
{
 
    touch_start(integer num)
    {
        if (gAttach)  // Object has not been attached yet
        {
            llRequestPermissions(llDetectedKey(0),PERMISSION_ATTACH);
            gAttach = FALSE;
        }
        else   // Object has been attached, but you still need PERMISSION_ATTACH in order to detach the object
        {
            if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH)
            {
                llDetachFromAvatar();  // Note that the object vanishes when detached, so there is no need to set gAttach = TRUE again
            }
        }
    }
 
    attach(key id)
    {
        if (id)  // Object has been attached, so request permissions again
        {
            llRequestPermissions(id,PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION);
        }
    }
 
    run_time_permissions (integer perm)
    {
        if (!gAttach)  //First time
        {
            if (perm & PERMISSION_ATTACH)
            {
                gAttach = TRUE;
                llAttachToAvatarTemp(ATTACH_HEAD);  // Initial PERMISSION_ATTACH is revoked at this point
            }
        }
        else  // Second time
        {
            if (perm & PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION)
            {
                llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
            }
        }
    }
}

An alternative solution:

// Because ownership changes when the object is attached, the initial PERMISSION_ATTACH is revoked and new permissions need to be requested.
 
default
{
    touch_start(integer num)
    {
        if (!llGetAttached()) llRequestPermissions( llDetectedKey(0), PERMISSION_ATTACH);
        else if ( llGetPermissions() & PERMISSION_ATTACH) llDetachFromAvatar();
    }
    attach(key id)
    {
        if (id) llRequestPermissions( id, PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions (integer perm)
    {
        if (!llGetAttached() && (perm & PERMISSION_ATTACH)) llAttachToAvatarTemp( ATTACH_NOSE);
        if (perm & PERMISSION_TRIGGER_ANIMATION) llStartAnimation( llGetInventoryName( INVENTORY_ANIMATION, 0));
    }
}

See Also

Events

•  run_time_permissions Permission receiving event

Functions

•  llGetPermissions Get the permissions granted
•  llGetPermissionsKey Get the agent who granted permissions
•  llRequestPermissions Request permissions
•  llDetachFromAvatar Detaches the object from the avatar
•  llGetAttached Gets the attach point number

Articles

•  Script permissions

Deep Notes

Search JIRA for related Issues

Footnotes

  1. ^ Multiple attachments per attach point were added as result of SCR-277[c]
This article wasn't helpful for you? Maybe the related article at the LSL Wiki is able to bring enlightenment.
Personal tools
In other languages