Jump to content

Unpacker automation with animation


Tattooshop
 Share

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

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

Recommended Posts

Hello! I'm trying unsuccessfully to edit the animated ( it plays avatar animation ) unpacker script. Now it is unpacked on click and manually detached. How to make unpacking and detaching happen automatically?

I added ( commented lines ) to the run_time_permissions event

        llSleep(5);
        if(permissions & PERMISSION_ATTACH)
        {
            llDetachFromAvatar( );
        }

and to the attach event

llRequestPermissions(attachedAgent, PERMISSION_ATTACH );

but so far the script gives an error, what is wrong here?

Thanks in advance for any help!

string anim = "Animation_Name";

integer attached = FALSE;  
integer permissions = FALSE;

default
{
    
    state_entry()
    {
        llRequestPermissions(llGetOwner(),  PERMISSION_TRIGGER_ANIMATION);
    }
    
    run_time_permissions(integer permissions)
    {
        if (permissions > 0)
        {
            llStartAnimation(anim);
            attached = TRUE;
            permissions = TRUE;
        }

        ////////////////////////////////// I ADDED THIS:
        /*llSleep(5);
        if(permissions & PERMISSION_ATTACH)
        {
            llDetachFromAvatar( );
        }*/
    }

    attach(key attachedAgent)
    {
        if (attachedAgent != NULL_KEY)
        {
            ////////////////////////////////// AND I ADDED THAT:
            /*llRequestPermissions(attachedAgent, PERMISSION_ATTACH );*/

            attached = TRUE;
            
            if (!permissions)
            {
                llRequestPermissions(llGetOwner(),  PERMISSION_TRIGGER_ANIMATION);  
            }
        }
        
        else
        {
            attached = FALSE;
            llStopAnimation(anim);
        }
    }
    
    touch_start(integer total_number)
    {
        integer x;
        for(x = 0; x < total_number; x++)
        {
            if(llDetectedKey(x) == llGetOwner())
            {
                string InvenName;
                integer InvenNumber = llGetInventoryNumber(INVENTORY_ALL);
                list InvenList = [];
                integer y;
                string ScriptName = llGetScriptName();
                for(y = 0; y < InvenNumber; y++)
                {
                    InvenName = llGetInventoryName(INVENTORY_ALL, y);
                    if(InvenName != ScriptName) 
                    {
                        if(llGetInventoryType(InvenName) != INVENTORY_ANIMATION)
                        InvenList += [InvenName];
                    }
                }
                llGiveInventoryList(llGetOwner(), llGetObjectName(), InvenList);
            }
        }
    }
}

 

Edited by Tattooshop
Link to comment
Share on other sites

As well as asking for permission to trigger an animation in state entry you'll need to request attach permissions in order to detach.

I'm guessing, but even when you have attached an item from inventory, you may need to specifically request attach permission for the script to allow it to complete the detach? Try requesting both animation and attach perms in both the attach event and state entry.

  • Thanks 1
Link to comment
Share on other sites

33 minutes ago, Profaitchikenz Haiku said:

Try requesting both animation and attach perms in both the attach event and state entry.

Thank you very much for your prompt reply!
Here's what I got, but the script throws an error: Script trying to trigger animations but PERMISSION_TRIGGER_ANIMATION permission not set

And it is unclear how to make unpacking happen automatically without clicking?

string anim = "Animation_Name";

integer attached = FALSE;  
integer permissions = FALSE;

