Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Joint sales script (split profit vendor)

daiz Papp
Registered User
Join date: 31 Jul 2007
Posts: 7
01-31-2008 03:25
split profit vendor script, split payment.
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();
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Library bump
02-14-2008 08:54
:o
_____________________
i've got nothing. ;)
daiz Papp
Registered User
Join date: 31 Jul 2007
Posts: 7
readme, manual by english
02-23-2008 11:22
[object name]

Joint Sales Script

[creation date]

Jan.30.2008 (2008/01/30)

updete May.22.2008 (2008/05/22)

[contents]

spv.sys (full permisson)
spv.que (full permisson)
spv.dat (full permisson)

[how to use]

split profit vendor script, split payment.

open "spv.dat" and write setting.

avatar name(owner1),(price)split profit,email,UUID(owner1)
avatar name(owner2),(price)split profit,email,UUID(owner2)

[example #1]
daiz Papp,8,,
daiz Papp,4,,

UUID can be obtained by automatic operation. if e-mail address is not written, e-mail is not sent.

[example #2]
daiz Papp,5,IM,

write "IM" when you send IM instead of e-mail.

[example #3]
daiz Papp,5,IM,f6a79bc8-aca4-4b2d-9818-2e26ce55c919

Avatar doesn't exist, please reconfirm the name of avatar.
still, please acquire UUID and write if it is impossible.

open "spv.sys" please look at item(your setting) for you to set it.

# TRUE is use, FALSE is doesn't use

(Price) sales price
(Repayment) automatic repayment function when error occurs.
(AutoSplit) evenly distributes
(GiveAll) all items in contents are given.
(GiveList) write item that wants to be given.... ["hair", "shoes", "guns"]

(UseIms) instant message
(UseEmail) e-mail

(NoteName) notecard name
(ScriptName) this sctipt name

(HttpRetry) communication to obtain UUID, retrial when error occurs.
(HttpTimeOut) time until discontinuing it when communication is crowded.

#

tree are put in sold box(contents). "spv.dat" and "spv.sys" "spv.que".

spv.dat(notecard) is put first. when script is put, it is initialized.
please permit remitting. initialize script again if you rewrite notecard.

[others]

this script can be freely used. but, please do not sell this script.
you can sell this script if ameliorable. please do not add license such as GNU GPL to it.

please do not put same two scripts. when repayment function is used, twice amount of money are repaid.
there is possibility money's being plundered, too, if you have permitted others edit of object.
use it carefully enough. llGiveMoney script accompanies risk.
daiz Papp
Registered User
Join date: 31 Jul 2007
Posts: 7
readme, manual by japanese
02-23-2008 11:34
[使い方]

複数のオーナーで作成したオブジェクトへの支払を各オーナーに自動で分配するスクリプトです。

spv.dat(ノートカード)を編集して複数のオーナー設定を行います。一行ごとに共同販売者の設定を書いてください。

アバター名(1),分配金,メールアドレス,アバターのUUID
アバター名(2),分配金,メールアドレス,アバターのUUID

カンマで区切ります。カンマが3つ以上あると認識されません。

(例) daiz Papp,40,e-mail.co.jp,f6a79bc8-aca4-4b2d-9818-2e26ce55c919
メールアドレスやUUIDは書く必要はありません。商品が売れた時にメールアドレスを書いた人だけにメールが送信されます。

# spv.sys(スクリプト)を開き "your setting" の部分を編集してください。TRUE 使用する FALSE 使用しない

(Price) 販売価格
(Repayment) 返金機能

(AutoSplit) ノートカードの分配設定を無視して自動で均等に分配
(GiveAll) 支払があった際に、コンテンツ内の全てを渡す(このスクリプトとノートカードは含まれない)
(GiveList) 支払があった際にリストに書かれた物だけ渡す (例)list GiveList = ["説明書","アイテム","写真"];
*) コンテンツ内にリスト内のアイテムが一つでも不足している場合は全て受け渡しが行われません。
(UseIms) 支払があった際にIMで通知(ノートカードのメールアドレス値にIMと書くこと)
(UseEmail) 支払があった際にメールで通知(ノートカードに書かない場合は通知されない)

(NoteName) ノートカードの名前
(ScriptName) スクリプトのリスト
*)ノートカードとスクリプトに書かれた名前のファイルは受け渡しされません。

(HttpRetry) w-hat.comへの通信エラーが出た際のリトライ回数。*)UUIDを自動で取得するための通信で、設置時に一度だけ行われます。
(HttpTimeOut) w-hat.comからUUIDを取得する際に何秒でタイムアウトするか?通信が混雑していた場合や時間がかかる場合中止します。

#

販売するオブジェクトに、設定したノートカードから入れて、その後にスクリプトを入れると初期化されます。
ノートカードを書き換えた際は、スクリプトを再コンパイルするか、取り出して削除して、再び入れてください。
分配用のllGiveMoneyを使用を許可するかどうかのダイアログが表示されるので、許可してください。

UUIDはw-hat.comから自動で取得します。
[sharing owner(アバター名)doesn't exist]と表示されるとUUIDが取得できないため、そのアバターへの分配は行われません。
アバター名が間違っていないか確認してください。
w-hat.comからUUIDが取得できない場合はアバターがいる場所でUUIDを取得してもらってノートカードに直接書いてください。
初期化が終了すればメッセージが表示されます。支払分配者がいない。設置したオーナーが全金額を受け取る。

#

返金機能をオンにしている
1)受け渡しされるアイテムがない場合は返金されます。
2)受け渡しされるアイテムリストのアイテムが一つでもない場合は全てのアイテムを渡たさず、返金されます。

返金機能をオフにしている
上記の1) 2)の場合、返金されないお金はオブジェクトの所有者に全額支払われます。
*)メールやIMの設定をしている場合、他の分配者にそのエラー通知のみが届きます。

[その他]

このスクリプトは自由に使用することができます。スクリプトのオリジナルを販売しないでください。
スクリプトを改善したものや、作成したオブジェクトにスクリプトを入れて販売することはできます。
その際にスクリプトを "no modify" にしてもかまいません(他のパーミッションを付加することも可能)。
GNU General Public License (GPL)等のそうした行為ができなくなるライセンスを付加しないでください。

*)直接の転売や、単純に日本語に翻訳しただけ、別の箱に入れて違うものだと言って販売する以外は自由です。

同じスクリプトを2つ入れると支払額の2倍の返金を行ってしまうので注意してください。
llGiveMoneyを使用したスクリプトはオーナーの指示なしに自動で送金を行います。
他人にオブジェクトを修正できる権限を与えていたり、予期せぬ不具合でお金を奪いとられる可能性もあります。

メール送信機能を使用していている場合、20秒間に1通しか送信できない制限があります。
この間に20回以上の支払いがあった場合、支払情報の一部がメールで送信されない場合があります。

メモリの制限上、分配できるオーナー数は10名程度です。メールアドレスや名前の長さによって変わります。
初期化できても支払時の処理でメモリを消費するため、10名はエラーがでない目安です。
*)最大で30名、通信の制限があるので20名が限度です。
メモリのエラーが出た場合、スクリプトを初期化しないと販売や分配が正常に行われない状態になります。