Difference between revisions of "Money"

From Second Life Wiki
Jump to navigation Jump to search
m
(Provide more basic examples. modified warning.)
Line 1: Line 1:
{{LSL_Event
{{LSL_Event
|inject-1={{LSL_Function/warning|Security|'''Always (''ALWAYS!'') check the amount paid in your money() event. Preconfigured payment amounts from [[llSetPayPrice]]() are only a suggestion to the client. The client can still send L$0 or any positive integer. ''Never'' trust the client software to be secure.'''}}
|inject-1={{LSL_Function/warning|Security|'''When writing a vendor, Always (''ALWAYS!'') check the amount paid in your money() event. Preconfigured payment amounts from [[llSetPayPrice]]() are only a suggestion to the client. The client can still send L$0 or any positive integer. ''Never'' trust the client software to be secure. This is not important, of course, for a simple tipjar'''}}
|event_id=20
|event_id=20
|event_delay
|event_delay
Line 15: Line 15:
* Money cannot be paid to an attachment.
* Money cannot be paid to an attachment.
|examples=
|examples=
This example shows the simplest tip-jar and shows how little code is needed to receive unverified amounts of money.
<lsl>
default
{
    money(key id, integer amount)      // Some money has been received (and has been paid into the owner's account)
    {
        // Thank the giver for their tip
        llInstantMessage(id, "Thanks for the L$"  + (string) amount + " tip!");
    }
}
</lsl>
Next level of tip jar, advising owner, keeping a running total, and with floating text to show status.
<lsl>
integer Total;
string  OwnerName;
default
{
    on_rez( integer sparam )
    {
        llResetScript();
    }
    state_entry()
    {
        OwnerName = llKey2Name( llGetOwner() );
        llSetText( OwnerName + "'s Tip Jar.\nAny tips gratefully received!\nL$0 Donated so far", <.2, 1, .6>, 1);
    }
    money(key id, integer amount)
    {
        Total += amount;
        // Shortcut 'cheat' to avoid multiple casts when constructing a message including non-string items
        string str = (string) [OwnerName, "'s Tip Jar.\nPlease tip if you are so inclined!\n$L", amount, " Was donated last!\n$L", Total, " Donated so far" ];
        llSetText(str, <1,1,1>, 1);
        //llSetText( OwnerName + "'s Tip Jar.\nPlease tip if you are so inclined!\n$L" + (string)amount + " Was donated last!\n" + "L$" + (string)totaldonated + " Donated so far",<.25,1,.65>,1);
        llInstantMessage(id,"Thanks for the tip!");
        llInstantMessage(llGetOwner(), llKey2Name(id) + " donated L$" + (string) amount );
    }
}
</lsl>
This example verifies the amount received (but without giving the user a clue as to the expected amount. Oh, and it doesn't actually work).
<lsl>
<lsl>
integer price = 10;
integer price = 10;

Revision as of 09:57, 12 January 2013

Emblem-important-red.png Security Warning!

When writing a vendor, Always (ALWAYS!) check the amount paid in your money() event. Preconfigured payment amounts from llSetPayPrice() are only a suggestion to the client. The client can still send L$0 or any positive integer. Never trust the client software to be secure. This is not important, of course, for a simple tipjar

Description

Event: money( key id, integer amount ){ ; }

Triggered when money is paid to the prim in the amount by id.

• key id who paid
• integer amount the amount paid

Specification

When money is paid to the prim, the money is given to the object's owner.
If the object is owned by or deeded to a group it is divvied up amongst the group members immediately (which is why groups can't grant PERMISSION_DEBIT). Only members of a role that has the "Accounting/Pay group liabilities and receive group dividends" attribute will receive money.
Don't forget to turn on the pay-behavior of the prims/objects involved.
The pay buttons should be configured in most applications where money is being transfered (llSetPayPrice), it makes paying money to the object easier.

Caveats

  • This event cannot be triggered by a call to llGiveMoney because llGiveMoney cannot be used by one object to pay another object.
  • Money cannot be paid to an attachment.


Examples

This example shows the simplest tip-jar and shows how little code is needed to receive unverified amounts of money. <lsl>

default {

   money(key id, integer amount)      // Some money has been received (and has been paid into the owner's account) 
   {
       // Thank the giver for their tip
       llInstantMessage(id, "Thanks for the L$"  + (string) amount + " tip!");
   }

} </lsl> Next level of tip jar, advising owner, keeping a running total, and with floating text to show status. <lsl> integer Total; string OwnerName;

default {

   on_rez( integer sparam )
   {
       llResetScript();
   }
   state_entry()
   {
       OwnerName = llKey2Name( llGetOwner() );
       llSetText( OwnerName + "'s Tip Jar.\nAny tips gratefully received!\nL$0 Donated so far", <.2, 1, .6>, 1);
   }
   money(key id, integer amount)
   {
       Total += amount;
       // Shortcut 'cheat' to avoid multiple casts when constructing a message including non-string items
       string str = (string) [OwnerName, "'s Tip Jar.\nPlease tip if you are so inclined!\n$L", amount, " Was donated last!\n$L", Total, " Donated so far" ];
       llSetText(str, <1,1,1>, 1);
       //llSetText( OwnerName + "'s Tip Jar.\nPlease tip if you are so inclined!\n$L" + (string)amount + " Was donated last!\n" + "L$" + (string)totaldonated + " Donated so far",<.25,1,.65>,1);
       llInstantMessage(id,"Thanks for the tip!");
       llInstantMessage(llGetOwner(), llKey2Name(id) + " donated L$" + (string) amount );
   }

} </lsl> This example verifies the amount received (but without giving the user a clue as to the expected amount. Oh, and it doesn't actually work). <lsl> integer price = 10;

default {

   state_entry()
   {
       llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
       key owner = llGetOwner();
       llRequestPermissions(owner, PERMISSION_DEBIT);
   }
   money(key id, integer amount)
   {
       if (amount == price)
       {
           llInstantMessage(id, "You paid " + (string)price + " L$.");
           return;
       }
       key owner = llGetOwner();
       key permKey = llGetPermissionsKey();
       integer perm = llGetPermissions();
       if (permKey != owner)
           return;
       if (!(perm & PERMISSION_DEBIT))
           return;
       if (amount < price)
       {
           llInstantMessage(id, "That's not enough money.");
           llGiveMoney(id, amount);
       }
       else if (price < amount)
       {
           integer change = amount - price;
           llInstantMessage(id, "You paid more than " + (string)price + " L$, "
                               + "your change is " + (string)change + " L$.");
           llGiveMoney(id, change);
       }
   }
   run_time_permissions(integer perm)
   {
       if(perm & PERMISSION_DEBIT)
           llOwnerSay("Setup complete");
   }

} </lsl>

See Also

Functions

•  llGiveMoney Give money to another avatar
•  llSetPayPrice Configure the pay buttons

Deep Notes

Signature

event void money( key id, integer amount );