Friday, April 3, 2026

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.

No comments:

Post a Comment