Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Donations with optional goodie bag

Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
09-09-2005 05:03
There are two scripts here - one that takes money, updates the donations total and if you want to give a goodie bag as a thank you will do that if there's a a suitable minimum donation. That script could go out fully modable and copiable as you choose.

There's a second script that will contain the key of the target person that donations need to channel to - the organiser of the event or the treasurer say. That's set up at the moment to channel each donation straight through (minDonation = 0), but you can change that to other values if you choose.

The goodie bag script:
CODE

//This is a two part donation box script. This part takes the donations and gives a goodie bag if you set one up. It sends a message to the other script saying what's been given - that allows the target of the donations to hand out copies without revealing their key to everyone.

//Please feel free to change these parts.
integer minDonation=30; //How much is the minimum donation to trigger giving the goodie bag?
string goodieBagName="RFL 'I sailed for hope' goodies"; //What do you call the goodie bag?
string cause="All donations go to RFL."; //Who does the money go to?

//Please don't change these unless you know what you're doing.
list goodies;
integer num;
integer donations;

setList() //This creates the list of goodies to give away. It's a function because it's called in several places - state_entry, on_rez and changed to account for all the ways you can set it up.
{
num=llGetInventoryNumber(INVENTORY_ALL); //How many items are in the inventory?
goodies=[]; //reset the list.
integer i;
for(i=0; i<num; ++i) //add inventory items to the goodie bag list
{
string temp=llGetInventoryName(INVENTORY_ALL, i);
if(temp!=llGetScriptName() || temp!="Hand donations over") //But don't add the two important scripts
{
goodies+=temp;
}
}
num-=2; //We use this to change the text in the next function. You can use it to tell them how many items in there too if you want.
setText(); //Call the set text function. Since this updates from the money event too, it needs to be separate.
}
setText() //so we can set up the hover text.
{
if(num==0) //no goodie bad so just show the donations amount.
{
llSetText(cause+"\nThank you for your support.\nDonations to date $"+(string)donations, <1,1,1>, 1.0);
} else //there are goodies, so tell them the minimum donation to get the bag.
{
llSetText(cause+"\nThank you for your support.\nDonations to date $"+(string)donations+"\nA donation of at least $"+(string)minDonation+"\ngets a "+goodieBagName, <1,1,1>, 1.0);
}
}
default
{
state_entry() //Set everything up when starting
{
setList();
}
on_rez(integer params) //Let's you set it up and then rez it somewhere else.
{
setList();
}
changed(integer change) //if they change the number of things in the inventory.
{
if(change & CHANGED_INVENTORY)
{
setList();
}
}
money(key id, integer amount) //deal with the money
{
llSay(0, "Thank you for your kind donation "+llKey2Name(id)); //Say thanks
if(amount>=minDonation) //See if they need a goodie bag
{
llGiveInventoryList(id, goodieBagName, goodies); //Give it to them
}
llMessageLinked(LINK_SET, amount, "Donation", id); //Pass the donation message over
donations+=amount; //update total donations
setText(); //update the display
}
link_message(integer sender, integer amount, string msg, key id)
{
if(msg=="refund") //If the person has refused to allow the script to debit them (and hand the donations on) set it as broken
{
llInstantMessage(id, "This donation box is broken. Please ask "+llKey2Name(llGetOwner())+" for a refund."); //tell the person who's donating
llSetText("This box is broken, please donate elsewhere", <1,0,0>, 1.0); //Set the warning text
llRemoveInventory(llGetScriptName()); //Get rid of this script so they can't give money any more.
}
}
}

and the script to hand the donations over - you'll need your key to use this!
CODE

//This is the giver part of the script. Set the donate key to the right person so the money goes to them.
//The person rezing this box needs to give debit permissions.
key donate=NULL_KEY; //set this to the right key for the person you're giving the money to
integer minHandOver; //set this to the minimum amount you want to hand over in each chunk

//don't play below here

integer tempMoney;
integer perms;
default
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); //Ask them for permissions
}
on_rez(integer param)
{
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); //Ask them for permissions.
}
link_message(integer sender, integer amount, string msg, key id) //receive the link message
{
if(msg=="Donation") //check it's the right message
{
if((perms & PERMISSION_DEBIT) == PERMISSION_DEBIT) //check they've given the right permissions
{
tempMoney+=amount;
if(tempMoney > minHandOver)
{
llGiveMoney(donate, minHandOver); //hand the money over
tempMoney=0;
}
} else
{
llMessageLinked(LINK_THIS, amount, "refund", id); //send the 'this box is broken' alert
}
}
}
run_time_permissions(integer perm)
{
perms=llGetPermissions();
}
changed(integer change)
{
if(change & 128) //And again -- change & 128 is the changed owner tag.
{
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
09-10-2005 21:21
/15/bb/60949/1.html
_____________________
i've got nothing. ;)
a lost user
Join date: ?
Posts: ?
09-10-2005 22:27
Wouldn't it be better to have it set the key dynamically? Most likely using a touch event with the people not in the active group culled out? I made a tip jar script not long ago in these forums that does this. Anything that is dynamic is better than something that is static when possible. If it's not possible to make it dynamic fine.. but I don't see why this should be a static, hardcoded key.

Also curious why it is split into two? There's also a couple of other confusing things in there that could be tidied up a little. Though I don't want to pick it to pieces at this time.. if you want some feedback on it.. let me know.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
09-11-2005 06:37
I played with various options for keys, and although all the options you suggest are good what I wanted was something rather specifically for a situation (such as Relay for Life) where the money wasn't going to the owner of the object but to the designated receiver.

Although there are ways to code for that for any circumstance I figured it was easier to have the target of the donations set their own key in the script - there are tons of ways around for people to find their own keys after all.

The reason for two scripts is so that said target can distribute the script with one (the one with their key in it) unmodifiable - so the money always comes to them - and the other modifiable so that you can set your own minimum donations etc.

I'd be happy to hear your thoughts on ways to improve it too - I scripted it in a reasonable hurry and made sure it works - but I never claimed to be a superb scripter there are always things that I'm learning about both LSL and scripting in general.