Table of Contents

Shortnote

The following script is a minimalist donation jar for use in clubs, on simulators or for a cause. This is different from the tipjar or the stripjar where an agent is the sole beneficiary of the accumulated tips. In this case, the jar can be set to a group in order to receive donations for the entire group.

The beggar in the image above is a sculpted creation that can be found at Sa'ng Fori Design.

This is the previous code of the tip-jar, now superseded by the ample donation jar.

Setup

  • Create a donation jar primitive.
  • Set the description to 0.
  • Create a new script in the donation jar primitive.
  • Copy and paste the code below into the script.
  • Edit the GOAL = 30000 and set it to your goal in L$.
  • Save the script.

Code

This script was tested and works on OpenSim version 0.7.4!

simple_donation_jar.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2012 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//                            CONFIGURATION                              //
///////////////////////////////////////////////////////////////////////////
 
// Set this to the amount of L$ needed to attain the goal.
integer GOAL = 100;
 
///////////////////////////////////////////////////////////////////////////
//                              INTERNALS                                //
///////////////////////////////////////////////////////////////////////////
 
// Progress @ http://grimore.org/fuss:lsl
string wasProgress(integer percent, integer length, list symbols) {
    percent /= (integer)((float)100.0/(length));
    string p = llList2String(symbols,0);
    integer itra = 0;
    do {
        if(itra>percent-1) p += llList2String(symbols,2);
        else p += llList2String(symbols,1);
    } while(++itra<length);
    return p + llList2String(symbols,3);
}
 
key _lastTip;
 
default
{
    state_entry() {
        // Set the pay buttons and click action.
        llSetPayPrice(100, [ "20", "40", "60", "80" ]);
        llSetClickAction(CLICK_ACTION_PAY);
        state update;
    }
    on_rez(integer num) {
        llResetScript();
    }
}
 
state donations {
    money(key id, integer amount) {
        _lastTip=id;
        llShout(0, "Thank you, " + llKey2Name(id) + " for the change!");
        llSetObjectDesc((string)((integer)llGetObjectDesc()+amount));
        state update;
    }
    on_rez(integer num) {
        llResetScript();
    }
}
 
state update {
    state_entry() {
        // Update the text with the current progress.
        llSetText("Spare a coin for this sim?\nProgress: " + wasProgress(((100*(integer)llGetObjectDesc())/GOAL), 5, ["[", "█", "░", "]"]) + " of L$" + (string)GOAL, <.5,1,1>, 1);
        // If the goal hasn't been reached, jump to the doner section.
        if((integer)llGetObjectDesc() < GOAL) jump doner;
        // If the goal has been attained or overstepped,
        // let the owner know, schedule a reset and return.
        llInstantMessage(llGetOwner(), "Donation goal attained!");
        llSetTimerEvent(60);
        return;
@doner;
        // If somebody tipped and this is not a script restart,
        // then get the display text and add a thank you message 
        // for the last tipper. We grab just the first name of 
        // the tipper to make the donation jar more personal.
        if(_lastTip) { 
            llSetText(llList2String(llGetPrimitiveParams([ PRIM_TEXT ]), 0) + "\nThank you, " + llList2String(llParseString2List(llKey2Name(_lastTip), [" "], [""]), 0) + "!", <.5,1,1>, 1);
            _lastTip = "";
        }
        // Go back to accepting donations.
        state donations;
    }
    timer() {
        // The goal has been attained, so after 60s we 
        // set the donations back to zero (laff) and we 
        // go back to accept donations.
        llSetObjectDesc("0");
        state donations;
    }
    on_rez(integer num) {
        llResetScript();
    }
}

secondlife/donation_jar/simple_donation_jar.txt · Last modified: 2017/02/22 18:21 (external edit)

Access website using Tor


For the copyright, license, warranty and privacy terms for the usage of this website please see the license and privacy pages.