User:Toady Nakamura/Simple Recording Tipjar
< User:Toady Nakamura
Jump to navigation
Jump to search
Revision as of 17:43, 28 July 2015 by Toady Nakamura (talk | contribs) (fix <source lang="lsl2"> </source> error which was causing page to display incorrectly)
- Put this script in any object you own for an instant tipjar; by Toady Nakamura.
integer totaldonated;
default
{
on_rez( integer sparam )
{
llResetScript(); // reset when rezzed out
}
state_entry()
{
llSetText("Donation Box\nL$0 Donated so far",<1.0,1.0,1.0>,0.85);
// set text, "message", color vector (here white), and intensity (here 85%)
}
money(key id, integer amount)// When someone pays the system records their key & the amount
{
totaldonated = totaldonated + amount;
// add the amount just given to the total from before
// "amount" comes from the money event
llSetText("Donation Box \n L$" + (string)totaldonated + " Donated so far",<1.0,1.0,1.0>,0.85);
// set the text to show the gift
llInstantMessage(id,"Thank you for the donation!, " + llKey2Name(id));
// send a private thank you to giver.
// "id" comes from the money event
llInstantMessage(llGetOwner(), llKey2Name(id) + " just donated $L" + (string)amount);
// privately message owner to say how much the donation was and the name of the giver.
}
}
Fancier Recording Tipjar
I found this one on the LSL-101/Logic [1] page and added it here for reference so you can see the difference between a simple script and one which is a bit more complicated. This one shows
- Donations so far
- Last donation
- Largest donation
string ownerName;
integer totalDonations;
integer topDonation;
integer lastDonation;
string topDonor;
string lastDonor;
vector white = <1.0, 1.0, 1.0>;
vector red = <1.0, 0.0, 0.0>;
vector yellow = <1.0, 1.0, 0.0>;
float alpha = 1.0;
default
{
state_entry()
{
key ownerKey = llGetOwner();
ownerName = llKey2Name(ownerKey);
llSetPayPrice(20, [10, 20, 50, 100]);
llSetText(ownerName + "\ndonations so far: 0 L$\n ", white, alpha);
}
money(key id, integer amount)
{
string name = llKey2Name(id);
string firstName = llGetSubString(name, 0, llSubStringIndex(name, " ") - 1);
llSay(0,"Thank you for the donation, " + firstName + "!");
totalDonations += amount;
lastDonation = amount;
lastDonor = name;
vector colorSet = yellow;
if (topDonation < lastDonation)
{
topDonation = lastDonation;
topDonor = lastDonor;
colorSet = red;
}
llSetText(ownerName
+ "\n donations so far: " + (string)totalDonations + " L$"
+ "\n last donation: " + (string)lastDonation + " L$ (" + lastDonor + ")"
+ "\n top donation: " + (string)topDonation + " L$ (" + topDonor + ")",
colorSet, alpha);
}
on_rez(integer start_param)
{
llResetScript();
}
}
Visit my LSL wiki page for my library of simple scripts ! Toady Nakamura