OsForceAttachToOtherAvatarFromInventory

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Add new exemples)
Line 13: Line 13:
 
|delay=0
 
|delay=0
 
|ossl_example=<source lang="lsl">
 
|ossl_example=<source lang="lsl">
 +
//
 +
// osForceAttachToOtherAvatarFromInventory Script Exemple
 +
//
  
//Author: mewtwo0641
+
string AvatarUuid = "<TARGET_AVATAR_UUID>";
//Simple example for osForceAttachToOtherAvatarFromInventory that attaches a list of items on touch
+
string ObjectName;
  
//List of items in object inventory to be attached in format: item_name, attach_point
+
default
list items =
+
{
[
+
    state_entry()
"Belt", (string)ATTACH_BELLY,
+
    {
"Hat", (string)ATTACH_HEAD,
+
        ObjectName = llGetInventoryName(INVENTORY_ALL, 0);
        "Left Shoe", (string)ATTACH_LFOOT,
+
 
        "Right Shoe", (string)ATTACH_RFOOT
+
        if (ObjectName == "")
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Inventory object missing ...");
 +
        }
 +
 
 +
        else if (AvatarUuid == "<USER_UUID_TO_EJECT>" || !osIsUUID(AvatarUuid))
 +
        {
 +
            llOwnerSay("Please replace <TARGET_AVATAR_UUID> with a valid user uuid");
 +
        }
 +
 
 +
        else
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Touch to see osForceAttachToOtherAvatarFromInventory attach the object to the target avatar's left hand.");
 +
            llSay(PUBLIC_CHANNEL, "Object name is " + ObjectName + " and target avatar uuid is " + AvatarUuid + " (" + osKey2Name(AvatarUuid) + ")");
 +
        }
 +
    }
 +
 
 +
 
 +
    touch_start(integer number)
 +
    {
 +
        osForceAttachToOtherAvatarFromInventory(AvatarUuid, ObjectName, ATTACH_LHAND);
 +
    }
 +
 
 +
    // The attach event is called on both attach and detach.
 +
    attach(key id)
 +
    {
 +
        // Test if is a valid key and not NULL_KEY ('id' is only valid on attach)
 +
        if (id && id != NULL_KEY)
 +
        {
 +
            llOwnerSay("The object " + ObjectName + " is attached to " + llKey2Name(id));
 +
        }
 +
 
 +
        else
 +
        {
 +
            llOwnerSay("The object is not attached!");
 +
        }
 +
    }
 +
 
 +
    on_rez(integer param)
 +
    {
 +
        // Reset the script if it's not attached.
 +
        if (!llGetAttached())       
 +
        {
 +
            llResetScript();
 +
        }
 +
    }
 +
}
 +
</source>
 +
''' For YEngine: '''
 +
<source lang="lsl">
 +
//
 +
// osForceAttachToOtherAvatarFromInventory Script Exemple
 +
//
 +
 
 +
string AvatarUuid = "<TARGET_AVATAR_UUID>";
 +
string ObjectName;
 +
 
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        ObjectName = llGetInventoryName(INVENTORY_ALL, 0);
 +
 
 +
        if (ObjectName == "")
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Inventory object missing ...");
 +
        }
 +
 
 +
        else if (AvatarUuid == "<USER_UUID_TO_EJECT>" || !osIsUUID(AvatarUuid))
 +
        {
 +
            llOwnerSay("Please replace <TARGET_AVATAR_UUID> with a valid user uuid");
 +
        }
 +
 
 +
        else
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Touch to see osForceAttachToOtherAvatarFromInventory attach the object to the target avatar's left hand.");
 +
            llSay(PUBLIC_CHANNEL, "Object name is " + ObjectName + " and target avatar uuid is " + AvatarUuid + " (" + osKey2Name(AvatarUuid) + ")");
 +
        }
 +
    }
 +
 
 +
 
 +
    touch_start(integer number)
 +
    {
 +
        osForceAttachToOtherAvatarFromInventory(AvatarUuid, ObjectName, ATTACH_LHAND);
 +
    }
 +
 
 +
    // The attach event is called on both attach and detach.
 +
    attach(key id)
 +
    {
 +
        // Test if is a valid key ('id' is only valid on attach)
 +
        if (id)
 +
        {
 +
            llOwnerSay("The object " + ObjectName + " is attached to " + llKey2Name(id));
 +
        }
 +
 
 +
        else
 +
        {
 +
            llOwnerSay("The object is not attached!");
 +
        }
 +
    }
 +
 
 +
    on_rez(integer param)
 +
    {
 +
        // Reset the script if it's not attached.
 +
        if (!llGetAttached())       
 +
        {
 +
            llResetScript();
 +
        }
 +
    }
 +
}
 +
