Percentage Paying (optional) Tip Jar ( V2 )

Written by Kitsune

Pays the percentage (if chosen) to the founder of the group you set the object to.

 

UNDER CERTAIN CONDITIONS (That you set and agree to) THIS SCRIPT WILL TAKE MONEY FROM YOUR ACCOUNT.

 

 

// V2 //
 
key owner;
 
integer debit_perms = FALSE;
 
integer pay_price = 0;
 
list pay_buttons = [20, 50, 100, 250];
 
integer percentage = 50; // Percentage to pay to the founder of the group the object is set to.
 
key beneficiary;
 
string default_message = "/me is very grateful for the generous contribution from ";
 
string beneficiary_message = "% of which has been paid to the founder of ";
 
key group_key;
 
string group_name;
 
default
{
    on_rez(integer param) {
        llResetScript();
    }
    state_entry() {
        owner = llGetOwner();
        llSetObjectName(llKey2Name(owner) + "'s Money Box");
        llSetPayPrice(pay_price, pay_buttons);
        if (percentage) {
            llRequestPermissions(owner, PERMISSION_DEBIT);
        }
    }
    run_time_permissions(integer perms) {
        if (perms & PERMISSION_DEBIT) {
            debit_perms = TRUE;
            group_key = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0);
            if (group_key != NULL_KEY) {
                llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
            }
        } else {
            llOwnerSay("Permissions must be granted for this script to function.");
            llRequestPermissions(owner, PERMISSION_DEBIT);
        }
    }
    http_response(key q, integer status, list metadata, string body) {
        if(status == 200) {
            integer name_start = (llSubStringIndex(body, "") + 7);
            integer name_end = (llSubStringIndex(body, "") - 1);
            integer founder_key_start = (llSubStringIndex(body, "founderid") + 20);
            integer founder_key_end = (founder_key_start + 35);
            beneficiary = llGetSubString(body, founder_key_start, founder_key_end);
            group_name = llGetSubString(body, name_start, name_end);
        } else if (status != 404) {
            llOwnerSay("There is a problem O.o");
            llSleep(10.0);
            llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
        } else {
            llOwnerSay("Catastrophic failure! Run for you life!!");
        }
    }
    money(key id, integer amount)
    {
        string message = "";
        integer dividend;
        string payer = llKey2Name(id);
        if (!percentage) {
            message = (default_message + payer);
        } else {
            dividend = llFloor((((float)amount)/100.0) * ((float)percentage));
            if (dividend) {
                if (debit_perms) {
                    message = (default_message + payer + ".\n" + ((string)percentage) + beneficiary_message + group_name);
                    llGiveMoney(beneficiary, dividend);
                } else {
                    message = (default_message + payer);
                }
            }
        }
        llSay(PUBLIC_CHANNEL, message);
        // OR llInstantMessage(id, message);
    }
}
[edit]