Difference between revisions of "LlTransferLindenDollars"

From Second Life Wiki
Jump to navigation Jump to search
m
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/permission|PERMISSION_DEBIT|grant=the owner}}{{LSL Function/avatar|destination}}
|inject-2={{LSL_Function/permission|PERMISSION_DEBIT|grant=the owner}}{{LSL Function/avatar|destination}}
{{Issues/VWR-28201}}{{Issues/SVC-7623}}
|func_id=?|func_sleep=0.0|func_energy
|func_id=?|func_sleep=0.0|func_energy
|func=llTransferLindenDollars
|func=llTransferLindenDollars
|return_type=key|return_text=used in a matching [[transaction_result]] event for the success or failure of the transfer. If the transaction is successful, this key will show in the [https://secondlife.com/my/account/transactions.php transaction history].
|return_type=key|return_text=used in a matching [[transaction_result]] event for the success or failure of the transfer. If the transaction is successful, this key will show in the [https://secondlife.com/my/account/transactions.php transaction history].
|p1_type=key|p1_name=destination
|p1_type=key|p1_name=destination
|p2_type=integer|p2_name=amount|p2_desc=number of L$, must be greater than zero, ('''amount''' &gt; 0)
|p2_type=integer|p2_name=amount|p2_desc=number of L$, must be greater than zero, ({{LSLP|amount}} &gt; 0)|p2_hover=number of L$, must be greater than zero, ('amount' &gt; 0)
|func_desc=Transfer '''amount''' of L$ money from script owner to '''destination''' avatar.
|func_desc=Transfer {{LSLP|amount}} of L$ money from script owner to {{LSLP|destination}} avatar.
|func_footnote=If you aren't going to use the return value or the resulting [[transaction_result]] event consider using [[llGiveMoney]] instead of this function.
|func_footnote=If you aren't going to use the return value or the resulting [[transaction_result]] event consider using [[llGiveMoney]] instead of this function.
|spec
|spec
Line 14: Line 15:
*Once a script has the [[PERMISSION_DEBIT]] permission it can empty an account of L$.
*Once a script has the [[PERMISSION_DEBIT]] permission it can empty an account of L$.
**Fraud & theft are both {{LL|TOS}} violations and crimes. Misuse this function and you risk being banned and legal action. In addition LL may freeze the accounts of anyone the money is transferred to and restore it to it's rightful owners. This may involve retrieving it from third party exchanges and accounts on those exchanges being frozen. The system is not designed to be friendly towards fraud.
**Fraud & theft are both {{LL|TOS}} violations and crimes. Misuse this function and you risk being banned and legal action. In addition LL may freeze the accounts of anyone the money is transferred to and restore it to it's rightful owners. This may involve retrieving it from third party exchanges and accounts on those exchanges being frozen. The system is not designed to be friendly towards fraud.
|examples=<lsl>//A simple piggy bank, anyone can pay in money and anyone can click it to get money out.
|examples=<source lang="lsl2">
// Pay 100 L$ to Fred Bloggs when he touches this prim
// Die if the transfer of funds was successful, else keep running


integer AMOUNT = 10; //The amount of money to be given each time it is clicked.
string  Recipient = "Fred Bloggs";     // Authorised recipient
integer STASH = 50;   //The amount of money the script has to give out by default.
integer Amount = 100;                   // Amount to pay Fred when he touches the prim


list trks;
integer DebitPerms;
 
key     TransactionID=NULL_KEY;
update()
{
     if(STASH >= AMOUNT)
        llSetText("I have L$"+(string)STASH + " to give away!", <1,1,1>, 1);
    else
        llSetText("I have no L$ to give away :(", <1,1,1>, 1);
}


default
default
Line 33: Line 29:
     state_entry()
     state_entry()
     {
     {
         llRequestPermissions(llGetOwner(), PERMISSION_DEBIT );
        // Ask the owner for permission to debit their account
         llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
     }
     }


     run_time_permissions (integer perm)
     run_time_permissions (integer perm)
     {
     {
         if(perm & PERMISSION_DEBIT)
         if (perm & PERMISSION_DEBIT)
        {
             DebitPerms = TRUE;
             state ready;    
        }
     }
     }
}


state ready
     touch_start(integer num_detected)
{
     state_entry()
     {
     {
         update();
         if (!DebitPerms)
            return;  // Cannot proceed - debit permissions not granted
        if (llDetectedName(0) != Recipient)
            return;  // unauthorised person is touching - ignore
        if (TransactionID != NULL_KEY)
            return;  // waiting on previous transaction to complete/fail
 
        key id = llDetectedKey(0);
        TransactionID = llTransferLindenDollars(id, Amount);
     }
     }
     touch_start(integer num)
 
     transaction_result(key id, integer success, string data)
     {
     {
         if(STASH >= AMOUNT)
         if (id != TransactionID)
            return;          // Ignore if not the expected transaction
       
        if (success)
         {
         {
             trks += llTransferLindenDollars(llDetectedKey(0), AMOUNT);
             llOwnerSay( "Transfer of L$ to " + Recipient + " was successful");
             STASH -= AMOUNT;
             llSleep(1.0);
             update();
             llDie();         // Die so Fred can't keep taking money
         }
         }
         else
         else
         {
         {
             llWhisper(0, "No more money to give away :(");
             llOwnerSay( "Transfer of L$ failed");
            TransactionID = NULL_KEY;
            // Keep the script running so Fred can try again, clear TransactionID to allow a new attempt
         }
         }
     }
     }
    money(key id, integer m)
}
    {
</source>
        STASH += m;
|complex_examples=
        update();
{{LSL DefineRow||[[Simple Piggy Bank]]|}}
    }
    transaction_result(key id, integer success, string data)
    {
        integer i = llListFindList(trks, [id]);
        if(~i)//Is it one of our transactions?
        {//It was!
            trks = llDeleteSubList(trks, i, i);
            if(!success)//Did it fail?
            {//Put the money back in the bank.
                //TODO: Handle the different transaction failure modes returned in the data CSV.
                STASH += AMOUNT;
                llWhisper(0, "Sorry but the transaction failed for some reason :(");
            }
        }
    }
}</lsl>
|helpers
|helpers
|also_functions=
|also_functions=
Line 99: Line 89:
|cat4
|cat4
|cat5
|cat5
|history = Date of Release  [[ Release_Notes/Second_Life_Server/11#11.12.03.246118 | 03/12/2011 ]]
}}
}}