</source>
 +
''' Another exemple: '''
 +
<source lang="lsl">
 +
// Simple example for osForceAttachToOtherAvatarFromInventory that attaches a list of items on touch
 +
// Author: mewtwo0641
 +
 
 +
// List of items in object inventory to be attached in format: item_name, attach_point
 +
list items = [
 +
    "Belt", (string)ATTACH_BELLY,
 +
    "Hat", (string)ATTACH_HEAD,
 +
    "Left Shoe", (string)ATTACH_LFOOT,
 +
    "Right Shoe", (string)ATTACH_RFOOT
 
];
 
];
  
Line 30: Line 154:
 
default
 
default
 
{
 
{
     touch_start(integer x)
+
     touch_start(integer number)
 
     {
 
     {
 
         toucher = llDetectedKey(0);
 
         toucher = llDetectedKey(0);
       
+
         integer i;
         integer i = 0;
+
 
       
+
         for(i = 0; i < llGetListLength(items); i++)
         for(i; i < llGetListLength(items); i++)
+
 
         {   
 
         {   
 
             string name = llList2String(items, i);       
 
             string name = llList2String(items, i);       
Line 45: Line 168:
 
     }
 
     }
 
}
 
}
 
 
</source>
 
</source>
|additional_info=This function was added in 0.7.4-post-fixes
+
|additional_info=This function was added in 0.7.4-post-fixes.<br>
 +
See [http://wiki.secondlife.com/wiki/Template:LSL_Constants_Attachment Attachment Points] for the complete list of LSL Attachment Points Constants.
 
}}
 
}}
 +
'''See Also: '''
 +
* [[osForceAttachToAvatar]]
 +
* [[osForceAttachToAvatarFromInventory]]
 +
* [[osForceAttachToOtherAvatarFromInventory]]
 +
* [[osForceDetachFromAvatar]]
 +
* [[osForceDropAttachment]]
 +
* [[osForceDropAttachmentAt]]
 +
* [[osDropAttachment]]
 +
* [[osDropAttachmentAt]]

Revision as of 11:29, 24 November 2020

osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, integer attachmentPoint)
Attach an inventory item in the object containing this script to any avatar in the region without asking for PERMISSION_ATTACH. Nothing happens if the avatar is not in the region.
  • rawAvatarId - The UUID of the avatar to which to attach. Nothing happens if this is not a UUID.
  • itemName - The name of the item. If this is not found then a warning is said to the owner.
  • attachmentPoint - The attachment point. For example, ATTACH_CHEST.

In OpenSimulator 0.7.4.

Threat Level VeryHigh
Permissions Use of this function is always disabled by default
Extra Delay 0 seconds
Example(s)
//
// osForceAttachToOtherAvatarFromInventory Script Exemple
//
 
string AvatarUuid = "<TARGET_AVATAR_UUID>";
string ObjectName;
 
