Jump to content

Automatically attach an object to an avatar, from a Prim's contents?


Floofies
 Share

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

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

Recommended Posts

Hi, I'm relatively new to LSL but I have a basic understanding.

I am creating a food item that, when touched, will give a selected object from it's contents and then automatically attach to an avatar. I have seen this scripting behavior in other things, such as a fridge. Can anyone give me some pointers? All the scripts I've seen that do this are no-read, so I have no examples. I've read up on the LSL wiki, but I can only find examples for attaching a prim itself, not it's contents.

 

What I have done so far:

1. On touch, display a dialog asking to select an object.

2. On selecting an object, give the selected object to the avatar's inventory.

 

What I need to do as well:

1. Automatically attach to the right hand, and orient in the proper position.

 

Thanks. :>

Link to comment
Share on other sites

Hmm, perhaps I am missing something.

I am getting a Syntax error when I inject the relevant code. On the llAttachToAvatarTemp line.

 

Here's what my script looks like, in the relevant section:

 if(llGetSubString(message, 0, 23) == llGetSubString(llGetInventoryName(GIVE_TYPE, itra), 0, 23)) {              {        llRequestPermissions( llGetOwner(), PERMISSION_ATTACH );    }               llAttachToAvatarTemp(ATTACH_RHAND)(id, llGetInventoryName(GIVE_TYPE, itra));                jump close;            }        } while(--itra>=0);@close;

 And here's the whole thing:

//////////////////////////////////////////////////////////// [K] Kira Komarov - 2011, License: GPLv3              //// Please see: http://www.gnu.org/licenses/gpl.html     //// for legal details, rights of fair usage and          //// the disclaimer and warranty conditions.              //////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////                   CONFIGURATION                      //////////////////////////////////////////////////////////////                                                      // // The possible values for this parameter are:// 0 for textures.// 1 for sound.// 3 for landmarks.// 5 for clothing.// 6 for objects.// 7 for notecards.// 10 for scripts (the giver script will be excluded).// 13 for body parts.// 20 for animations.// 21 for gestures. // The type is 6, so using the reference above, this // script will hand out objects.integer GIVE_TYPE = 6;  //                                                      ////                  END CONFIGURATION                   //////////////////////////////////////////////////////////// integer _runner = 0;integer _comHandle = 0;list _cList = [];list _storage = []; list mFwd() {    if(_runner+1>llGetListLength(_storage)) return _cList;    return (_cList = llListInsertList(llListInsertList(llList2List(_storage, ++_runner, _runner+=9), ["<= Back"], 0), ["Next =>"], 2));}  list mBwd() {    if(_runner-19<0) return _cList;    return (_cList = llListInsertList(llListInsertList(llList2List(_storage, _runner-=19, _runner+=9), ["<= Back"], 0), ["Next =>"], 2));} default{    state_entry()    {        _storage = [];        integer itra=llGetInventoryNumber(GIVE_TYPE)-1;        do {            if(llGetInventoryName(GIVE_TYPE, itra) != llGetScriptName())                _storage += llGetSubString(llGetInventoryName(GIVE_TYPE, itra), 0, 23);        } while(--itra>=0);        _cList = llListInsertList(llListInsertList(llList2List(_storage, _runner, _runner+=9), ["<= Back"], 0), ["Next =>"], 2);    }     listen( integer channel, string name, key id, string message ) {        if(message == "<= Back") {            llDialog(id, "Would you like Regular or Chocolate flavored Dragon Spunk?:\n", mBwd(), channel);            return;        }         if(message == "Next =>") {            llDialog(id, "Would you like Regular or Chocolate flavored Dragon Spunk?:\n", mFwd(), channel);            return;        }        integer itra = llGetInventoryNumber(GIVE_TYPE)-1;        do {            if(llGetSubString(message, 0, 23) == llGetSubString(llGetInventoryName(GIVE_TYPE, itra), 0, 23)) {              {        llRequestPermissions( llGetOwner(), PERMISSION_ATTACH );    }               llAttachToAvatarTemp( ATTACH_RHAND )(id, llGetInventoryName(GIVE_TYPE, itra));                jump close;            }        } while(--itra>=0);@close;        llListenRemove(_comHandle);    }    touch_start(integer total_number)    {        integer comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;        _comHandle = llListen(comChannel, llDetectedName(0), llDetectedKey(0), "");        llDialog(llDetectedKey(0), "Would you like Regular or Chocolate flavored Dragon Spunk?:\n", _cList, comChannel);    }}
Link to comment
Share on other sites

You have a parenthesis where there should be a comma in the temp line, but also you should be rezzing the object inworld so that the avatar can touch it in order for a temp attach to work. Also, you have not requested any permissions, without which the object will not be allowed to attach.

 

The wiki entry for llAttachToAvatarTemp gives several good examples, and shows how to request permissions and where to attach them.

 

In the run-time-permissions event, check the permission has been granted, and if it has, then issue the attach statement.

 

if instead you want to give out objects that the avatar recieves into their inventory, and can attach from there by clicking, then the simplest way is to attach the object to your right hand, edit it uintil satiosfied, take it back into your inventory, and then drag it into the prim from which it will be given out. When the recepient gets it and clicks on it from their inventory, it will rememebr the attachment you set when you saved it in the first place. In that case, you do not need to call the llAttachToAvatarTemp function, as it will not work for that type of object.

  • Like 1
Link to comment
Share on other sites

Ok, I modified (pretty much just copy-pasted) the code which also rezzes the object and tracks the permissions. I now get a syntax error on the run_time_permissions line for some reason.

 

 do {            if(llGetSubString(message, 0, 23) == llGetSubString(llGetInventoryName(GIVE_TYPE, itra), 0, 23)) {  {        llRequestPermissions( llGetOwner(), PERMISSION_ATTACH );    }        run_time_permissions( integer vBitPermissions )    {        if( vBitPermissions & PERMISSION_ATTACH )        {            llAttachToAvatarTemp( ATTACH_RHAND , id, llGetInventoryName(GIVE_TYPE, itra));        }        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");            }        }    }                jump close;            }        } while(--itra>=0);@close;

 On second thought, maybe I didn't do that right. I need to create a seperate script that rezzes the object. 

Link to comment
Share on other sites

That's because you have run_time_permissions and some other event handlers inside what looks like to be part of a function, it needs to be outside, at the same level as the attach, touch, and other events

The attach event will occur just like a touch, listen, etc. So your script needs event handlers for all such events, which cannot be inside loops or functions, but must be in the current state. State_entry is such an event.

 

 

 

  • Like 1
Link to comment
Share on other sites

You know what... lol. Thanks for the help, but I realized I was going about it all wrong. I went ahead and started clean, then got the rez script working! Next I'll make the object attach itself upon rezzing. I think I'm all set, but thank you!

Link to comment
Share on other sites

There is one more little gotcha you need to know about attachToAvatarTemp, which I struggled with, as well as having to call request permisions to attach the object to the avatar, you have to specifically call requestPermissions to detach it from the avatar,.

I spent an hour banging my fingers round the keyboard before I got that sorted. So, you need to have a global string or integer somewhere that is set to attach or detach, 1 or 0, before calling requestPermissions,

Inside run_time_permissions, when you check if you have been granted attach permissions, look at the variable to see if you are to attach or detach the object. The first time you call it, to actually attach, the avatar will get the dialog asking them to OK the action, but when you make the call to detach, there is no dialog becuase it knows it already has the permissions.

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2724 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...