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.
A tip jar is part of every club, live music venue and event in Second Life. This free script turns any object into one: residents pay it, it thanks them by name, and it shows the total and the last tipper above the jar.
// Tip Jar - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-tip-jar-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Put this script in any object. Residents pay the object, it thanks them and shows the total.
// The money goes to the owner of the object (or to the group, if the object is deeded to a group).
// Owner: touch the jar (right-click > Touch when CLICK_TO_PAY is on) to see the total or reset it.
string THANK_YOU = "Thank you for the tip, %name%!"; // %name% becomes the tipper's name
integer PUBLIC_THANKS = TRUE; // TRUE = say thanks in local chat, FALSE = only the tipper sees it
integer DEFAULT_AMOUNT = 100; // the amount in the Pay window's box
list QUICK_AMOUNTS = [50, 100, 250, 500]; // exactly four quick buttons, in L$
integer CLICK_TO_PAY = TRUE; // TRUE = a left click opens the Pay window
vector TEXT_COLOR = <1.0, 0.85, 0.3>;
integer gTotal = 0;
string gLast = "";
string gOwnerName = "";
integer gChan;
integer gListen;
string fillName(string s, string name)
{
integer i = llSubStringIndex(s, "%name%");
if (i == -1) return s;
return llInsertString(llDeleteSubString(s, i, i + 5), i, name);
}
showText()
{
string t = "Tip jar";
if (gOwnerName != "") t += " for " + gOwnerName;
t += "\nL$" + (string)gTotal + " received";
if (gLast != "") t += "\nLast tip: " + gLast;
llSetText(t, TEXT_COLOR, 1.0);
}
default
{
state_entry()
{
gOwnerName = llGetDisplayName(llGetOwner());
llSetPayPrice(DEFAULT_AMOUNT, QUICK_AMOUNTS);
if (CLICK_TO_PAY) llSetClickAction(CLICK_ACTION_PAY);
else llSetClickAction(CLICK_ACTION_TOUCH);
showText();
}
on_rez(integer param)
{
llResetScript();
}
money(key id, integer amount)
{
gTotal += amount;
gLast = llGetDisplayName(id);
string msg = fillName(THANK_YOU, gLast);
if (PUBLIC_THANKS) llSay(0, msg);
else llRegionSayTo(id, 0, msg);
showText();
}
touch_start(integer total)
{
key who = llDetectedKey(0);
if (who != llGetOwner())
{
llRegionSayTo(who, 0, "Right-click me and choose Pay to leave a tip. Thank you!");
return;
}
llListenRemove(gListen);
gChan = -1000000 - (integer)llFrand(1000000.0);
gListen = llListen(gChan, "", who, "");
llDialog(who, "Tip jar total: L$" + (string)gTotal, ["Reset total", "Close"], gChan);
llSetTimerEvent(60.0);
}
listen(integer channel, string name, key id, string message)
{
if (message == "Reset total")
{
gTotal = 0;
gLast = "";
showText();
llOwnerSay("The total is back to L$0.");
}
llListenRemove(gListen);
llSetTimerEvent(0.0);
}
timer()
{
llListenRemove(gListen);
llSetTimerEvent(0.0);
}
}
Free to use, change and put in your own creations, also ones you sell.
How to set it up
- Make or rez the jar and put the script in its Contents.
- Change the thank-you message and the four quick amounts if you like, then save.
- Left-click the jar: the Pay window opens. Pay yourself L$1 to test it.
- As the owner, right-click the jar and choose Touch to see the total or reset it.
Settings
- THANK_YOU: the message after each tip. %name% becomes the tipper's display name.
- PUBLIC_THANKS: TRUE thanks people in local chat, FALSE sends it only to the tipper.
- DEFAULT_AMOUNT and QUICK_AMOUNTS: the amount in the Pay box and the four quick buttons, in L$.
- CLICK_TO_PAY: TRUE opens the Pay window with a normal left click.
- TEXT_COLOR: the colour of the floating text.
Who gets the money?
Tips go to the owner of the object. If you deed the object to a group, the money goes to the group instead. For a DJ and a host sharing tips, each can rez their own jar, or the venue can deed a jar to the club group.
Frequently asked questions
Does the tip jar need debit permission?
No. Receiving money does not need any permission. Never give a tip jar permission to take money from your account.
Why does the total go back to zero?
The total is kept while the script runs. Taking the jar into inventory and rezzing it again resets it, as does resetting the script.
Can I hide the floating text?
Yes. Remove the showText() calls, or set the text colour's transparency in llSetText to 0.0.