default
{
    state_entry()
    {
        ObjectName = llGetInventoryName(INVENTORY_ALL, 0);
 
        if (ObjectName == "")
        {
            llSay(PUBLIC_CHANNEL, "Inventory object missing ...");
        }
 
        else if (AvatarUuid == "<USER_UUID_TO_EJECT>" || !osIsUUID(AvatarUuid))
        {
            llOwnerSay("Please replace <TARGET_AVATAR_UUID> with a valid user uuid");
        }
 
        else
        {
            llSay(PUBLIC_CHANNEL, "Touch to see osForceAttachToOtherAvatarFromInventory attach the object to the target avatar's left hand.");
            llSay(PUBLIC_CHANNEL, "Object name is " + ObjectName + " and target avatar uuid is " + AvatarUuid + " (" + osKey2Name(AvatarUuid) + ")");
        }
    }
 
 
    touch_start(integer number)
    {
        osForceAttachToOtherAvatarFromInventory(AvatarUuid, ObjectName, ATTACH_LHAND);
    }
 
    // The attach event is called on both attach and detach.
    attach(key id)
    {
        // Test if is a valid key and not NULL_KEY ('id' is only valid on attach)
        if (id && id != NULL_KEY)
        {
            llOwnerSay("The object " + ObjectName + " is attached to " + llKey2Name(id));
        }
 
        else 
        {
            llOwnerSay("The object is not attached!");
        }
    }
 
    on_rez(integer param)
    {
        // Reset the script if it's not attached.
        if (!llGetAttached())        
        {
            llResetScript();
        }
    }
}

For YEngine:

//
// osForceAttachToOtherAvatarFromInventory Script Exemple
//
 
string AvatarUuid = "<TARGET_AVATAR_UUID>";
string ObjectName;
 
default
{
    state_entry()
    {
        ObjectName = llGetInventoryName(INVENTORY_ALL, 0);
 
        if (ObjectName == "")
        {
            llSay(PUBLIC_CHANNEL, "Inventory object missing ...");
        }
 
        else if (AvatarUuid == "<USER_UUID_TO_EJECT>" || !osIsUUID(AvatarUuid))
        {
            llOwnerSay("Please replace <TARGET_AVATAR_UUID> with a valid user uuid");
        }
 
        else
        {
            llSay(PUBLIC_CHANNEL, "Touch to see osForceAttachToOtherAvatarFromInventory attach the object to the target avatar's left hand.");
            llSay(PUBLIC_CHANNEL, "Object name is " + ObjectName + " and target avatar uuid is " + AvatarUuid + " (" + osKey2Name(AvatarUuid) + ")");
        }
    }
 
 
    touch_start(integer number)
    {
        osForceAttachToOtherAvatarFromInventory(AvatarUuid, ObjectName, ATTACH_LHAND);
    }
 
    // The attach event is called on both attach and detach.
    attach(key id)
    {
        // Test if is a valid key ('id' is only valid on attach)
        if (id)
        {
            llOwnerSay("The object " + ObjectName + " is attached to " + llKey2Name(id));
        }
 
        else 
        {
            llOwnerSay("The object is not attached!");
        }
    }
 
    on_rez(integer param)
    {
        // Reset the script if it's not attached.
        if (!llGetAttached())        
        {
            llResetScript();
        }
    }
}

Another exemple:

// Simple example for osForceAttachToOtherAvatarFromInventory that attaches a list of items on touch
// Author: mewtwo0641
 
// List of items in object inventory to be attached in format: item_name, attach_point
list items = [
    "Belt", (string)ATTACH_BELLY,
    "Hat", (string)ATTACH_HEAD,
    "Left Shoe", (string)ATTACH_LFOOT,
    "Right Shoe", (string)ATTACH_RFOOT
];
 
key toucher;
 
default
{
    touch_start(integer number)
    {
        toucher = llDetectedKey(0);
        integer i;
 
        for(i = 0; i < llGetListLength(items); i++)
        {  
            string name = llList2String(items, i);      
            integer point = (integer)llList2String(items, i + 1);            
            osForceAttachToOtherAvatarFromInventory(toucher, name, point);
            i++;
        }
    }
}
Notes
This function was added in 0.7.4-post-fixes.

See Attachment Points for the complete list of LSL Attachment Points Constants.


See Also:

Personal tools
General
About This Wiki