User:Toady Nakamura/Simple Recording Tipjar

From Second Life Wiki
< User:Toady Nakamura
Revision as of 10:02, 19 October 2012 by Toady Nakamura (talk | contribs) (added more code)
Jump to navigation Jump to search
  • 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> integer i; // donations so far integer m; // high gift integer n; string donorh; // high donor name string donorl; // for donor's name string owner; // for owner's name vector color1 = <1,1,1>; // one color vector color2 = <1,0,0>; // another color vector color3 = <1,1,0>; // one more color! float alpha = 1.0;// intensity of set text (zero to 1.0)

default {

   on_rez(integer start_param)
   {
       llResetScript(); 
   }

   state_entry()
   {
       owner = llKey2Name(llGetOwner()); // get the owner's name
       llSetPayPrice(20, [10,20,50,100]); // set the box of possible amounts with $20L as least
       llSetText("MY Tip Jar\nDonations so far: L$0\n:'(\n ", color1, alpha); // set text
   }

   money(key id, integer amount)
       {
           string thanks = llKey2Name(id); // gets id from money event, converts to name string
           list tlst = llParseString2List(thanks, [""], [" "]); //divide the list using blank space as separator
           string thank = llList2String(tlst, 0); // use only the first name part
           llSay(0,"Thank you kindly, " + (string)thank + "!"); // Acknowledge gift in chat
           if (amount > m) // if gift is higher than HIGH GIFT ... (remember m starts out at zero)
           {
               i += amount; // add the amount to donations so far
               m = amount; // holds the amount of this gift & changes the former high gift to the new high gift amount
               donorh = llKey2Name(id); // set the high donor's name
            // use all that to make the set text display
               llSetText(owner +"'s Tip Jar\nDonations so far: L$" + (string)i + 
                                           "\nLast donation: L$" + (string)m + 
                                           "\nLargest donation: L$" + (string)m  + 
                                           " (" + (string)donorh + ")", color2, alpha);
           }
           else if (amount <= m) // if gift is not higher than HIGH GIFT
           {
               i += amount;// add the amount to donations so far
               n = amount; // holds the amount of this gift. 
               // use all that to make the set text display
               donorl = llKey2Name(id); // set donor name
               llSetText(owner +"'s Tip Jar\nDonations so far: L$" + (string)i + 
                                          "\nLast donation: L$" + (string)n + 
                                          "\nLargest donation: L$" + (string)m + 
                                          " (" + (string)donorh + ")", color3, alpha);
           }
       }

}</lsl>