Difference between revisions of "User talk:Prajna Vella"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 9: Line 9:
//
//
// The script will not give any no-transfer items (because it can't, just as you can't)
// The script will not give any no-transfer items (because it can't, just as you can't)
// nor will it give any no-copy items (because llGiveInventoryList() doesn't allow it).
// nor will it add no-copy items because llGiveInventoryList() doesn't allow it.


string version = "1.0"; // the script version number
string version = "1.0"; // the script version number
Line 19: Line 19:
// this could have been included in the getList() function but the script is
// this could have been included in the getList() function but the script is
// much more readable if it is done here.
// much more readable if it is done here.
addItem(string item) {
addItem(string itemName) {
// get the permissions the object owner has for this item
// get the permissions the object owner has for this item
integer ownerPerms = llGetInventoryPermMask(item, MASK_OWNER);
integer ownerPerms = llGetInventoryPermMask(itemName, MASK_OWNER);
// only add items the owner has permission to copy and transfer
// only add items the owner has permission to copy and transfer
if ((ownerPerms & (PERM_COPY | PERM_TRANSFER)) == (PERM_COPY | PERM_TRANSFER))
if ((ownerPerms & (PERM_COPY | PERM_TRANSFER)) == (PERM_COPY | PERM_TRANSFER))
// add the item to the list
// add the item to the list
contents += item;
contents += itemName;
else
else
llOwnerSay("Couldn't add '" + item + "' because you must have transfer and copy permissions.");
llOwnerSay("Couldn't add '" + itemName + "' because you must have transfer and copy permissions.");
}
}


Line 35: Line 35:
contents = [];
contents = [];
// how many items are there in the contents?
// how many items are there in the contents?
integer item = llGetInventoryNumber(INVENTORY_ALL);
integer items = llGetInventoryNumber(INVENTORY_ALL);
// we find out the name of this script here so we only have to do it once
// we find out the name of this script here so we only have to do it once
string thisScript = llGetScriptName();
string thisScript = llGetScriptName();
// this efficiently refers to the current item and will loop until we have reached item 0
// this efficiently refers to the current item and will loop until we have reached item 0
while (item) {
while (items) {
// this line gets the item name but first decrements the item counter
// this line gets the item name but first decrements the item counter
// it is very efficient and takes care of the fact itemes are numbered starting with 0
// it is very efficient and takes care of the fact itemes are numbered starting with 0
string thisItem = llGetInventoryName(INVENTORY_ALL, --item);
string thisItem = llGetInventoryName(INVENTORY_ALL, --items);
// we need to check we don't give a copy of this script
// we need to check we don't give a copy of this script
if (thisItem != thisScript)
if (thisItem != thisScript)

Revision as of 08:37, 4 May 2009

Sorry about the mess; I'm just practising my wiki editing.

<lsl> // Give object contents in a folder to AV on touch - by Prajna Vella // // This script can be put in a 'giver' object along with the items you want to give to // anyone who touches the object. If you want to add an item, just add it to the // object's contents; the script will notice the change and update the list. // // The script will not give any no-transfer items (because it can't, just as you can't) // nor will it add no-copy items because llGiveInventoryList() doesn't allow it.

string version = "1.0"; // the script version number string folder = "Ephemera Gifts"; // the name of the folder we will give to the AV that touches the object string title = "Gifts"; // the floating title for the giver object list contents; // the list of items we will put in the folder

// check we can give the item and if so add it to the list // this could have been included in the getList() function but the script is // much more readable if it is done here. addItem(string itemName) { // get the permissions the object owner has for this item integer ownerPerms = llGetInventoryPermMask(itemName, MASK_OWNER); // only add items the owner has permission to copy and transfer if ((ownerPerms & (PERM_COPY | PERM_TRANSFER)) == (PERM_COPY | PERM_TRANSFER)) // add the item to the list contents += itemName; else llOwnerSay("Couldn't add '" + itemName + "' because you must have transfer and copy permissions."); }

// get the list of the items we will give getList() { // empty the list of items contents = []; // how many items are there in the contents? integer items = llGetInventoryNumber(INVENTORY_ALL); // we find out the name of this script here so we only have to do it once string thisScript = llGetScriptName(); // this efficiently refers to the current item and will loop until we have reached item 0 while (items) { // this line gets the item name but first decrements the item counter // it is very efficient and takes care of the fact itemes are numbered starting with 0 string thisItem = llGetInventoryName(INVENTORY_ALL, --items); // we need to check we don't give a copy of this script if (thisItem != thisScript) addItem(thisItem); } }

// we do this as a user defined function so it can be called from both state_entry() and changed() events config() { // tell the owner what is happening and get the list of items to give llOwnerSay("Version " + version); llOwnerSay("Configuring..."); getList(); llOwnerSay("Ready to give folder " + folder); llOwnerSay("Containing: " + llList2CSV(contents)); // set the floating text on the giver llSetText(title, <1.0,1.0,1.0>, 1.0); }

default { // when the script starts running state_entry() { config(); }

// when someone touches the object touch_start(integer count) { // count is how many people touched the object while (count) { // we find out the UUID key of the AV that touched key id = llDetectedKey(--count); // and give them the folder llGiveInventoryList(id, folder, contents); } }

// when the contents of the object is changed changed(integer change) { if (change && CHANGED_INVENTORY) // we get the list of items again config(); } } </lsl>