Difference between revisions of "User talk:Prajna Vella"
Prajna Vella (talk | contribs) |
Prajna Vella (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Sorry about the mess; I'm just practising my wiki editing. | |||
<lsl> | <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 current 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 items 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> | </lsl> | ||
Latest revision as of 16:11, 6 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 current 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 items 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>