Latest revision as of 11:12, 22 January 2015

Summary

Function: key llTransferLindenDollars( key destination, integer amount );

Transfer amount of L$ money from script owner to destination avatar.
Returns a key used in a matching transaction_result event for the success or failure of the transfer. If the transaction is successful, this key will show in the transaction history.

• key destination avatar UUID
• integer amount number of L$, must be greater than zero, (amount > 0)

To run this function the script must request the PERMISSION_DEBIT permission with llRequestPermissions and it must be granted by the owner. If you aren't going to use the return value or the resulting transaction_result event consider using llGiveMoney instead of this function.

Caveats

Permissions
  • Do not depend upon the auto-grant status of permissions. Always use the run_time_permissions event.
  • If the script lacks the permission PERMISSION_DEBIT, the script will shout an error on DEBUG_CHANNEL and the operation fails (but the script continues to run).
  • If PERMISSION_DEBIT is granted by anyone other than the owner, then when the function is called an error will be shouted on DEBUG_CHANNEL.
  • Once the PERMISSION_DEBIT permission is granted there is no way to revoke it except from inside the script (for example, with a new llRequestPermissions call) or the script is reset or deleted.
  • An object cannot pay another object.
  • Objects deeded to groups cannot give money (the permission cannot be granted).
  • Use is limited to 30 payments in a 30 second interval for all scripts owned by that resident on a region. Sustained overage will produce a script error and halt payments while the rate remains excessive. Historically, faster payments have failed intermittently.
  • Once a script has the PERMISSION_DEBIT permission it can empty an account of L$.
    • Fraud & theft are both Linden Lab violations and crimes. Misuse this function and you risk being banned and legal action. In addition LL may freeze the accounts of anyone the money is transferred to and restore it to it's rightful owners. This may involve retrieving it from third party exchanges and accounts on those exchanges being frozen. The system is not designed to be friendly towards fraud.

Examples

// Pay 100 L$ to Fred Bloggs when he touches this prim
// Die if the transfer of funds was successful, else keep running

string  Recipient = "Fred Bloggs";      // Authorised recipient
integer Amount = 100;                   // Amount to pay Fred when he touches the prim

integer DebitPerms;
key     TransactionID=NULL_KEY;

default
{
    state_entry()
    {
        // Ask the owner for permission to debit their account
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }

    run_time_permissions (integer perm)
    {
        if  (perm & PERMISSION_DEBIT)
            DebitPerms = TRUE;
    }

    touch_start(integer num_detected)
    {
        if (!DebitPerms)
            return;  // Cannot proceed - debit permissions not granted
        if (llDetectedName(0) != Recipient)
            return;  // unauthorised person is touching - ignore
        if (TransactionID != NULL_KEY)
            return;  // waiting on previous transaction to complete/fail

        key id = llDetectedKey(0);
        TransactionID = llTransferLindenDollars(id, Amount);
    }

    transaction_result(key id, integer success, string data)
    {
        if (id != TransactionID)
            return;          // Ignore if not the expected transaction
        
        if (success)
        {
            llOwnerSay( "Transfer of L$ to " + Recipient + " was successful");
            llSleep(1.0);
            llDie();          // Die so Fred can't keep taking money
        }
        else
        {
            llOwnerSay( "Transfer of L$ failed");
            TransactionID = NULL_KEY;
            // Keep the script running so Fred can try again, clear TransactionID to allow a new attempt
        }
    }
}

Complex Examples

•  Simple Piggy Bank

Notes

  • released on main server channel on 3-Dec-2011

See Also

Events

•  run_time_permissions Permission receiving event
•  transaction_result
•  money

Functions

•  llGetPermissions Get the permissions granted
•  llGetPermissionsKey Get the agent who granted permissions
•  llRequestPermissions Request permissions
•  llGiveMoney
•  llSetPayPrice

Articles

•  Script permissions

Deep Notes

History

Date of Release 03/12/2011

Signature

function key llTransferLindenDollars( key destination, integer amount );