Real Object Inventory To Dialog
De DigiWiki.
This script will display all items contained in an Object Inventory, regardless of the amount of items or length of item names. Further more, this script allows you to determine who has access to the Object using this script. It also provides an easy way to configure end, next and back buttons. I have used non standard unicode characters for my buttons in this example (characters that cannot be part of an item name). A simple giver has been implemented, which checks your permissions on any selected Inventory Item to see if it's actually transferable.
If the Owner uses the object, the above check is not done.
Apart from displaying content in a dialog, this script demonstrates several techniques that are useful in many ways.
// Real Object Inventory To Dialog // By PixelProphet Lane // Please note that any and every script published in the script library falls under the // Creative Commons Creative Commons Attribution-Share Alike 3.0 license. // See https://wiki.secondlife.com/wiki/Project:Copyrights for details. // If you intend to distribute this code as is, then please the comments above as they are. // In case you distribute this code as non modifiable part of your scripts or objects, please include a reference to the page // you aquired the source from. integer DLGCHAN; integer HDL; integer ISACTIVE; integer PAGE; integer LINE; integer INBOX; integer UPDATE; integer TIMEOUT = 20; string NOTECARD = "users"; string BTN_NEXT = "next ►"; string BTN_BACK = "◄ back"; string BTN_END = "▣ end"; string OBJECTNAME; string ME; string MESSAGE; string CURRENTUSERNAME; key CURRENTUSERKEY; key QUERY; key OWNER; list USERS; list BUTTONS; SendDialog() { if (INBOX == 0) { llDialog(CURRENTUSERKEY,"No items in inventory!",[],-1); return; } integer items_per_dlg = 10; integer lastpage= llCeil((float)INBOX / (float)items_per_dlg); if (PAGE > lastpage) { PAGE = lastpage; } if (PAGE < 1) { PAGE = 1; } BUTTONS = []; MESSAGE = ""; integer i; integer min = (PAGE - 1) * items_per_dlg; integer max = PAGE * items_per_dlg; if (max >= INBOX) { max = INBOX; } for (i = min; i < max; ++i) { string item = llGetInventoryName(INVENTORY_ALL, i); //Don't give this script or users notecard away if (item != ME && item != NOTECARD) { MESSAGE += (string)i+" "+item+"\n"; BUTTONS += (string)i; } } if (PAGE == 1 && lastpage > 1) { BUTTONS += [BTN_END,BTN_NEXT]; } if (PAGE == 1 && lastpage == 1) { BUTTONS += BTN_END; } if (PAGE > 1 && PAGE < lastpage) { BUTTONS += [BTN_BACK,BTN_NEXT]; } if (PAGE == lastpage && PAGE != 1) { BUTTONS += BTN_BACK; } integer len = llGetListLength(BUTTONS); for (i = 0; i < len; i = i + 3) { BUTTONS = llListInsertList(llDeleteSubList(BUTTONS, -3, -1), llList2List(BUTTONS, -3, -1), i); } llSetTimerEvent(TIMEOUT); llDialog(CURRENTUSERKEY, MESSAGE+" ",BUTTONS,DLGCHAN); } integer IsAuthorized(string name) { if (~llListFindList(USERS, [name])) return TRUE; return FALSE; } integer IsValidButton(string name) { if (~llListFindList(BUTTONS, [name])) return TRUE; return FALSE; } default { on_rez(integer arg) { llResetScript(); } state_entry() { ISACTIVE = FALSE; OWNER = llGetOwner(); OBJECTNAME = llGetObjectName(); ME = llGetScriptName(); INBOX = llGetInventoryNumber(INVENTORY_ALL); DLGCHAN = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) ); LINE = 0; PAGE = 1; //Notecards that have been newly created and have not been opened and saved at least once, //do not have a valid asset id and will return NULL_KEY (They're just placeholders) if (llGetInventoryKey(NOTECARD) != NULL_KEY) { QUERY = llGetNotecardLine(NOTECARD, LINE); } else { llWhisper(0,"No Notecard by the name of "+NOTECARD+" or "+NOTECARD+" is not a valid asset."); } } touch_start(integer num) { key avatarkey = llDetectedKey(0); string avatarname = llDetectedName(0); //Check if avatar who touched is authorized if(avatarkey != OWNER && !IsAuthorized(avatarname)) { return; } if (UPDATE) { llDialog(avatarkey, OBJECTNAME+" is currently updating....\nPlease wait.", [] ,-1); return; } if (!ISACTIVE || avatarkey == CURRENTUSERKEY) { ISACTIVE = TRUE; llListenRemove(HDL); //Listen to this avatar only HDL = llListen(DLGCHAN, "", avatarkey, ""); CURRENTUSERKEY = avatarkey; CURRENTUSERNAME = avatarname; PAGE = 1; SendDialog(); } else { llDialog(avatarkey, OBJECTNAME+" is currently in use by "+CURRENTUSERNAME+"\nPlease wait.", [] ,-1); } } changed(integer change) { if (change & CHANGED_INVENTORY) { UPDATE = TRUE; //Wait until there are no changes for atleast 2 seconds until reading notecard again //Since there was a change in inventory, we can remove the listener too if there was one llSetTimerEvent(2); } } listen(integer channel, string name, key id, string msg) { if (msg == BTN_END) { llSetTimerEvent(0.1); return; } if (msg == BTN_NEXT) { ++PAGE; SendDialog(); return; } if (msg == BTN_BACK) { --PAGE; SendDialog(); return; } //If it wasn't end, back or next, then check if it was valid if (IsValidButton(msg)) { string item = llGetInventoryName(INVENTORY_ALL, (integer)msg); if (item != "" && item != ME && item != NOTECARD) { //If the user is not the Owner, check to see that item is actually transferable if (id != OWNER) { integer ownerPerms = llGetInventoryPermMask(item, MASK_OWNER); if (ownerPerms & PERM_TRANSFER) { llGiveInventory(id,item); } } else { //Owner always gets item llGiveInventory(id,item); } } SendDialog(); } } dataserver(key query_id, string data) { if (query_id == QUERY) { if (data != EOF) { //Remove leading and trailing spaces data = llStringTrim(data,STRING_TRIM); //If data still contains valid information after trimming, store it if (data != "\n" && data != "") USERS += data; ++LINE; QUERY = llGetNotecardLine(NOTECARD, LINE); } else { UPDATE = FALSE; llOwnerSay("No more lines in "+NOTECARD+", read " + (string)LINE + " lines."); } } } timer() { llSetTimerEvent(0); llListenRemove(HDL); ISACTIVE = FALSE; CURRENTUSERNAME = ""; CURRENTUSERKEY = NULL_KEY; if (UPDATE) { INBOX = llGetInventoryNumber(INVENTORY_ALL); LINE = 0; USERS = []; //Since inventory has changed and we need to read out notecard, we check again to see if it's valid if (llGetInventoryKey(NOTECARD) != NULL_KEY) { QUERY = llGetNotecardLine(NOTECARD, LINE); } else { llWhisper(0,"No Notecard by the name of "+NOTECARD+" or "+NOTECARD+" is not a valid asset."); } } } }