Friday, April 3, 2026

Expanded Mailbox Script

The very first script I provided actually was a complete, working mailbox script! The magic happens with the llAllowInventoryDrop(TRUE); command, which is what turns a regular object into a functioning mailbox that anyone can drop items into.

However, if you are looking for a more "complete" mailbox experience, I have expanded the script below. This upgraded version combines the dual-notification system from earlier with standard mailbox features: floating hover text to identify the mailbox, and a touch response that gives people instructions on how to use it.

Here is the combined, expanded script for you, Lady Kati Evans:

Code snippet
// --- CONFIGURATION ---
// Replace the zeros below with the actual UUID key of the second person.
key second_person = "00000000-0000-0000-0000-000000000000"; 

// Change the text between the quotes to customize the floating text over the mailbox.
// The \n creates a new line.
string hover_text = "Magistrate's Mailbox\nHold Ctrl and drag items here to drop them.";

// Color of the hover text in RGB format (currently set to white).
vector text_color = <1.0, 1.0, 1.0>; 
// ---------------------

default
{
    state_entry()
    {
        // 1. Turns the object into a mailbox
        llAllowInventoryDrop(TRUE);
        
        // 2. Sets the floating text above the mailbox
        llSetText(hover_text, text_color, 1.0); 
    }

    // 3. Gives instructions if someone clicks the mailbox
    touch_start(integer total_number)
    {
        key clicker = llDetectedKey(0);
        llRegionSayTo(clicker, 0, "To leave a message or item, please hold down the 'Ctrl' key on your keyboard and drag the item from your inventory directly onto this mailbox.");
    }

    // 4. Handles the notifications when an item is dropped
    changed(integer change)
    {
        // CHANGED_ALLOWED_DROP triggers when someone else drops an item.
        // CHANGED_INVENTORY triggers if the owner drops an item.
        if (change & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
        {
            string regionName = llGetRegionName();
            string objectName = llGetObjectName();
            string message = "Notification: A new item has been dropped into '" + objectName + "' in the region " + regionName + ".";
            
            // Send IM to Owner
            llInstantMessage(llGetOwner(), message);
            
            // Send IM to the Second Person
            if (second_person != NULL_KEY && second_person != "")
            {
                llInstantMessage(second_person, message);
            }
        }
    }
}

What's New in This Version:

  • Hover Text: Added llSetText in the configuration section so you can display a floating title over the mailbox.

  • Click-to-Learn: Added a touch_start event. If a resident doesn't know how to drop items into a mailbox, they will usually click it. This will send them a private chat message explaining the "Ctrl + Drag" method.

  • All-in-One: It still retains the instant message notifications sent directly to you and the second UUID key you provide.

The Mailbox Script

Here is the Second Life (LSL) script for your mailbox.

By default, LSL does not natively tell a script the exact name of the item that was just dropped into it; it only triggers an event to say that the inventory has changed. To keep the script reliable and prevent it from running out of memory, this script will instantly announce that a drop occurred, along with the name of the mailbox and the region it is located in.

The Mailbox Script

Code snippet
// Replace the zeros below with the actual UUID key of the second person.
key second_person = "00000000-0000-0000-0000-000000000000"; 

default
{
    state_entry()
    {
        // This allows non-owners to hold Ctrl and drag items into the mailbox's inventory
        llAllowInventoryDrop(TRUE);
    }

    changed(integer change)
    {
        // CHANGED_ALLOWED_DROP triggers when someone else drops an item in.
        // CHANGED_INVENTORY triggers if the owner drops an item in.
        if (change & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
        {
            // Construct the message
            string regionName = llGetRegionName();
            string objectName = llGetObjectName();
            string message = "Notification: A new item has been dropped into '" + objectName + "' in the region " + regionName + ".";
            
            // 1. Send an Instant Message to the Owner
            llInstantMessage(llGetOwner(), message);
            
            // 2. Send an Instant Message to the second person
            // We check to make sure a valid key was entered before trying to send
            if (second_person != NULL_KEY && second_person != "")
            {
                llInstantMessage(second_person, message);
            }
        }
    }
}

How to set it up:

  1. Right-click your mailbox object and select Edit.

  2. Go to the Content tab.

  3. Click New Script, open it, and paste the code above into it.

  4. Important: On line 2, you must replace the 00000000-0000-0000-0000-000000000000 with the actual UUID of the second person you want to notify. (You can usually find a resident's UUID by looking at their web profile URL, or by using viewer tools/scripts designed to grab keys).

  5. Click Save.

How it works:

  • llAllowInventoryDrop(TRUE): This is required so that other residents can give items to the object. They do this by holding down the Ctrl key and dragging an item from their inventory directly onto the mailbox.

  • llInstantMessage: This function is used instead of llOwnerSay because it guarantees the message will be sent to both avatars as an IM, even if they are offline or in a completely different region in Second Life.