Jump to content

4 way split avatar sensor tip jar


Moni Telling
 Share

You are about to reply to a thread that has been inactive for 1654 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Separate the task into two parts:  (1) Split the total in four parts  >>  integer sub_part = total / 4 .  (2) Give each person a part, if that person is in the region:

integer i;
while (i < 4)
{
    if ( llGetAgentSize(llList2Key(list_of_avatars,i) )
    {
        llTransferLindenDollars( llList2Key(list_of_avatars,i), sub_part );
    }
    ++i;
}

assuming that you have put the avatar keys into a global list, list_of_avatars.  Then you have to figure out what to do with any remaining parts. I'd suggest splitting them and sending them to the avatars who are in the region, but you could save them for the next time you have cash to split, or you could keep them yourself.  Same with any amount that's left over if the total amount of cash isn't evenly divisible by 4.

Edit: Oh, I forgot the bit about "too far from the tip jar".   Use the result of llGetObjectDetails ( llList2Key(list_of_avatars,i),[OBJECT_POS]) and llVecDist to write a test to see whether the avatar is close enough, once you have decided what "close enough" means.

Edited by Rolig Loon
  • Like 1
Link to comment
Share on other sites

okay your suggestion helped but I couldn't get it work the way you wrote. I did it the way I knew how It kinda worked but I still need some help figuring the rest and fix these bugs

 

list list_of_avatars = ["222ade58-d3bf-4fb7-9910-6e39008183fa","dd55ba04-18c0-4c5b-8241-d5503b6ec044"];

 integer i;
integer DebitPerms;

float comission=25; // for % comission
default
{
    state_entry()
    {
      llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
 
    run_time_permissions (integer perm)
    {
        if  (perm & PERMISSION_DEBIT)
            DebitPerms = TRUE;
    }
    money(key giver, integer amount)
    {
       
          integer i;
        integer length = llGetListLength(list_of_avatars);
        do
        {
             float percentage = (float)amount/100*comission;
           llGiveMoney(llList2Key(list_of_avatars,i),(integer)percentage);

llSay(0,(string)llList2Key(list_of_avatars,i));
}
        while(++i < length);
       

  } 
}

Link to comment
Share on other sites

3 hours ago, Moni Telling said:

        integer length = llGetListLength(list_of_avatars);

        do
        {
             float percentage = (float)amount/100*comission;

as wrote, a issue with the way the payment (percentage) is calculated is that 100/25 (1/4th) of the money received is paid to each avatar in the list

should the list have more than 4 avatars then the total paid will exceed the total received. While the intent is not to have more than 4 listed then money being money is best to safeguard against this by limiting the max. number of individual payments to 4

there are a number of ways to deal with this. One way is

integer number_of_payments = 4;

integer residual_amount = money;

integer amount_to_pay = residual_amount / number_of_payments;

if (amount_to_pay)  // > 0. will be 0 when money < number_of_payments
{
    integer length = llGetListLength(list_of_avatars);
    integer i;
    while ((i++ < length) && (number_of_payments--)) // pay up to the 1st 4 avatars found  
    { 
       key id = llList2Key(list_of_avatars, i - 1);
       if (llGetAgentSize(id))  
       {   // agent found on region
       	   if (llVectDist(llGetPos(), llList2Vector(llGetObjectDetails(id, [OBJECT_POS]), 0) <= 20.0)
           {    // agent within 20 meters
		llGiveMoney(id, amount_to_pay);
                residual_amount -= amount_to_pay;
           }
       }
    }
}

if (residual_amount)  // > 0
{
    // do something with it or keep it

}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1654 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...