Jump to content

LlAttachToAvatar

From OSgrid Wiki
Revision as of 16:00, 30 December 2017 by Osgridadmin (talk | contribs) (→Function: llAttachToAvatar( integer attachment );)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Function: llAttachToAvatar( integer attachment );

Attaches the object to the avatar who has granted permission to the script. The object is taken into the users inventory and attached to the attach point attachment.
• integer attachment – ATTACH_* constant or valid value (see the tables below)

Requires the PERMISSION_ATTACH permission, granted by the owner, to run.
If attachment is zero, then the object attaches to the attach point it was most recently attached to.

Constant Comment
LINK_ROOT 1 sends to root prim in a linked set
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
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
Constant Comment
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
ATTACH_BELLY 28 belly/stomach/tummy
ATTACH_RPEC 29 left pectoral
ATTACH_LPEC 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


Caveats
• 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. The script will only lose the permission if it is reset or the object derezzed (deleted, detached, or taken).
• The call will fail if the avatar is not the owner of the object being attached, even if PERMISSION_ATTACH has been properly granted.
• Two objects cannot be attached to the same attachment point at the same time. • 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 attachment is zero but the object was never previously attached, it defaults to the right hand (ATTACH_RHAND).

Examples

<source lang="lsl">

//-- 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 (PERMISSION_ATTACH & vBitPermissions)
       {
           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 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");
           }
       }
   }

</source>

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