Create And Script Your Own Tip Jar


Learn how to script and create your very own tip jar.

This tutorial includes the actual script and a explanation of how the script works.

Here is the script you will need for this project: Tip Jar SL Script

I wrote this script with some unique features in hopes it may help anyone in need of a tip jar.

Once you have scripted your new jar, size to fit your needs, add a texture. Make your jar unique 🙂

Getting Started:

1. Rez a prim
2. Edit prim
3. Go to contents
4. Click New Script
5. Double click and open the script
6. Copy the contents from the above Tip Jar SL Script
7. Remove all contents in the New Script and paste the Tip Jar SL Script
8. Save.

Once you get the message that the script has saved, exit edit.

This script uses particle effects. Let’s the avatar log in or log out of the jar.

Uses a Server call that allows your jar to show your sudo name and not your log in name.

For example, if your Second Life name is ‘Love2DJ4Life Resident’ and your sudo name is ‘Mark The DJ’, the name ‘Mark The DJ’ will appear over the jar.

Let’s dive into the code to see what is exactly going on:

money(key giver, integer amount) {
llSay(0, “Thank you for the L$ tip, ” + llKey2Name(giver));
total+=amount;
Lastgiver = llKey2Name(giver);
Lastgiven = amount;
fakeMakeExplosion(80, 1.0, 13.0, 2.2, 1.0, “fire”, <0.0, 0.0, 0.0>);

llSleep(.5);
fakeMakeExplosion(80, 1.0, 13.0, 2.2, 1.0, “smoke”, <0.0, 0.0, 0.0>);
llSleep(1);
llParticleSystem([]);

updateText();
}

This section of code allows your tip jar to receive tips.

When another avatar right clicks your jar, the ability to pay is enabled.

This code does the following:

Stores the avatars UUID that just gave you a tip
Uses llKey2Name to display the avatars actual name and not the UUID
Adds the total tips to the integer total
Stores the amount of the most recent tip to the integer amount
Does a particle explosion by calling the fakeMakeExplosion sub script
Calls updateText to update the text that is seen over the tip jar

updateText()
{
string str = owner_display_name + “‘s Tip Jar\n”;
string str2 = “All tips greatly appreciated!”;
if( total>0 )
str+=Lastgiver + ” tipped ” + (string)Lastgiven +”L$\n” + (string)total + “L$ donated so far.\n”;
else
str+=”Your tips are greatly apprecaited!\n” + “0 L$ tips given so far\n”;

llSetText(str, <1.0, 1.0, 0.0> , 1);
}

The updateText does the following:

Displays your sudo name using owner_display_name
Displays last tip giver name, how much they tipped and total tips received

Since this code calls on owner_display_name, let’s see what this code does:

dataserver(key queryid, string data)
{
if ( owner_name_query == queryid )
{
owner_display_name = data;
updateText();
}
}
}

This code queries the UUID of the avatar who has logged into to the tip jar. Once the server call grabs your sudo name from your UUID, a call to updateText is made to display the new name.

When you log into the jar, the following is called:

owner_key = aviKey;
owner_name_query = llRequestDisplayName(owner_key);

This code stores your UUID to the key owner_key
A query is created using owner_name_query that equals owner key (your UUID)

The script does the following:

Avatar touches
Chooses Log In or Log Out
Once the avatar logs in, a call is made to grab the sudo name
Sudo name is then updated to updateText
Tip jar waits for a tip

Another avatar touches to tip
Tip amount is added to total as well as the current tip amount
An explosion effect is called
A call to updateText is made

You are free to add more features to this script. This is to give you a better understanding of how a tip jar works. Also note, when someone tips they will see the default pay amounts. You can set a given tip amount by adding the following code: llSetPayPrice( PAY_HIDE , [50,100,150,200] ). This will display 50, 100, 150, 200 as the default amounts. To use this feature just replace the following section:

state_entry()
{

gToggle = 0;
integer n1 = random_integer( 1, 9999 );
channel = n1;
listen_handle = llListen(channel, “”,llGetOwner(),””);

}

with

state_entry()
{

integer n1 = random_integer( 1, 9999 );
channel = n1;
listen_handle = llListen(channel, “”,llGetOwner(),””);
llSetPayPrice( PAY_HIDE , [50,100,150,200] );

}

Here is a video showcasing how the script works in action:

What's Your Reaction?

WTF WTF
0
WTF
ROFL ROFL
0
ROFL
OMG OMG
0
OMG
LOVE LOVE
1
LOVE
LIKE LIKE
0
LIKE
CUTE CUTE
0
CUTE
ANGRY ANGRY
0
ANGRY

More From: club

Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
Video
Youtube, Vimeo or Vine Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
%d bloggers like this: