Jump to content

Auto-Attach Script


CamdenJ
 Share

You are about to reply to a thread that has been inactive for 448 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have seen it, mainly as related to AvSitter. I click on an object and am asked permission to attach the object and it autoattaches. Anyone know where I can find this script? The menu is black not the blue menu. I have searched the MP and am unable to find it.

Link to comment
Share on other sites

From the wiki:

Quote
//-- 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();
        }
    }
}

https://wiki.secondlife.com/wiki/LlAttachToAvatarTemp

  • Like 1
  • Thanks 3
Link to comment
Share on other sites

The OP mentioned AVsitter, and the other option is to use the "AVobject" script distributed open-source with AVsitter, specifically the one already compiled to the AVsitter experience so it will auto-attach a rezzed prop without requesting permissions each time, for those who have granted experience permissions to that experience. (Presumably that's not the case as described, though, or the OP wouldn't be seeing a menu at all.)

This is assuming the to-be-attached object is rezzed on command, not just a thing in-world to be attached once and never again available to anybody else (for which one might use plain old llAttachToAvatar() so it at least stayed in their inventory).

In any case, the permissions and attachment script must be in the object being attached, not in an object that rezzes it (so that object must be effectively full-perm to you, modulo slam bit shenanigans). The rezzer, however, may look like the thing to be attached and contain a touch script to relay the key of the toucher so the rezzed attachment knows to whom it should attach. 

 

Link to comment
Share on other sites

57 minutes ago, CamdenJ said:

Thank you. This is what I am looking for but my object has other objects that I want to attach. Let's say, when someone clicks on a pitcher, then they receive a glass of water.

You may need a pair of scripts. One for the "giving" object, one for the "given" object.

  • On touch, "giving" rezzes "given", and wait until "given" is ready
    • Can be as simple as waiting for a couple of seconds, or opens a listener and wait until "given" sends a 'ready' to the listener
  • On rez, "given" starts a listener
  • "Giving" object tells "given" the UUID of the avatar
  • "Given" does the temp-attach trick and removes the listener
    • Optionally, "given" script also deletes itself to reduce sim load

That's my naive take... maybe someone can tell a better way?

Link to comment
Share on other sites

8 hours ago, primerib1 said:

maybe someone can tell a better way?

You rez the object with the start parameter as the llHash of the person to attach to, then the rezzed object does a llSensor or llGetAgentList in on_rez and searches for the avatar who's hashed key matches, then requests permissions and attaches to them.

Roughly (I'm too lazy to test and debug):

//Rezzer:
llRezAtRoot(myObj, rezPos, rezVel, rezRot, llHash(whoToGiveTo));

//Rezzed object:
on_rez(integer hash)
{   list nearby = llGetAgentList(AGENT_LIST_PARCEL,[]);
    integer i = llGetListLength(nearby);
    key agent;
    while( (llHash(agent=llList2Key(nearby,~--i))!=hash) && (i>-1) ); // empty while loop convenient for variable filling.
    if(agent)
    {   llRequestPermission(agent,PERMISSION_ATTACH);
        llSetTimerEvent(15.0); // in the timer event, die because nobody attached the object.
    }else
    {   llSay(0,"Warning, agent to attach to not found, destroying.");
     	llDie();
    }
}
timer()
{   llSay(0,"permission not granted, dieing.");
    llDie();
}
run_time_permissions(key who, integer perms)
{   llSetTimerEvent(0.0); // don't die.
    llAttachToAvatarTemp(who,0);
}

Alternatively, you could store the key to attach to in the the description or invisible hover text of the rezzer, which you could fetch from the rezzed object with:

key parent = llList2Key(llGetObjectDetails(llGetKey(),[OBJECT_REZZER_KEY]),0);
string parent_text = llList2String(llGetObjectDetails(parent,[OBJECT_TEXT]),0);
string parent_desc = llList2String(llGetObjectDetails(parent,[OBJECT_DESC]),0);

 

Edited by Quistess Alpha
  • Thanks 1
Link to comment
Share on other sites

9 hours ago, Qie Niangao said:

(for which one might use plain old llAttachToAvatar() so it at least stayed in their inventory).

A little off-topic, but llAttachToAvatar is a bit tricky to use correctly, because it does not automatically transfer ownership like the temporary version.

Quote

The only clean way I know of to transfer ownership (via script) other than temp-attach is to set the object for sale and have the new owner buy it.

It might be interesting to try and see what happens if you try to llAttachToAvatar an object which is already temp-attached.

Edited by Quistess Alpha
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

7 hours ago, Quistess Alpha said:

You rez the object with the start parameter as the llHash of the person to attach to, then the rezzed object does a llSensor or llGetAgentList in on_rez and searches for the avatar who's hashed key matches, then requests permissions and attaches to them.

A bit tangential ...

Is it not enough to just use the first 4 bytes of the UUID?

So something like

(integer)("0x" + whoToGiveTo)

Link to comment
Share on other sites

21 minutes ago, primerib1 said:

Is it not enough to just use the first 4 bytes of the UUID?

That should have the same probability of a collision, but since we have llHash, we might as well use it.

On another tangent, I vaguely remember reading somewhere on the wiki that someone found an example of a linden and a resident who's UUIDs differed by only one or two hex characters. I don't know if there are any known examples of two avatars who's UUIDs hash to the same value.

  • Thanks 1
Link to comment
Share on other sites

21 hours ago, primerib1 said:

On touch, "giving" rezzes "given", and wait until "given" is ready

  • Can be as simple as waiting for a couple of seconds, or opens a listener and wait until "given" sends a 'ready' to the listener

The object_rez event is raised once the new object is ready to receive messages.

The new object should have an active listener before it's rezzed, in state_entry.

This way you don't need two-way communication while ensuring that the message will arrive even in lag or with a delayed script start.

Link to comment
Share on other sites

11 minutes ago, Wulfie Reanimator said:

The new object should have an active listener before it's rezzed, in state_entry.

Ahh makes sense...

So the "given" object should be created and have its script(s) running, before "Take"ing it into inventory to be placed into the "Giver", rite?

And don't use llScriptReset() in on_rez probably :D

Therefore when the "given" object is (re)rezzed, the script simply resumes with listener immediately active, and the "Giver" just send the UUID via a predefined channel, and the listen() event of the "given" object can simply pick up from the queue...

Um, am I getting these correctly?

  • Like 2
Link to comment
Share on other sites

3 hours ago, CamdenJ said:

Thank you. This is what I am looking for but my object has other objects that I want to attach. Let's say, when someone clicks on a pitcher, then they receive a glass of water.

... hasn't this been asked before?

And discussed quite a bit?

Link to comment
Share on other sites

I'm not sure what the question is here, but maybe it's just a question of rezzing different attachments depending on what part of the rezzer object is touched. That's a pretty common thing to do, all depending on the construction of the rezzer (e.g., maybe there's a list of which attachment to rez from inventory for each possible llDetectedTouchFace(), or maybe for a multi-link rezzer a list of link names* paired with the associated inventory names to be rezzed as attachments).

(Sorry if this is all too basic. It's nothing to do with how to make stuff auto-attach, but that part has been pretty much addressed here already.)

__________________
* e.g., llGetLinkName ( llDetectedLinkNumber ( 0 ) ) in a touch_start / _end event. 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 448 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...