Second Life today in one place Gifts & freebies updated every hour 7 languages Free to list your store
12:49 SLT List your event+ List
Grid issue
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
LSL script

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.

101 lines ·

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.

lsl-gift-giver-script.lsl · 101 lines Check this script
// 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

  1. Rez a box, sign or poster for your gift and put the script in its Contents.
  2. Add your gift items (clothes, furniture, a landmark, a notecard). They must be copyable for the next owner.
  3. 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.
  4. 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.

Check your own script: LSL syntax checker →

More scriptsAll scripts
LSL script · 55 lines

LSL door script: touch to open, closes by itself

Free LSL door script for Second Life. Touch to open and close, the door swings on its hinge and closes by itself after a few seconds. Sounds optional.

LSL script · 69 lines

LSL sit and pose script for chairs and pose balls

Free LSL sit script for Second Life chairs, benches and pose balls: sit and play your own animation, set the sit position, hide the ball while in use.

LSL script · 96 lines

LSL tip jar script with thank-you message and total

Free LSL tip jar script for Second Life clubs, DJs, hosts and stores: quick pay buttons, a thank-you message, the total and last tipper in floating text.