please look at next comment about explanation.
// script code [spv.sys] -------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
// your setting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
integer Price = 10;
integer Repayment = FALSE;
integer AutoSplit = TRUE;
integer GiveAll = TRUE;
list GiveList = [];
integer UseIms = TRUE;
integer UseEmail = TRUE;
string NoteName = "spv.dat";
list ListScript = ["spv.sys","spv.que"];
integer HttpRetry = 10;
float HttpTimeOut = 30;
// your setting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
list ListName = [];
list ListUuid = [];
list ListPrice = [];
list ListEmail = [];
integer Server = FALSE;
float ServerTimeOut = 10;
integer Note = TRUE;
integer NoteLine = 0;
list RequestKey = [];
list RequestName = [];
list Distribution = [];
integer Balance = 0;
string GetUrl(vector pos)
{
return "http://slurl.com/secondlife/" + llGetRegionName() + "/" + (string)llFloor(pos.x) + "/" + (string)llFloor(pos.y)+ "/" + (string)llFloor(pos.z);
}
SendMail(integer check, key id, integer pay)
{
integer Length = llGetListLength(ListName);
integer i = 0;
for(i = 0; i < Length; i++)
{
string Address = llList2String(ListEmail, i);
string Error = llList2String(["give error, ","purchase, "], check);
if(Address == "IM"

{
if(UseIms)
{
string Message = "joint sales " + Error + llKey2Name(id) + ". payment " + (string)pay + "L$. ";
Message += "region: " + GetUrl(llGetPos());
llInstantMessage(llList2Key(ListUuid, i), Message);
}
}
else if(Address != ""

{
string Message = "Joint sales " + Error + " \n";
Message += "Region: " + GetUrl(llGetPos()) + "\n";
Message += "Avatar: " + llKey2Name(id) + "\n";
Message += "Payment: " + (string)pay + "L$\n\n";
integer Value = llList2Integer([pay,Balance],check);
Message += "Object owner: " + llKey2Name(llGetOwner()) + "\nBalance: " + (string)Value + "L$\n\n";
if(check)
{
Message += "Split profit: \n";
integer Split = llGetListLength(ListName);
integer j = 0;
for(j = 0; j < Split; j++)
Message += llList2String(ListName, j) + " (" + llList2String(Distribution, j) + "L$)" + "\n";
}
llMessageLinked(LINK_SET, 10000, Address, NULL_KEY);
llMessageLinked(LINK_SET, 10001, "Secondlife - Joint sales", NULL_KEY);
llMessageLinked(LINK_SET, 10002, Message, NULL_KEY);
}
}
}
SplitPayment(integer pay)
{
Balance = pay;
integer Length = llGetListLength(ListName);
if(Length == 0)
return;
Distribution = [];
integer i = 0;
for(i = 0; i < Length; i++)
{
integer Split = 0;
if(AutoSplit)
Split = pay / Length;
else
Split = (integer)llList2String(ListPrice, i);
if(Split > 0)
{
if((Balance - Split) < 0)
Split = Balance;
Balance -= Split;
}
else
Split = 0;
if(Balance > -1)
{
Distribution = (Distribution=[]) + Distribution + [(string)Split];
if(Split > 0)
llGiveMoney(llList2Key(ListUuid, i), Split);
}
else
Distribution = (Distribution=[]) + Distribution + ["0"];
}
}
CheckPayment(key id, integer pay)
{
if(pay == Price)
{
integer Check = TRUE;
integer Length = llList2Integer([llGetListLength(GiveList),llGetInventoryNumber(INVENTORY_ALL)], GiveAll);
list List = [];
integer i = 0;
for(i = 0; i < Length; i++)
{
string Name = llList2String([llList2String(GiveList, i), llGetInventoryName(INVENTORY_ALL, i)], GiveAll);
if(llListFindList([NoteName] + ListScript, [Name]) == -1 && llGetInventoryType(Name) != -1)
List = (List=[]) + List + [Name];
}
integer Count = llGetListLength(List);
if((Count != 0 && GiveAll) || (Count != 0 && Count == Length && !GiveAll))
{
for(i = 0; i < Count; i++)
llGiveInventory(id, llList2String(List, i));
Check = FALSE;
}
if(Check && Repayment)
llGiveMoney(id, pay);
else if(!Check)
{
SplitPayment(pay);
if(UseEmail)
SendMail(TRUE, id, pay);
}
else
SendMail(FALSE, id, pay);
}
else if(Repayment)
llGiveMoney(id, pay);
else
SendMail(FALSE, id, pay);
}
CheckAvatar()
{
llSetTimerEvent(0);
Server = FALSE;
integer Length = llGetListLength(ListUuid);
integer i = 0;
for(i = 0; i < Length; i++)
{
if(llList2String(ListName, i) != llList2String(RequestName, i))
{
llOwnerSay("sharing owner, \"" + llList2String(ListName, i) + "\" doesn't exist."
;ListUuid = llDeleteSubList(ListUuid, i, i);
ListUuid = llListInsertList(ListUuid, [""], i);
}
}
RequestKey = [];
RequestName = [];
list _ListName = [];
list _ListUuid = [];
list _ListPrice = [];
list _ListEmail = [];
for(i = 0; i < Length; i++)
{
if(llList2String(ListUuid, i) != ""

{
_ListName = (_ListName=[]) + _ListName + [llList2String(ListName, i)];
_ListUuid = (_ListUuid=[]) + _ListUuid + [llList2Key(ListUuid, i)];
_ListPrice = (_ListPrice=[]) + _ListPrice + [llList2String(ListPrice, i)];
_ListEmail = (_ListEmail=[]) + _ListEmail + [llList2String(ListEmail, i)];
}
}
ListName = _ListName;
ListUuid = _ListUuid;
ListPrice = _ListPrice;
ListEmail = _ListEmail;
if(llGetListLength(ListName) != 0)
llOwnerSay("initialize ok, owners: " + llList2CSV(ListName));
else
llOwnerSay("initialize ok, no part owner."
;}
Key2Name()
{
Server = TRUE;
llSetTimerEvent(ServerTimeOut);
HttpTimeOut = -1;
RequestKey = [];
integer Length = llGetListLength(ListUuid);
NoteLine = Length;
integer i = 0;
for(i = 0; i < Length; i++)
{
key Key = llList2Key(ListUuid, i);
if(Key == NULL_KEY)
{
NoteLine --;
RequestKey = (RequestKey=[]) + RequestKey + [NULL_KEY];
}
else
RequestKey = (RequestKey=[]) + RequestKey + [llRequestAgentData(Key, DATA_NAME)];
RequestName = (RequestName=[]) + RequestName + [""];
}
if(NoteLine == 0)
CheckAvatar();
}
Name2Key()
{
integer Length = llGetListLength(ListName);
integer i = 0;
for(i = 0; i < Length; i++)
{
if(llList2Key(ListUuid, i) == NULL_KEY)
{
key Key = llHTTPRequest("http://w-hat.com/name2key?terse=1&name=" + llEscapeURL(llList2String(ListName, i)), [], ""
;RequestKey = (RequestKey=[]) + RequestKey + [Key];
}
else
{
RequestKey = (RequestKey=[]) + RequestKey + [NULL_KEY];
NoteLine --;
}
}
if(NoteLine == 0)
Key2Name();
else
llSetTimerEvent(HttpTimeOut);
}
ReceiveUuid(integer status, key id, string body)
{
integer Index = llListFindList(RequestKey,[id]);
if(Index == -1 || id == NULL_KEY)
return;
if(status == 499 || status != 200)
{
HttpRetry --;
if(HttpRetry < 0)
llOwnerSay("HTTP error, \"" + llList2String(ListName, Index) + "\" was not completed."
;else
{
key Key = llHTTPRequest("http://w-hat.com/name2key?terse=1&name=" + llEscapeURL(llList2String(ListName, Index)), [], ""
;RequestKey = llDeleteSubList(RequestKey, Index, Index);
RequestKey = llListInsertList(RequestKey, [Key], Index);
}
}
else
{
key Key = NULL_KEY;
if((key)body != NULL_KEY)
Key = (key)body;
ListUuid = llDeleteSubList(ListUuid, Index, Index);
ListUuid = llListInsertList(ListUuid, [Key], Index);
NoteLine --;
if(NoteLine == 0)
Key2Name();
}
}
default
{
on_rez(integer i)
{
//llResetScript();
}
state_entry()
{
llResetTime();
llSetTimerEvent(0);
llOwnerSay("load " + NoteName + ", please wait ..."
;llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
llSetPayPrice(PAY_HIDE, [ Price, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
if(llGetInventoryType(NoteName) != -1)
llGetNotecardLine(NoteName, NoteLine);
else
{
llOwnerSay("\"" + NoteName + "\" notecard is not found."
;CheckAvatar();
}
}
run_time_permissions(integer i)
{
if(!(i & PERMISSION_DEBIT))
llOwnerSay("permission of distribution \"PERMISSION_DEBIT\" was not able to be acquired."
;}
money(key id, integer i)
{
CheckPayment(id, i);
}
timer()
{
if(HttpTimeOut > 0)
{
llOwnerSay("HTTP request is time out."
;llSetTimerEvent(0);
HttpTimeOut = -1;
Key2Name();
}
if(Server)
{
llOwnerSay("SERVER request is time out."
;CheckAvatar();
}
}
http_response(key id, integer status, list metadata, string body)
{
if(HttpTimeOut < 0)
return;
ReceiveUuid(status, id, body);
}
dataserver(key id, string data)
{
if(Note)
{
if(data != EOF)
{
list List = llCSV2List(data);
if(llGetListLength(List) == 4)
{
ListName = (ListName=[]) + ListName + [llList2String(List,0)];
string Key = llList2String(List,3);
if(Key == ""
Key = (string)NULL_KEY;ListUuid = (ListUuid=[]) + ListUuid + [(key)Key];
ListPrice = (ListPrice=[]) + ListPrice + [llList2String(List,1)];
ListEmail = (ListEmail=[]) + ListEmail + [llList2String(List,2)];
}
NoteLine ++;
llGetNotecardLine(NoteName, NoteLine);
}
else
{
Note = FALSE;
NoteLine = llGetListLength(ListName);
if(llGetListLength(ListName) != 0)
Name2Key();
else
llOwnerSay("initialize ok. no part owner."
;}
}
else
{
integer Index = llListFindList(RequestKey,[id]);
if(Index == -1 || id == NULL_KEY)
return;
NoteLine --;
RequestName = llDeleteSubList(RequestName, Index, Index);
RequestName = llListInsertList(RequestName, [data], Index);
if(data == EOF || NoteLine == 0)
CheckAvatar();
}
}
}
// script code [spv.que] -------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
string Address = "";
string Subject = "";
string Message = "";
InitData()
{
Address = "";
Subject = "";
Message = "";
}
default
{
link_message(integer sender_num, integer num, string data, key id)
{
if(num == 10000)
{
InitData();
Address = data;
}
else if(num == 10001)
Subject = data;
else if(num == 10002)
{
Message = data;
llEmail(Address, Subject, Message);
InitData();
}
}
}
