Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // [*TA*] Backup Box
- // A script by Tutti Anatine
- // Version: DEVELOPMENT
- key CREATOR = "95eaa123-5b83-437e-9fe9-90def840da39";
- // # Contents
- // - [Documentation] Description
- // - [Documentation] Setup
- // - [Documentation] How to use
- // - [Documentation] License
- // - [Documentation] Known issues
- // - [Script] Settings
- // - [Script] Logic
- // Please read the documentation!
- // # Description
- // This script creates a Backup Box, in which you can store items to back them
- // up in your inventory. You can use these to declutter your items or keep
- // copies of breakable objects.
- // # Setup
- // 1. Rez a prim of your choice from the build menu, or a custom object. We'll
- // refer to this as "box" from here on.
- // 2. Drag this script from your inventory to the box.
- // 3. Optional: Open the script in the box and configure the values below the
- // section "Settings."
- // 4. Wait for the script to tell you that it's set up.
- // 5. Give the object a sensible name through the edit window, so you can easily
- // identify it in your inventory.
- // 6. Take the object back into your inventory. This object is your basic backup
- // box, from which you can create new ones.
- // # How to use
- // 1. Drag your basic backup box from your inventory into the world.
- // 2. Place the items you want to backup into the inventory of your box. You can
- // do this through the edit window, or by dragging items from your inventory
- // to the box while holding the CTRL button on your keyboard.
- // 3. Click the box to open the menu, which allows you to set a custom name and
- // optional description for the box.
- // 4. Once everything is ready, take the box into your inventory. From there,
- // you can always drag it back into the world to unpack it from the menu.
- // # License
- // This script is open source. You are free to use it, modify it and spread
- // (only) with full permissions. You are not allowed to charge money for this
- // script. If you have paid for it, ask for a full refund! Please do not remove
- // comment lines but update them if you have functionally modified the script.
- // # Known issues
- // - Due to the way CHANGED_INVENTORY works, the script does not detect when
- // no-copy items are removed from inventory.
- // See also: http://wiki.secondlife.com/wiki/CHANGED_INVENTORY
- // - Due to limitations in llGiveInventoryList, you cannot unpack no-copy items.
- // See also: http://wiki.secondlife.com/wiki/LlGiveInventoryList
- // -----------------------------------------------------------------------------
- // Settings
- // -----------------------------------------------------------------------------
- // Set the optional prefix for the object name
- string OBJECT_NAME_PREFIX = "[Backup]";
- // Whether to show floating text
- integer ENABLE_FLOATING_TEXT = TRUE;
- // The color of the floating text
- vector FLOATING_TEXT_COLOR = <1.0, 1.0, 1.0>;
- // The transparency of the floating text
- float FLOATING_TEXT_ALPHA = 1.0;
- // Whether to apply a texture to all sides of the object.
- integer APPLY_BOX_TEXTURE = FALSE;
- // The key of the texture that is applied when APPLY_BOX_TEXTURE is TRUE.
- key BOX_TEXTURE = "";
- // The channel for the menu to communicate on. Should be negative.
- integer DIALOG_CHANNEL = -46346436;
- // The number of seconds it takes for the menu to stop listening.
- float DIALOG_TIMEOUT = 20.0;
- // -----------------------------------------------------------------------------
- // Logic; do not edit below this line unless you know what you're doing!
- // -----------------------------------------------------------------------------
- integer isReady = FALSE;
- key ownerKey;
- list inventoryList;
- integer containsNoCopyItems = FALSE;
- integer dialogHandler;
- integer isWaitingForNameInput = FALSE;
- integer isWaitingForDescInput = FALSE;
- indexInventory()
- {
- inventoryList = [];
- containsNoCopyItems = FALSE;
- string scriptName = llGetScriptName();
- integer count = llGetInventoryNumber(INVENTORY_ALL);
- string inventoryName;
- integer ownerPerms;
- while (count--) {
- inventoryName = llGetInventoryName(INVENTORY_ALL, count);
- if (inventoryName != scriptName) {
- ownerPerms = llGetInventoryPermMask(inventoryName, MASK_OWNER);
- if (!(ownerPerms & PERM_COPY)) {
- containsNoCopyItems = TRUE;
- } else {
- inventoryList += [inventoryName];
- }
- }
- }
- if (containsNoCopyItems) {
- llOwnerSay("Warning: this object contains no-copy items. Items without copy permissions cannot be unpacked automatically.");
- }
- updateFloatingText();
- }
- updateFloatingText()
- {
- if (!ENABLE_FLOATING_TEXT) {
- return;
- }
- string text = llGetObjectName();
- if (llGetObjectDesc()) {
- text += "\n" + llGetObjectDesc();
- }
- text += "\nNumber of contents: " + (string) llGetListLength(inventoryList);
- if (containsNoCopyItems) {
- text += "\nWarning: contains no-copy items!";
- }
- llSetText(text, FLOATING_TEXT_COLOR, FLOATING_TEXT_ALPHA);
- }
- clearDialogs()
- {
- llSetTimerEvent(0.0);
- llListenControl(dialogHandler, FALSE);
- isWaitingForNameInput = FALSE;
- isWaitingForDescInput = FALSE;
- }
- default {
- state_entry()
- {
- llOwnerSay("Initializing, please wait a moment.");
- ownerKey = llGetOwner();
- indexInventory();
- dialogHandler = llListen(DIALOG_CHANNEL, "", ownerKey, "");
- llListenControl(dialogHandler, FALSE);
- if (APPLY_BOX_TEXTURE) {
- llSetTexture(BOX_TEXTURE, ALL_SIDES);
- }
- isReady = TRUE;
- llOwnerSay("Finished, touch to open the menu.");
- }
- touch_start(integer num_detected)
- {
- if (!isReady) return;
- if (llDetectedKey(0) != ownerKey) {
- llWhisper(0, "Only " + llKey2Name(ownerKey) + " can operate this menu.");
- return;
- }
- integer numberOfContents = llGetListLength(inventoryList);
- list dialogOptions = ["Unpack", "Reset", "Close", "Set name", "Set descrip."];
- string dialogMessage = "Please choose an option.";
- dialogMessage += "\n\nObject name prefix: " + OBJECT_NAME_PREFIX;
- dialogMessage += "\nNumber of items inside: " + (string) numberOfContents;
- llListenControl(dialogHandler, TRUE);
- llDialog(ownerKey, dialogMessage, dialogOptions, DIALOG_CHANNEL);
- llSetTimerEvent(DIALOG_TIMEOUT);
- }
- listen(integer channel, string name, key id, string message) {
- llSetTimerEvent(0.0);
- // Below is one "(else) if" statement, split up for improved readability
- string action = llToLower(message);
- // Dialog: Close the dialog
- if (action == "close") {
- clearDialogs();
- }
- // Dialog: Reset the script
- else if (action == "reset") {
- llResetScript();
- }
- // Dialog: Give the inventory of the object
- else if (action == "unpack") {
- clearDialogs();
- if (llGetListLength(inventoryList) == 0) {
- llOwnerSay("Cannot unpack, as inventory is empty.");
- } else {
- llGiveInventoryList(id, llGetObjectName(), inventoryList);
- if (containsNoCopyItems) {
- llOwnerSay("Unpacked successfully. Warning: this object contains no-copy items, which cannot be unpacked automatically. Accept the inventory offer to continue, then take no-copy items from this object manually.");
- } else {
- llOwnerSay("Unpacked successfully. Accept the inventory offer to continue.");
- }
- }
- }
- // Dialog: Trigger dialog to set the name of the object
- else if (action == "set name") {
- isWaitingForNameInput = TRUE;
- llTextBox(id, "Enter a new name.", channel);
- llSetTimerEvent(DIALOG_TIMEOUT);
- llOwnerSay("Provide a new name through the text box.");
- }
- // Dialog: Trigger dialog to set the description of the object
- else if (action == "set descrip.") {
- isWaitingForDescInput = TRUE;
- llTextBox(id, "Enter a new description.", channel);
- llSetTimerEvent(DIALOG_TIMEOUT);
- llOwnerSay("Provide a new description through the text box.");
- }
- // Text box: Set the name of the object
- else if (isWaitingForNameInput) {
- clearDialogs();
- string newName = message;
- if (OBJECT_NAME_PREFIX) {
- newName = OBJECT_NAME_PREFIX + " " + newName;
- }
- llSetObjectName(newName);
- llOwnerSay("Name successfully changed.");
- updateFloatingText();
- }
- // Text box: Set the description of the object
- else if (isWaitingForDescInput) {
- clearDialogs();
- llSetObjectDesc(message);
- llOwnerSay("Description successfully changed.");
- updateFloatingText();
- }
- // Fallback for invalid input
- else {
- llOwnerSay("Invalid input: \"" + message + "\" (sender: " + name + ").");
- clearDialogs();
- }
- }
- timer() {
- clearDialogs();
- llOwnerSay("Time's up! Activate the menu if you want to try again.");
- }
- changed(integer change)
- {
- if (!isReady) return;
- if ((change & CHANGED_INVENTORY) || (change & CHANGED_ALLOWED_DROP))
- {
- indexInventory();
- }
- if (change & CHANGED_OWNER)
- {
- llResetScript();
- }
- }
- on_rez(integer start_param)
- {
- llResetScript();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement