Jump to content
You are about to reply to a thread that has been inactive for 131 days.

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

Recommended Posts

Posted

I have a dispensing device attached to an altbot that takes drink orders by chat then, originally, sent the drink to an avatar's inventory. With help from Die Niango we worked to change the action from sending the drink item to an avatar's inventory to attaching the item to the avatar. The re-written dispenser script seems to function as it should:

default
{
    state_entry()
    {
    }

    link_message(integer sender_num, integer num, string str, key id)
    {   
        if (num != -2000) return;
        
        if (llSubStringIndex(str, "giveinv ") == 0)
        {   
            llSay(0, "One shot coming up!");
            string item_name = llStringTrim(llGetSubString(str, 7, -1), STRING_TRIM);
            integer item_type = llGetInventoryType(item_name);
            
            if (item_type == INVENTORY_OBJECT)
            {
                // Rez the object near the avatar
                vector rez_pos = llGetPos() + <0, 0, 1>; // Rez 1 meter above the prim
                rotation rez_rot = llGetRot();
                
                // Set the owner key in a global variable in the rezzed object
               // string previous_desc = llGetObjectDesc();
                llSetObjectDesc((string)id); // Temporarily set the description to the user key
                
                llRezObject(item_name, rez_pos, ZERO_VECTOR, rez_rot, 0);
                
               // llSetObjectDesc(previous_desc); // Restore the original description
            }
            else
            {
                llSay(0, "The item is not an object and cannot be attached.");
            }
        }
    }
}

An attach() script in the inventory item being transfered to the avatar, however, is not working, leaving the item razzed above the dispenser and unattached to the avatar:

default
{
    state_entry()
    {
        // Do nothing here initially
    }
    
    on_rez(integer start_param)
    {
        // Find out which object rezzed us:
        key rezzer = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]), 0);
        
		// Retrieve the target avatar key from the rezzer's description field:
        key owner_id = (key)llList2Key(llGetObjectDetails(rezzer, [OBJECT_DESC]), 0);
        
		llRequestPermissions(owner_id, PERMISSION_TRIGGER_ANIMATION);
        llSay(0, (string)owner_id);
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION && perm & PERMISSION_ATTACH)
        {
            // Play the "hold" animation
            llStartAnimation("hold");
             
			// Attach to the avatar at the desired attachment point
            llAttachToAvatarTemp(ATTACH_RHAND);
        }
    }

   attach(key id)
    {
        if ((id == NULL_KEY) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
        {
            // Stop the animation when the object is detached
            llStopAnimation("hold");
        }
    }

    touch_start(integer total_number)
    {
        key toucher = llDetectedKey(0);
        if ((llGetPermissionsKey() == toucher)
            && (llGetPermissions() & PERMISSION_ATTACH))
        {
            llDetachFromAvatar();
        }
        // else we'll just ignore the touch
    }
}

The key of the avatar who placed the order does get pasted into the dispenser's description text field. I can't see where or why the above script should fail. Any ideas?

  • Like 2
Posted

You're never requesting the permission to attach on this line:

llRequestPermissions(owner_id, PERMISSION_TRIGGER_ANIMATION);

It should probably be

 

llRequestPermissions(owner_id, PERMISSION_TRIGGER_ANIMATION|PERMISSION_ATTACH);
Posted

YOu are right Frionil Fang, the script was misssing something every important. I made the correction, but still, no go.

default
{
    state_entry()
    {
        // Do nothing here initially
    }
    
    on_rez(integer start_param)
    {
        // Retrieve the owner key from the description field
        // Find out which object rezzed us:
        key rezzer = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]), 0);
        // Retrieve the target avatar key from the rezzer's description field:
        key owner_id = (key)llList2Key(llGetObjectDetails(rezzer, [OBJECT_DESC]), 0);
        llRequestPermissions(owner_id, PERMISSION_TRIGGER_ANIMATION|PERMISSION_ATTACH);
        llSay(0, (string)owner_id);
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION && perm & PERMISSION_ATTACH)
        {
            // Play the "hold" animation
            llStartAnimation("hold");
             // Attach to the avatar at the desired attachment point
            llAttachToAvatarTemp(ATTACH_RHAND);
        }
    }

   attach(key id)
    {
        if ((id == NULL_KEY) && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
        {
            // Stop the animation when the object is detached
            llStopAnimation("hold");
        }
    }
    touch_start(integer total_number)
    {
        key toucher = llDetectedKey(0);
        if ((llGetPermissionsKey() == toucher)
            && (llGetPermissions() & PERMISSION_ATTACH))
        {
            llDetachFromAvatar();
        }
        // else we'll just ignore the touch
    }
}

Th item rezzes but does not attach.

Posted

Ah, as it turns out, the attach script does function correctly. It was the inventory item, for some reason unknown, which was causing the problem. So everything is. now operating as it should. YAY!

  • Like 3
You are about to reply to a thread that has been inactive for 131 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
×
×
  • Create New...