default
{
    
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);
    }
    
    run_time_permissions(integer permissions)
    {
        if (permissions > 0)
        {
            llStartAnimation(anim);
            attached = TRUE;
            permissions = TRUE;
        }
        llSleep(5);
        if(permissions & PERMISSION_ATTACH)
        {
            llDetachFromAvatar( );
        }
    }

    attach(key attachedAgent)
    {
        if (attachedAgent != NULL_KEY)
        {
            attached = TRUE;
            
            if (!permissions)
            {
                llRequestPermissions(attachedAgent, PERMISSION_TRIGGER_ANIMATION);  
                llRequestPermissions(attachedAgent, PERMISSION_ATTACH );
            }
        }
        
        else
        {
            attached = FALSE;
            llStopAnimation(anim);
        }
    }
    
    touch_start(integer total_number)
    {
        integer x;
        for(x = 0; x < total_number; x++)
        {
            if(llDetectedKey(x) == llGetOwner())
            {
                string InvenName;
                integer InvenNumber = llGetInventoryNumber(INVENTORY_ALL);
                list InvenList = [];
                integer y;
                string ScriptName = llGetScriptName();
                for(y = 0; y < InvenNumber; y++)
                {
                    InvenName = llGetInventoryName(INVENTORY_ALL, y);
                    if(InvenName != ScriptName) 
                    {
                        if(llGetInventoryType(InvenName) != INVENTORY_ANIMATION)
                        InvenList += [InvenName];
                    }
                }
                llGiveInventoryList(llGetOwner(), llGetObjectName(), InvenList);
            }
        }
    }
}

 

Link to comment
Share on other sites

You have to bitwise-Or the permissions required in the request, and likewise check for them explicitly with bitwise-and in the run time event. Have a look at the wiki examples for llRequestPermissions, it shows exactly how to do it.

 

For the unpacking look at the wiki for llGiveInventory... or folder.

Edited by Profaitchikenz Haiku
Spelling, what else?
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Profaitchikenz Haiku said:

Have a look at the wiki examples for llRequestPermissions

I sort of figured out how to do it, it's not clear only how to arrange it:

state_entry()

{

llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);

llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);

}

attach(key attachedAgent)

{

if (attachedAgent != NULL_KEY)

{

llRequestPermissions(attachedAgent, PERMISSION_TRIGGER_ANIMATION);

llRequestPermissions(attachedAgent, PERMISSION_ATTACH );

}

run_time_permissions(integer permissions)

{

if (permissions & (PERMISSION_ATTACH && PERMISSION_TRIGGER_ANIMATION))

{

llStartAnimation(anim);

llSleep(5);

llDetachFromAvatar( );

}

Edited by Tattooshop
Link to comment
Share on other sites

Quote

if (permissions & (PERMISSION_ATTACH && PERMISSION_TRIGGER_ANIMATION))

You need to use a single '|' instead of a double &&. && is 'logical and' so if (PERMISSION_ATTACH && PERMISSION_TRIGGER_ANIMATION) is equal to 1, not the value you intend, which is I believe (PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION). this would check if one or both of the permissions are set. If you want to check that both permissions are set, I believe you need something like

if( (perms & (PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION)) == (PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION) )

there might be a more concise way of doing it, but I can't think of it at the moment.

Edited by Quistessa
got my logic wrong.
  • Thanks 1
Link to comment
Share on other sites

Your script is failing because the calls to request permissions only set a single bit, but the test in run_time_permissions is testing to see if both bits are set, and that won't give a true result.

 

Where you have two separate calls to llRequestPermissions, combine them into one. I'm fairly sure this was in the wiki example I pointed you at, but you do it by using the single pipe character to bitwise-Or the permissions thus

 

llRequestPermissions(avatar, PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH)

 

Inside the run_time_permissions event make two separate tests, the first is

 

if( perms & PERMISSION_TRIGGER_ANIMATION)

{ do any animation there. }

 

The second test is 

 

if(perms & PERMISSION_ATTACH)

 

{ do any detaching there. }

 

 

Edited by Profaitchikenz Haiku
  • Thanks 1
Link to comment
Share on other sites

On 3/5/2021 at 4:43 PM, Profaitchikenz Haiku said:

Your script is failing because the calls to request permissions only set a single bit, but the test in run_time_permissions is testing to see if both bits are set, and that won't give a true result.

Hello! Thanks a lot for your help! It works like magic! :D👍

 

Link to comment
Share on other sites

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