Give Contents
Version 1.0

This script is a general "unpacker" that gives the contents of a prim (with the exception of any scripts) to the owner when the object is worn (on_rez) or rezzed in world. It then deletes or detaches itself after a few seconds.

If cleanup is set to FALSE then the item will persist. In this case, touch_start can be used to give the contents as well.

Download script

// This script is free to redistribute and modify, as long as
// any copies of it can be redistributed and modified.
//
// If modifications are made please notate them in the header.
//
// Version 1.1, August 2019 - © Summer Haas


integer cleanup = TRUE;
float pause = 2.0;

give(key agent)
{
	list inventory = [];
	integer i = 0;
	integer contents = INVENTORY_ALL;

	for(i=0; i < llGetInventoryNumber(contents); i++)
	{
		//skip any scripts in the inventory
		if (llGetInventoryType(llGetInventoryName(contents,i)) != INVENTORY_SCRIPT)
			inventory += [llGetInventoryName(contents,i)];
	}

	llGiveInventoryList(agent, llGetObjectName(), inventory);
}


default
{
	state_entry()
	{
		llSetMemoryLimit(16384);
	}

	on_rez(integer start_param)
	{
		give(llGetOwner());

		if (llGetAttached() == 0 && cleanup)
		{
			llSleep(pause);
			llDie();
		}
	}

	attach(key attached)
	{
		llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);
	}

	run_time_permissions(integer perm)
	{
		if(perm & PERMISSION_ATTACH && cleanup)
		{
			llSleep(pause);
			llDetachFromAvatar();
		}
	}

	touch_start(integer total_number)
	{
		if (llDetectedKey(0) == llGetOwner())
		{
			give(llDetectedKey(0));
	
			if (cleanup)
			{
				llSleep(pause);
				llDie();
			}
		}
	}
}