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
// 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:
Right-click your mailbox object and select Edit.
Go to the Content tab.
Click New Script, open it, and paste the code above into it.
Important: On line 2, you must replace the
00000000-0000-0000-0000-000000000000with 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).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 ofllOwnerSaybecause 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