LSL gift giver script for freebies and group gifts
Free LSL gift giver for Second Life stores: touch to get every item as one folder, for everyone or only for group members wearing the group tag.
Every store needs a gift giver. This script hands out everything in an object's Contents as one tidy folder when someone touches it. Switch on GROUP_ONLY and it becomes a group gift board: only residents wearing your store's group tag get the gift.
// Gift Giver (everyone or group only) - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-gift-giver-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Put this script and your gift items in an object. Touch it to receive everything in its Contents
// (except this script) as one folder. Items must be copyable for the next owner.
// With GROUP_ONLY = TRUE, only residents wearing the same group tag as the object get the gift:
// set the object's group in the Edit window (General tab) first.
integer GROUP_ONLY = FALSE;
string FOLDER_NAME = ""; // "" = use the object's name
string THANK_YOU = "Enjoy your gift! It is in your inventory.";
string NO_GROUP_TEXT = "Sorry, this gift is for group members. Wear the group tag and touch me again.";
integer COOLDOWN_SECONDS = 60; // the same avatar can take the gift again after this time
list gRecent = []; // [avatar key, unix time, ...]
string folderName()
{
if (FOLDER_NAME != "") return FOLDER_NAME;
return llGetObjectName();
}
list giftItems()
{
list out = [];
string me = llGetScriptName();
integer n = llGetInventoryNumber(INVENTORY_ALL);
integer i;
for (i = 0; i < n; ++i)
{
string name = llGetInventoryName(INVENTORY_ALL, i);
if (name != me) out += [name];
}
return out;
}
giveGift(key who, integer sameGroup)
{
if (GROUP_ONLY)
{
// an object without a group would let everyone in, so check that a group is set
key objGroup = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0);
if (objGroup == NULL_KEY)
{
llRegionSayTo(who, 0, "This gift giver is not set up yet.");
return;
}
if (!sameGroup)
{
llRegionSayTo(who, 0, NO_GROUP_TEXT);
return;
}
}
integer now = llGetUnixTime();
integer i = llListFindList(gRecent, [who]);
if (i != -1)
{
if (now - llList2Integer(gRecent, i + 1) < COOLDOWN_SECONDS)
{
llRegionSayTo(who, 0, "You already have this gift. Look for the folder \"" + folderName() + "\" in your inventory.");
return;
}
gRecent = llDeleteSubList(gRecent, i, i + 1);
}
list stuff = giftItems();
if (llGetListLength(stuff) == 0)
{
llRegionSayTo(who, 0, "This gift giver is empty right now.");
return;
}
llGiveInventoryList(who, folderName(), stuff);
llRegionSayTo(who, 0, THANK_YOU);
gRecent += [who, now];
if (llGetListLength(gRecent) > 200) gRecent = llDeleteSubList(gRecent, 0, 1);
}
default
{
state_entry()
{
if (GROUP_ONLY)
{
key objGroup = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0);
if (objGroup == NULL_KEY) llOwnerSay("GROUP_ONLY is on, but this object has no group. Set the group in the Edit window (General tab), then reset the script.");
}
}
touch_start(integer total)
{
integer d;
for (d = 0; d < total; ++d)
{
giveGift(llDetectedKey(d), llDetectedGroup(d));
}
}
changed(integer change)
{
if (change & CHANGED_OWNER) llResetScript();
}
}
Free to use, change and put in your own creations, also ones you sell.
How to set it up
- Rez a box, sign or poster for your gift and put the script in its Contents.
- Add your gift items (clothes, furniture, a landmark, a notecard). They must be copyable for the next owner.
- For a group gift, set GROUP_ONLY to TRUE and set the object's group in the Edit window, General tab. Save the script again.
- Touch the giver to test it. The gift arrives as a folder named after the object.
Settings
- GROUP_ONLY: FALSE gives to everyone; TRUE only to residents wearing the object's group tag.
- FOLDER_NAME: the name of the folder the gift arrives in; empty uses the object's name.
- THANK_YOU and NO_GROUP_TEXT: the messages residents see.
- COOLDOWN_SECONDS: stops the same avatar from taking the gift again and again by accident.
Tips
- Change the gift each month by swapping the items in the Contents; the script does not need to change.
- Put a short notecard in the gift with a landmark to your store and a thank-you.
- List your gift on WhatSL for free so more residents find it.
Frequently asked questions
Why does a resident in my group get "this gift is for group members"?
They are in the group but have another group tag active. Ask them to make your group their active group and touch again.
Why are some items missing from the folder?
Items that are no-copy for the next owner cannot be given in a folder. Make them copyable, or use a separate giver for each no-copy item.
Can I give a landmark too?
Yes. Anything in the Contents except the script itself is given, including landmarks and notecards.