02-18-2013, 02:34 AM
PHP Code:
//CDru
key owner;integer stp;key req;integer done=0;
//This is the list of partners that the object should split profits with.
//Please note that if the entry is a UUID, the script does not need to perform
//any outworld search to acquire the UUID based on name.
//If entry is a name, please make it exact, though it
//does not need to be case sensitive.
//The first example is provided. The profit holders are left in blank.
//If you wish to add profit holders, either enter their name, or their
//UUID. (If name, make sure it is full name - not case sensitive)
//
//Example:
//
//Each entry should be "Name or UUID", Percentage of profit,
//
//list partners=[
// "Charliedru Lannock", 5, //Entries before the last need a comma after the quotation mark.
// "Carina Luminos", 5,
// "8f12ef0d-78e2-47da-af07-36392fdc816a", 5 //The last entry gets no comma after the quotation mark.
//];
//This should be limited to 20 partners maximum.
list partners=[
"", 10,
"", 20
];
list garbage=[];
list finaldata=[];
//Function Handlers
//Next step to check in partners list
next(){stp+=2;llSetTimerEvent(0.1);}
//Return the string for the current step
string l2s(){return llList2String(partners,stp);}
//Request debit permissions for split profit
reqq(){llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);}
//Return the amt to give to the partner
integer cut(integer percent, integer amt){return (integer)(((float)percent/100)*amt);}
//Add data to be removed to the garbage list.
discard(string tmp){llOwnerSay("Discarding "+tmp+" due to invalid name/key.");garbage+=tmp;}
//Verify the list to see it is a UUID. If not, then
//do an HTTP Request to acquire the person's UUID.
listcheck(){
if(stp>=(llGetListLength(partners)-1)){
dump();return;
}
string tmp=l2s();
if(tmp==""){llOwnerSay("Error: There are blank entries in the script. Please enter data the data necessary.");return;}
if((key)tmp!=NULL_KEY && llStringLength(tmp)==36){
finaldata+=[tmp,llList2Integer(partners,stp+1)];
next();return;
}
else{
if(llGetListLength(llParseString2List(tmp,[" "],[]))!=2){
discard(tmp);next();return;
}
else{
req=llHTTPRequest("http://w-hat.com/name2key?terse=1&name="+llEscapeURL(tmp),[],"");
}
}
}
//Dump the invalid data
dump(){
partners=[];garbage=[];
done=1;llSetTimerEvent(0.25);
}
//Pay out to the partners based on each of their shares
payout(integer amt){integer a=0;integer b=llGetListLength(finaldata);
for(;a<b;a++){
if(a%2==0){
if(llList2Integer(finaldata,a+1)!=0) llGiveMoney(llList2Key(finaldata,a),cut(llList2Integer(finaldata,a+1),amt));
}
}
}
default{
on_rez(integer parm){llResetScript();}
state_entry(){owner=llGetOwner();llOwnerSay("/me requires Debit Permissions to split profits. Please accept.");
reqq();
}
http_response(key rid, integer stat, list metadata, string body){
if(req==rid){
string tmp=l2s();
if((key)body==NULL_KEY){
discard(tmp);next();return;
}
else{
garbage+=tmp;finaldata+=body;finaldata+=llList2Integer(partners,stp+1);next();
}
}
}
run_time_permissions(integer perm){
if(perm&PERMISSION_DEBIT){
llOwnerSay("Please provide a moment to verify the list of profit holders.");
stp=0;listcheck();
}
}
timer(){
llSetTimerEvent(0.0);
if(!done)listcheck();
else
state ready2pay;
}
}
state ready2pay{
on_rez(integer parm){llResetScript();}
state_entry(){llOwnerSay("List has been verified. Split profit is now enabled for all on the partner list.");}
money(key who, integer amt){
if(llGetListLength(finaldata)<=1) return;
payout(amt);
}
}
//CDru