A B C D E F G I J K L M N O R S T U V W

money(key id, integer amount)

This event is triggered when the agent with the key id gives amount of Linden Dollars to the object.

The existence of a money event (even an empty one) in the current state enables the “Pay” entry in the PieMenu when right-clicking the object and allows users to pay the object’s owner. Note that this gives you control of when the “Pay” entry is shown, by switching between states with and without a money event handler.

The amount is chosen via an input field by the giver, or by the amounts specified in the “Fast Pay” buttons (to customize the values of these, use llSetPayPrice).

If the object is deeded to a group, the group receives the money.

Example:

default {
    money(key giver, integer amount) {
        llSay(0, "Thanks for the " + (string)amount + "L$, " + llKey2Name(giver));
    }
}

Longer Example:

// ExampleMoney
// Pay the object money, this script refunds incorrect payments
// This code is public domain.

integer gCorrectAmount = 10; // this defines the correct price -- we only accept L$10

default
{
    state_entry()
    {
        // get permission from the owner to pay out money using the llGiveMoney function.
        llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
    }
     
    money(key id, integer amount)
    {
        // has the user paid the correct amount?
        if (amount == gCorrectAmount)
        {
            // if so, thank the payer by name.
            llSay(0,"Thank you, " + llKey2Name(id) + ".");
        }
        
        // is the amount paid less than it needs to be?
        else if (amount < gCorrectAmount)
        {
            // if so, tell them they're getting a refund, then refund their money.
            llSay(0,"You didn't pay enough, " + llKey2Name(id) + ". Refunding your payment of L$" + (string)amount + ".");
            llGiveMoney(id, amount); // refund amount paid.
        }
        
        // if it's not exactly the amount required, and it's not less than the amount required,
        // the payer has paid too much.
        else
        {
            // tell them they've overpaid.
            integer refund = amount - gCorrectAmount; // determine how much extra they've paid.
            llSay(0,"You paid too much, " + llKey2Name(id) + ". Your change is L$" + (string)refund + ".");
            llGiveMoney(id, refund); // refund their change.
        }
    }
}

Notes:

  • Under some circumstances, a linked object may display the “Pay” option in the pie menu for other prims, even when the script containing the money event has moved to a different state. This is an old bug, but it’s not clear on how to predict when this will happen. To avoid this sort of problem, use a single state in the payment script and simply refund the money when the object would otherwise have switched into another state. (See this thread for more.)
  • Money cannot be paid to an attachment; while there is a “Pay” option on the pie menu, paying money to an attachment will not cause the money() event to be triggered.

 

Q: Someone said they paid my object, but they didn’t get anything. I see the transaction in my account’s transaction history, though. What gives?
A: Under high database or sim load, there appears to be a bug where the money event is not triggered. The Lindens are aware of the problem, but there’s not yet any word on a fix. In the meantime, it can help to add a list to your script containing a log of users (using llKey2Name) to pay your object money (from the script’s perspective, at least, meaning the money event was triggered) and the time at which they paid. Then, if you receive a complaint, you can easily check against your log to see if the customer is telling the truth.

 

Q: Is there a way to find out when money is paid into a user’s account?
A: No, the money() event can only be triggered when money is paid directly to the object containing the money() event. There is no way for an LSL script to check a user’s money, nor be triggered when it changes.
In theory, one could run a script on an external server that parsed the contents of the SL Account page on the SL website, then coordinated payment data with scripts in SL. This would naturally depend on several factors, such as the rate at which the SL Account page is actually updated, the amount of transactions from different sources you’re likely to have, and of course, how much the Lindens do or do not want your bot to hammer their server.

To give money via a script, use the llGiveMoney function.