// 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.
}
}
}
Examples |
money() |
llGiveMoney