Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script that pays 2 people on purchase? possible?

Oblivion Plasma
Registered User
Join date: 28 Feb 2006
Posts: 8
02-07-2007 02:46
Now, I had a quick search, but I am very very new at scripting. (I can make a box that says hello when in range of it, thats it so far), but am learning.

On one of my longer extended ideas or projects is to have a vendor or something that will sell something, but the funds from the sale will go to multipul people upon sale.

e.g. a group made an item, so the cash is split evenly to the contributers?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-07-2007 03:39
From: Oblivion Plasma
Now, I had a quick search, but I am very very new at scripting. (I can make a box that says hello when in range of it, thats it so far), but am learning.

On one of my longer extended ideas or projects is to have a vendor or something that will sell something, but the funds from the sale will go to multipul people upon sale.

e.g. a group made an item, so the cash is split evenly to the contributers?


If an item is group owned then each member of the group will get an equal share automatically when the item is bough/paid.

If you dont have a group 'group' then you will have to perform the same steps manually.
In the pay event you will need to calculate the amount to pay each person and then use
llGiveMoney(key,amount) to pay them. The owner of the object will need to give debit permissions (obviously).

You can set the split percentage if you use a second list to hold the percentages. Obviously you can also screw this up and end out paying more than 100%!
(of course you may want it to....)

A very simple script to give you a start point
CODE

list People = [ "xxxxx-xxxx-xxxxx-xxxxxx", // Newgate
"xxxxx-xxxx-xxxxx-xxxxxx"]; // who ever else

list Percentage = [ "90.0", // Newgate
"5.0"]; // who ever else - leaves 5% for owner

default
{
state_entry()
{
integer perms = llGetPermissions();
if((perms & PERMISSION_DEBIT) != PERMISSION_DEBIT)llRequestPermissions(llGetOwner() , PERMISSION_DEBIT );
integer NumberOfPeople = llGetListLength(People);
integer NumberOfPercents = llGetListLength(Percentage );
if(NumberOfPeople != NumberOfPercents)
{
Percentage = [];
llOwnerSay("ERROR : Number of People in List does not match number of entries in percentage pay out table.");
}
else
{
float total = 0.0;
integer index;
for(index = 0;index < NumberOfPeople;index++)
{
total += (float)llList2String(Percentage,index);
}
if(total > 100.0)
{
Percentage = [];
llOwnerSay("ERROR : Total percentage pay out table is greater than 100!");
}
}
}

money(key id, integer amt)
{
integer NumberOfPeople = llGetListLength(People);
integer NumberOfPercents = llGetListLength(Percentage );
float percentage = amt / NumberOfPeople;
integer index;
for(index = 0;index < NumberOfPeople;index++)
{
// Does match so use table percentages
if(NumberOfPeople == NumberOfPercents)
{
percentage = (float)llList2String(Percentage,index);
}
key av = llList2Key(People,index);
integer amount = (integer)(amt * percentage);
if(amount > 0)llGiveMoney(av,amount);
}
}
}
Oblivion Plasma
Registered User
Join date: 28 Feb 2006
Posts: 8
02-07-2007 04:14
Thankyou very much for this, I will take a good luck in a few hours once I finish off at work.

We are not part of a "group" group, but that maybe easier to sort out in a way.


Example.

I put this vendor script on a rendor on rented land.

I as the owner of the item that its selling gets 60% of the sale
The person I am renting the land off gets the other 40% of the sale price


The use of it isnt exactly that, but thats the best example I can give I think
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-07-2007 04:27
From: Oblivion Plasma
Thankyou very much for this, I will take a good luck in a few hours once I finish off at work.

We are not part of a "group" group, but that maybe easier to sort out in a way.


Example.

I put this vendor script on a rendor on rented land.

I as the owner of the item that its selling gets 60% of the sale
The person I am renting the land off gets the other 40% of the sale price


The use of it isnt exactly that, but thats the best example I can give I think



Obviously you will need to add code the money event to handle the actual vending of the item.
Also since its only you then using lists is over kill -


CODE

key PayCommisionTo = "xxxxx-xxxx-xxxxx-xxxxxx"; // Newgate
float Percentage = 90.0; // Newgate

default
{
state_entry()
{
integer perms = llGetPermissions();
if((perms & PERMISSION_DEBIT) != PERMISSION_DEBIT)llRequestPermissions(llGetOwner() , PERMISSION_DEBIT );
}

money(key id, integer amt)
{
integer amount = (integer)(amt * Percentage);
if(amount > 0)llGiveMoney(PayCommisionTo,amount);
}
}
Patrick2 Chama
Registered User
Join date: 15 Sep 2006
Posts: 52
02-07-2007 08:51
Here's one I found a while back when I was new 2 SL, but I forgot to write down who made it :(

If anyone knows who the author is, please post, I'd love to find out.

I've never actually tested it, but it looks functional. Looks like the names of the two people payed are entered into the object description seperated by a comma.

CODE

integer price;
key ida;
key idb;
float pca;
float pcb;

key buyer_id;

