Create an attractive gift box and put this script in it along with a notecard and any inventory items you want to give (objects, LMs, textures, scripts,.....). The notecard must contain only text, and no line may be longer than 255 characters. Put the recipient avatar's name in the object's Description field, being sure to spell it EXACTLY right. The script leads you through a very simple setup. Thereafter, the object will only respond to a touch by the intended recipient. When that happens, the object "Ruths" itself to a graceful cloud, reads the message in IM, offers the gift item(s), and dies peacefully.
OK, so it's not heavy-duty scripting. It's a fun way to send a personalized message.
CODE
// MessageFor by Rolig Loon May 2009
// Use this script when you want to leave a note and (optionally) gift items for a specific recipient.
// The script gives you, the owner, setup instructions when it starts.
// When setup is complete, the recipient identified in the object's hover text can receive the message and gift(s) by
touching the object.
// The object ignores touches by any other avatar.
string gName; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries
string Recipient; // Name of the avatar for whom the message and gift(s) are intended
key SpeakTo; // llDetectedKey of person touching the object
integer click = 0; // Flag to check initialization
default
{
state_entry()
{
Recipient = llGetObjectDesc();
llSetObjectName("");
llInstantMessage(llGetOwner(),"/me Initializing ...");
llInstantMessage(llGetOwner(),"/me Type the recipient's avatar name in the Description field of this
object. Spelling and capitalization count.");
llInstantMessage(llGetOwner(),"/me Type your message on a notecard (nothing but text and no lines longer
than 255 characters). Put the card and any gifts");
llInstantMessage(llGetOwner(),"/me in this object's contents. When you have finished, click on the object
to finish initialization.");
llSetText("Message for " + Recipient +"\n\n (Touch to Receive)", <1,1,0>, 1.0);
}
touch_start(integer num_detected)
{
++click;
if (llDetectedKey(0) == llGetOwner())
{
if(click > 1)
{
llResetScript(); // Owner changed something and wants to rerun setup
}
llInstantMessage(llGetOwner(),"/me ..... updating information ......");
llInstantMessage(llGetOwner(),"/me Initialization is complete. The object is ready to give its
message and contents to " + Recipient);
llInstantMessage(llGetOwner(),"/me Please double check the spelling of \"" + Recipient+ "\" and be
sure that your message and gift(s) are in the object.");
llInstantMessage(llGetOwner(),"/me If you change anything, click to re-initialize the object before
giving it.");
llSetObjectName("Message for " + Recipient);
}
else if(llDetectedName(0) == Recipient) // Check to verify that the toucher is the intended recipient
{
llSetAlpha(0.0,ALL_SIDES); //"Ruth" the object into a pulsating cloud
llParticleSystem([
PSYS_PART_MAX_AGE, 4.,
PSYS_PART_START_SCALE, <0.8, 1.0, 0.>,
PSYS_PART_END_SCALE, <.02, .02, 0.>,
PSYS_PART_START_COLOR, <1., 1., 1.>,
PSYS_PART_START_ALPHA, 0.5,
PSYS_PART_END_COLOR, <1., 1., 1.>,
PSYS_PART_END_ALPHA, 0.,
PSYS_SRC_TEXTURE, "1759c1dc-d8e3-8081-a2bb-052190abcadf",
PSYS_SRC_MAX_AGE, 0.,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE_CONE,
PSYS_SRC_INNERANGLE, PI,
PSYS_SRC_OUTERANGLE, 0.,
PSYS_SRC_BURST_RATE, 0.02,
PSYS_SRC_BURST_RADIUS, 0.,
PSYS_SRC_BURST_PART_COUNT, 1,
PSYS_SRC_BURST_SPEED_MIN, 0.1,
PSYS_SRC_BURST_SPEED_MAX, 1.,
PSYS_PART_FLAGS,
PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK |
PSYS_PART_EMISSIVE_MASK | PSYS_PART_TARGET_POS_MASK
]);
SpeakTo = llDetectedKey(0);
string HoldName = llGetObjectName();
llSetObjectName (" ");
llInstantMessage(SpeakTo, "/me Message for " + Recipient);
llSetObjectName (HoldName);
llSetTimerEvent(3.0);
gName = llGetInventoryName(INVENTORY_NOTECARD, 0); // find the first notecard in the object's
inventory
gQueryID = llGetNotecardLine(gName, gLine); // request first line
}
}
dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if (data != EOF) // Read lines from the notecard until finished
{
string HoldName = llGetObjectName();
llSetObjectName("");
llInstantMessage(SpeakTo, "/me " + (string)data); // Send the line to recipient by IM
llSetObjectName(HoldName);
++gLine; // increase line count
}
else // Give Recipient the contents of inventory and finish
{
list inventory_types =
[INVENTORY_BODYPART,INVENTORY_CLOTHING,INVENTORY_LANDMARK,INVENTORY_NOTECARD,INVENTORY_OBJECT,INVENTORY_SCRIPT,INVENT
ORY_SOUND,INVENTORY_TEXTURE];
integer inventory_count = llGetListLength(inventory_types);
integer j;
integer k;
integer type;
integer typecount;
string myname = llGetScriptName();
string objectname;
for (j=0; j<inventory_count;j++)
{
type = llList2Integer(inventory_types,j);
typecount = llGetInventoryNumber(type);
if (typecount > 0)
{
for (k=0; k<typecount;k++)
{
objectname = llGetInventoryName(type,k);
if (objectname != myname) // don't distribute this script
{
llGiveInventory(SpeakTo,objectname);
}
}
}
}
llInstantMessage(llGetOwner(),"Your message and gift(s) have been delivered to " + Recipient);
llInstantMessage(SpeakTo,"/me This object will self-destruct in 5 seconds.");
llParticleSystem([]); // Not really necessary, but it makes for graceful exit.
llSleep(5.0);
llDie(); // Delete the object
}
}
}
timer()
{
gQueryID = llGetNotecardLine(gName, gLine); // request next line
}
}