Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

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
Discussion Thread
09-10-2005 21:21
/54/a1/61165/1.html
_____________________
i've got nothing. ;)