User:Toady Nakamura/Simple Recording Tipjar
< User:Toady Nakamura
Jump to navigation
Jump to search
Revision as of 11:09, 19 October 2012 by Kireji Haiku (talk | contribs) (rewrote second example script using variable names that actually mean something and improved readability and memory usage)
- Put this script in any object you own for an instant tipjar.
- By Toady Nakamura
<lsl> 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. }
} </lsl>
Fancier Recording Tipjar
I found this one on the LSL-101/Logic 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
<lsl> string ownerName;
integer totalDonations;
integer topDonation; integer lastDonation;
string topDonor; string lastDonor;
vector colorWhite = <1.0, 1.0, 1.0>; vector colorRed = <1.0, 0.0, 0.0>; vector colorYellow = <1.0, 1.0, 0.0>;
float floattextAlpha = 1.0;// [0.0, 1.0]
default {
on_rez(integer start_param) { llResetScript(); }
changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); }
state_entry() { key ownerKey = llGetOwner(); ownerName = llKey2Name(ownerKey);
llSetPayPrice(20, [10, 20, 50, 100]);
llSetText(ownerName + "\ndonations so far: 0 L$\n ", colorWhite, floattextAlpha); }
money(key id, integer amount) { string name = llKey2Name(id); string firstName = llGetSubString(name, 0, llSubStringIndex(name, " ") - 1);
// PUBLIC_CHANNEL has the integer value 0 llSay(PUBLIC_CHANNEL, "Thank you for the donation, " + firstName + "!");
totalDonations += amount;
lastDonation = amount; lastDonor = name; vector colorToUse = colorYellow;
if (topDonation < lastDonation) { topDonation = lastDonation; topDonor = lastDonor; colorToUse = colorRed; }
llSetText(ownerName +"\ndonations so far: " + (string)totalDonations + " L$" + "\nlast donation: " + (string)lastDonation + " L$ (" + lastDonor + ")" + "\ntop donation: " + (string)topDonation + " L$ (" + topDonor + ")", colorToUse, floattextAlpha); }
} </lsl>