give_items()
{
integer i;
list give;
list item_give;
integer do_individual = FALSE;
for ( i=0 ; i<llGetInventoryNumber( INVENTORY_ALL ) ; i++ )
{
string iname = llGetInventoryName( INVENTORY_ALL, i );
if ( iname != llGetScriptName() )
{
if ( ( llGetInventoryPermMask( iname, MASK_OWNER ) & PERM_COPY ))
{
give = give + [ iname ];
}
else
{
item_give = item_give + [ iname ] ;
do_individual = TRUE;
}
}

}
llGiveInventoryList( buyer_id, llGetObjectName(), give );
if ( do_individual )
{
for ( i=0 ; i>llGetListLength( item_give ) ; i++ )
{
llGiveInventory( buyer_id, llList2String( item_give, i ));
}
}
}

init()
{
llRequestPermissions ( llGetOwner(), PERMISSION_DEBIT );
}
default
{
state_entry()
{
init();
}
on_rez( integer param )
{
init();
}
run_time_permissions( integer perm )
{
if ( (perm && PERMISSION_DEBIT) )
{
state ready;
}
else
{
llOwnerSay ( "To share proceeds I must have give money(DEBIT) permissions");
llOwnerSay ( "Try again");
llResetScript();
}
}
}
state ready
{
state_entry()
{
list temp = llCSV2List(llGetObjectDesc());
price = (integer)llList2String(temp,0);
ida = llList2String(temp,1);
pca = (float)llList2String(temp,2);
idb = llList2String(temp,3);
pcb = (float)llList2String(temp,4);
llOwnerSay ( (string)pca + " percent will go to (1st name shown) ");
llRequestAgentData ( ida, DATA_NAME );
llOwnerSay ( (string)pcb + " percent will go to (2nd name shown) ");
llRequestAgentData ( idb, DATA_NAME );
llSleep(2);
llSetText ( llGetObjectName() + "\nPrice " + (string)price , <1,1,1>,1);
}
dataserver( key id, string NAME )
{
llOwnerSay( NAME + " will receive proceeds from sale of this item" );
}
money ( key id, integer amount )
{
buyer_id = id;
if ( amount != price )
{
llInstantMessage( id, "Sorry the price for this item is " + (string)price +". Your payment has been refunded");
llGiveMoney( id, amount );
return;
}
give_items();
llInstantMessage ( id, "Thankyou for your purchase - We hope you enjoy");
float calc = amount + 0.0;
float a = calc * ( pca/100 );
float b = calc * ( pcb/100 );
llGiveMoney( ida, (integer)a );
llGiveMoney( idb, (integer)b );
llOwnerSay ( llGetObjectName() + " was purchased and the proceeds split as follows :" );
llOwnerSay ( (string)a + " to person 1, and " + (string)b + " to person 2." );
llInstantMessage ( ida, "you have been paid " + (string)a +
" from the sale of " + llGetObjectName() );
llInstantMessage ( ida, "you have been paid " + (string)a +
" from the sale of " + llGetObjectName() );
}
}
Strollerweb Market
Registered User
Join date: 20 Nov 2006
Posts: 21
02-09-2007 12:36
I keep getting a llGiveMoney invalid parameter warning with all these scripts!
I asuming that the XXXX's are the avatar name!

key PayCommisionTo = "xxxxx-xxxx-xxxxx-xxxxxx"; // Newgate

or am I totaly missing the plot here!
Breandan Turas
Registered User
Join date: 7 Nov 2006
Posts: 1
02-09-2007 13:12
llGiveMoney utilizes av's Key not name

There are probably different ways of finding out an av's key ... but an easy way is to write quick script for a single prim object using a touch_start trigger ... and llDetectedKey to return the key of the av that touches the object, convert the key to a string and have the object say it ....

Hope this helps.
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-09-2007 13:33
No, they're user keys (UUIDs).

Put this script in an object and touch it.

CODE

default
{
state_entry()
{
llSetText("Touch me\nand I'll say\nyour UUID\n\n", <1.0,1.0,1.0>,1.0);
llSetObjectName("UUID Speaker");
}

touch_start(integer total_number)
{
llSay(0, llDetectedName(0) + ": " + (string)llDetectedKey(0));
}
}


That tells you your key.
Strollerweb Market
Registered User
Join date: 20 Nov 2006
Posts: 21
02-11-2007 07:54
well that worked thank you.

I used the script posted by Patrick 2 Chama (in this thread) which works great. the only thing it does not do is let the second person know where the money came from. It just says Object Pay! any idea on how to show who and what paid?

I must admit i did not use the Description field for the values, I just entered the values, but i dont think that made any difference!
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-11-2007 09:18
The llInstantMessage calls should tell the other recipient, but there's a typo -- the 'ida' in the second call should be 'idb'.

However, those could be a real nuisance for anyone receiving lots of money from these objects, so it should be optional, card configurable and/or touch to change via menu.
Strollerweb Market
Registered User
Join date: 20 Nov 2006
Posts: 21
02-13-2007 14:18
Yeah picked up on the instant message call being a repeat, thats ok.

The problem comes when looking at thier Transaction History through the users account on the Web site, it just says an Object Paid x amount as there is a few of us using this script now, the landlord does not know who has paid! any ideas on how to pass a description into this?