LlAttachToAvatar

From Second Life Wiki
Jump to: navigation, search

Summary

Function: llAttachToAvatar( integer attach_point );

Attaches the object to the avatar who has granted permission to the script. The object is taken into the users inventory and attached to attach_point.

• 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 and it must be granted by the owner. If attach_point is zero, then the object attaches to the attach point it was most recently attached to.

KBnote.png Note: Constants in italic require a viewer compatible with the Project Bento skeleton.
Body
Constant # Comment
ATTACH_HEAD 2 head
ATTACH_NOSE 17 nose
ATTACH_MOUTH 11 mouth
ATTACH_FACE_TONGUE 52 tongue
ATTACH_CHIN 12 chin
ATTACH_FACE_JAW 47 jaw
ATTACH_LEAR 13 left ear
ATTACH_REAR 14 right ear
ATTACH_FACE_LEAR 48 left ear (extended)
ATTACH_FACE_REAR 49 right ear (extended)
ATTACH_LEYE 15 left eye
ATTACH_REYE 16 right eye
ATTACH_FACE_LEYE 50 left eye (extended)
ATTACH_FACE_REYE 51 right eye (extended)
ATTACH_NECK 39 neck
ATTACH_LSHOULDER 3 left shoulder
ATTACH_RSHOULDER 4 right shoulder
ATTACH_LUARM 20 left upper arm
ATTACH_RUARM 18 right upper arm
ATTACH_LLARM 21 left lower arm
ATTACH_RLARM 19 right lower arm
ATTACH_LHAND 5 left hand
ATTACH_RHAND 6 right hand
ATTACH_LHAND_RING1 41 left ring finger
ATTACH_RHAND_RING1 42 right ring finger
ATTACH_LWING 45 left wing
ATTACH_RWING 46 right wing
ATTACH_CHEST 1 chest/sternum
ATTACH_LEFT_PEC 29 left pectoral
ATTACH_RIGHT_PEC 30 right pectoral
ATTACH_BELLY 28 belly/stomach/tummy
ATTACH_BACK 9 back
ATTACH_TAIL_BASE 43 tail base
ATTACH_TAIL_TIP 44 tail tip
ATTACH_AVATAR_CENTER 40 avatar center/root
ATTACH_PELVIS 10 pelvis
ATTACH_GROIN 53 groin
ATTACH_LHIP 25 left hip
ATTACH_RHIP 22 right hip
ATTACH_LULEG 26 left upper leg
ATTACH_RULEG 23 right upper leg
ATTACH_RLLEG 24 right lower leg
ATTACH_LLLEG 27 left lower leg
ATTACH_LFOOT 7 left foot
ATTACH_RFOOT 8 right foot
ATTACH_HIND_LFOOT 54 left hind foot
ATTACH_HIND_RFOOT 55 right hind foot
HUD
Constant Comment
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

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).
  • If PERMISSION_ATTACH is granted by anyone other than the owner, then when the function is called an error will be shouted on DEBUG_CHANNEL.
  • 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) or the script is reset or deleted.
  • 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 disable.
  • 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. -- SCR-137

Important Issues

~ All Issues ~ Search JIRA for related Bugs
   llAttachToAvatar can cause a stack/heap collision in certain circumstances
   Add companion command to llAttachToAvatar() to allow attaching multiple items in same attachment point

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 )     
            llAttachToAvatar( 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 id)
    {
        // The attach event is called on both attach and detach, but 'id' is only valid on attach
        if (id)
            llOwnerSay( "The object is attached to " + llKey2Name(id) );
        else 
            llOwnerSay( "The object is not attached");
    }
}

See Also

Events

•  run_time_permissions Permission receiving event
•  attach

Functions

•  llGetPermissions Get the permissions granted
•  llGetPermissionsKey Get the agent who granted permissions
•  llRequestPermissions Request permissions
•  llAttachToAvatarTemp Attach an object to any avatar but only temporarily
•  llDetachFromAvatar Detaches the object from the avatar
•  llGetAttached Gets the attach point number (that the object is attached to)

Articles

•  Script permissions

Deep Notes

All Issues

~ Search JIRA for related Issues
   llAttachToAvatar() can cause parentless attachments that can subsequently crash the client when selected
   Allow llAttachToAvatar() to switch attachment locations
   llAttachToAvatar can cause a stack/heap collision in certain circumstances
   Add companion command to llAttachToAvatar() to allow attaching multiple items in same attachment point

Footnotes

  1. ^ Multiple attachments per attach point were added as result of SCR-277

Signature

function void llAttachToAvatar( integer attach_point );

Haiku

Embrace me. I'm yours
Forever. Even detached
To inventory.