Difference between revisions of "User:Toady Nakamura/Simple Recording Tipjar"

From Second Life Wiki
Jump to navigation Jump to search
m (→‎Fancier Recording Tipjar: cleaned up variable names to be less confusing to beginners. I use these scripts as class examples, please do not over complicate them.)
m (→‎Fancier Recording Tipjar: removed changed event which was redundant to on_rez, rearranged slightly to rematch my class notes for this script)
Line 54: Line 54:
string lastDonor;
string lastDonor;


vector white = <1.0, 1.0, 1.0>;
vector white = <1.0, 1.0, 1.0>;
vector red = <1.0, 0.0, 0.0>;
vector red   = <1.0, 0.0, 0.0>;
vector yellow = <1.0, 1.0, 0.0>;
vector yellow = <1.0, 1.0, 0.0>;


float alpha = 1.0;// [0.0, 1.0]
float alpha = 1.0;


default
default
{
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
            llResetScript();
    }
     state_entry()
     state_entry()
     {
     {
Line 108: Line 97:
                     + "\n top donation: "    + (string)topDonation    + " L$ (" + topDonor + ")",
                     + "\n top donation: "    + (string)topDonation    + " L$ (" + topDonor + ")",
                           colorSet, alpha);
                           colorSet, alpha);
    }
    on_rez(integer start_param)
    {
        llResetScript();
     }
     }
}
}
</lsl>
</lsl>

Revision as of 12:16, 30 October 2012

  • 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 [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

<lsl> 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();
   }

} </lsl>