I've used this a lot for my packaged products. Iv'e always given it out with full perms, but it seems about time to share it with the wiki folks here as well. --
DedricMauriac
- When owner touches the object, a folder is given to them containing all copyable items in the contents excluding the script and any specified items.
- When a non-owner touches the object, they get an information notecard (if present), and a landmark (if present) as well as a message that they are not the owner
- When the creator modifies inventory, permissions of each item are sent to the owner. This helps me a lot to make sure I have permissions setup accordingly.
list exclude = []; // list of inventory to exclude from list
string prefix = ".: Dedric Mauriac :."; // prefix of folder given to owner with inventory
string packageSuffix = " (boxed)"; // suffix of package (usually to indicate it is boxed
string infoSuffix = ""; // only notecards with this suffix will be handed out as package information
string info; // information notecard to be given to anyone who is not the owner
string landmark; // store landmark to be given to anyone who is not the owner
list inventory; // inventory to be handed out to the end-user
string product; // name of the product
//Strife says: I optimized "-(1 + llStringLength(value))" to "~llStringLength(value)"
//also did some small code clean up etc. The 'endsWith' function works differently now.
//it will really only effect infoSuffix. Don't forget to set one ^^ (even if you don't use it).
init()
{
info = landmark = "";
product = productName();
makeInventoryList();
if (inventory == [])
llSetText("", <0.0,0.0,0.0>, 0.0);
else
llSetText("Touch me to unpack\nyour new " + product + ".",<1.0,1.0,1.0>,1.0);
checkInventoryPermissions();
}
makeInventoryList()
{
inventory = [];
integer i;
integer n = llGetInventoryNumber(INVENTORY_ALL);
for(i = 0; i < n; ++i)
{
string name = llGetInventoryName(INVENTORY_ALL, i);
if(llGetInventoryPermMask(name, MASK_OWNER) & PERM_COPY)
if(include(name))
{
inventory += [name];
if(isInfo(name)) info = name;
else if(isLandmark(name)) landmark = name;
}
}
}
string productName()
{
string name = llGetObjectName();
if(endsWith(name, packageSuffix))
name = llGetSubString(name, 0, ~llStringLength(packageSuffix));
return name;
}
checkInventoryPermissions()
{
if(llGetOwner() == llGetCreator())
{
llOwnerSay(permissionString(llGetObjectPermMask(MASK_NEXT)));
integer count = llGetInventoryNumber(INVENTORY_ALL);
integer i;
for(i = 0; i < count; ++i)
checkPermissions(llGetInventoryName(INVENTORY_ALL, i));
}
}
integer include(string name)
{
if(name != llGetScriptName())
return (llListFindList(exclude, [name]) == -1);
return FALSE;
}
integer isLandmark(string name)
{
if(llGetInventoryType(name) == INVENTORY_LANDMARK)
if(llGetInventoryPermMask(name, MASK_OWNER) & PERM_TRANSFER)
return TRUE;
return FALSE;
}
integer isInfo(string name)
{
if(llGetInventoryType(name) == INVENTORY_NOTECARD)
if(llGetInventoryPermMask(name, MASK_OWNER) & PERM_TRANSFER)
return endsWith(name, infoSuffix);
return FALSE;
}
integer endsWith(string text, string value)
{
return llDeleteSubString(text, 0, ~llStringLength(value)) == value;
}
checkPermissions(string name)
{
integer mask = llGetInventoryPermMask(name, MASK_NEXT);
llOwnerSay(name + ": " + permissionString(mask));
}
string permissionString(integer mask)
{
list perms = [];
if(mask & PERM_COPY) perms += "copy";
if(mask & PERM_MODIFY) perms += "modify";
if(mask & PERM_TRANSFER) perms += "transfer";
if(perms == []) perms = ["limited"];
return llList2CSV(perms);
}
default
{
state_entry()
{
init();
}
on_rez(integer start_param)
{
init();
}
touch_start(integer total_number)
{
integer i = 0;
for(i = 0; i < total_number; ++i)
if(llDetectedKey(i) == llGetOwner())
{
if(llGetListLength(inventory))
{
llGiveInventoryList(llGetOwner(), prefix + " " + product, inventory);
llOwnerSay("Your items are now in your inventory in a folder called " + prefix + " " + product + ".");
}
}
else
{
llOwnerSay("Only the owner can unpack me.");
if(info) llGiveInventory(llDetectedKey(i), info);
if(landmark) llGiveInventory(llDetectedKey(i), landmark);
}
}
changed(integer change)
{
if(change & CHANGED_INVENTORY) init();
}
}
ScriptLibrary