Jump to content

Give everything except certain item


Tattooshop
 Share

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

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

Recommended Posts

How to make this unpacker give everything except certain item, named "except.object" for example? :D

default
{
    state_entry()
    {
        llSetMemoryLimit(llGetUsedMemory() + 1024);
    }
    touch_start(integer n)
    {
        if (llDetectedKey(0) == llGetOwner()) // Detect owner
        {
            for (n--; n >= 0; n--)
            {
                integer j = llGetInventoryNumber(INVENTORY_ALL);
                for (j--; j >= 0; j--)
                {
                    string name = llGetInventoryName(INVENTORY_ALL, j);
                    if (llGetInventoryType(name) != INVENTORY_SCRIPT)
                    {
                        llGiveInventory(llDetectedKey(n), name);
                    }
                }
            }
        }
    }
}

 

Link to comment
Share on other sites

Check the object's name at the same time you check it's not a script:

if (name != "except.object" && llGetInventoryType(name) != INVENTORY_SCRIPT)

One thing, though: if you're giving several objects at once I'd be inclined to use llGiveInventoryList, which puts all the items together in a new folder in the target's inventory and only triggers a single accept/decline dialog.

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, KT Kingsley said:

Check the object's name at the same time you check it's not a script:


if (name != "except.object" && llGetInventoryType(name) != INVENTORY_SCRIPT)

One thing, though: if you're giving several objects at once I'd be inclined to use llGiveInventoryList, which puts all the items together in a new folder in the target's inventory and only triggers a single accept/decline dialog.

I used another unpacker with list and added your line - works perfectly! Thank you! :)

string EXCEPT_ITEM_NAME = "except.object"; // Item you want to exclude

default
{
    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;
                for(y = 0; y < InvenNumber; y++)
                {
                    InvenName = llGetInventoryName(INVENTORY_ALL, y);
                    if(InvenName != EXCEPT_ITEM_NAME && llGetInventoryType(InvenName) != INVENTORY_SCRIPT) 
                    InvenList += [InvenName];
                }          
                llGiveInventoryList(llGetOwner(), llGetObjectName(), InvenList);
            }
        }
    }
}

 

Edited by Tattooshop
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Another snippet (which may be a bit faster in big inventories) is to create the list as per @Tattooshop and @Innula Zenovka's suggestions, but instead of the check in the loop, add a deletion clause after. This prevents the check for the item to be excluded running for every item in prim inventory.  With small prim inventories this makes no difference, but if your prim has a large inventory, this might impact performance.

I often use this to exclude the giver script as below
 

list glInventoryToGive;

CreateInventoryList()
{
	glInventoryToGive = [];

	integer iInvCount = llGetInventoryNumber(INVENTORY_ALL);
	if (iInvCount == 1) //Only this script present, so exit
	{
		return;
	}
	
	integer i;
	for (i = 0; i < iInvCount; ++i)
    	{
    		glInventoryToGive += llGetInventoryName(INVENTORY_ALL, i);
    	}

	i = llListFindList(glMyInventoryList, [llGetScriptName()]); //Find this script, because we don't want to give that
	if (~i)
	{
    		glMyInventoryList = llDeleteSubList(glMyInventoryList, i, i);  //Item is in the list, so delete from the list
	}
}

In the above example, you can replace llGetScriptName() with your object's name.

  • Like 1
Link to comment
Share on other sites

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