Difference between revisions of "User talk:Prajna Vella"
Prajna Vella (talk | contribs) m |
Prajna Vella (talk | contribs) |
||
Line 1: | Line 1: | ||
// 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) | |||
// and it will warn you if you put no-copy items in it (since once it has given a copy | |||
// of the item it won't have another copy to give to someone else). | |||
string version = "1.0"; // the script version number | 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 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 | string title = "Gifts"; // the floating title for the giver object | ||
list contents; // the list of items we will put in the folder | 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 item) { | |||
// get the permissions the object owner has for this item | |||
integer ownerPerms = llGetInventoryPermMask(item, 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 += item; | |||
else | |||
llOwnerSay("Couldn't add '" + item + "' because you must have transfer and copy permissions."); | |||
} | |||
// get the list of the items we will give | // get the list of the items we will give | ||
getList() { | getList() { | ||
// empty the list of items | |||
contents = []; | |||
// how many items are there in the contents? | // how many items are there in the contents? | ||
integer item = llGetInventoryNumber(INVENTORY_ALL); | integer item = llGetInventoryNumber(INVENTORY_ALL); | ||
Line 20: | Line 39: | ||
while (item) { | while (item) { | ||
// 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 | // it is very efficient and takes care of the fact itemes are numbered starting with 0 | ||
string thisItem = llGetInventoryName(INVENTORY_ALL, -- | string thisItem = llGetInventoryName(INVENTORY_ALL, --item); | ||
// 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) | ||
addItem(thisItem); | |||
} | } | ||
} | } | ||
Line 31: | Line 50: | ||
config() { | config() { | ||
// tell the owner what is happening and get the list of items to give | // tell the owner what is happening and get the list of items to give | ||
llOwnerSay("Version " + version); | |||
llOwnerSay("Configuring..."); | llOwnerSay("Configuring..."); | ||
getList(); | getList(); | ||
llOwnerSay("Ready to give folder " + folder); | llOwnerSay("Ready to give folder " + folder); | ||
llOwnerSay("Containing: " + llList2CSV(contents)); | llOwnerSay("Containing: " + llList2CSV(contents)); | ||
Line 52: | Line 71: | ||
while (count) { | while (count) { | ||
// we find out the UUID key of the AV that touched | // we find out the UUID key of the AV that touched | ||
key id = llDetectedKey(-- | key id = llDetectedKey(--count); | ||
// and give them the folder | // and give them the folder | ||
llGiveInventoryList(id, folder, contents); | llGiveInventoryList(id, folder, contents); | ||
Line 65: | Line 84: | ||
} | } | ||
} | } | ||
Revision as of 08:18, 4 May 2009
// 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) // and it will warn you if you put no-copy items in it (since once it has given a copy // of the item it won't have another copy to give to someone else).
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 item) { // get the permissions the object owner has for this item integer ownerPerms = llGetInventoryPermMask(item, 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 += item; else llOwnerSay("Couldn't add '" + item + "' 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 item = 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 (item) { // 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, --item); // 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(); } }