Difference between revisions of "Personal ATM Machine"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
I made this script to allow me to store my Lindens in another account, in order to stop me from spending them so carelessly. Others may find it useful.
<source lang="lsl2">
// ATM Machine script, Jessikiti Nikitin 2010
// ATM Machine script, Jessikiti Nikitin 2010
//
// Brief instructions for use:
//
// Give this script to your alt, ensuring their balance is L$0 (or setting the balance in the variable below),
// put it in an object and then allow debit permissions when the object requests them.
//
// You can then manage your alt's balance using the object, without the alt having to be logged in.
// To deposit lindens, pay the object. To withdraw lindens, touch the object for a menu.


Brief instructions for use:
key managerKey = "00000000-0000-0000-0000-000000000000"; // change this to your main avatar's key


Give this script to your alt, ensuring their balance is L$0 (or setting the balance in the variable below then allow debit permissions when the object requests them.
You can then manage your alt's balance using the object, without the alt having to be logged in. To deposit lindens, pay the object. To withdraw lindens, touch the object for a menu.
<lsl>
key managerKey = "00000000-0000-0000-0000-000000000000"; // change this to your main avatar's key
list dialogAmounts = ["50", "100", "250", "500", "1000", "5000", "10000", "50000", "All"];
list dialogAmounts = ["50", "100", "250", "500", "1000", "5000", "10000", "50000", "All"];
integer balance = 0;
integer balance = 0;
Line 20: Line 25:
     opChannel = llFloor((llFrand(1000000) * -1)-1000000);  // creates random operation channel to
     opChannel = llFloor((llFrand(1000000) * -1)-1000000);  // creates random operation channel to
                                                             // prevent spying on withdrawal amounts
                                                             // prevent spying on withdrawal amounts
                                                           
     listenHandle = llListen(opChannel, "", managerKey, "");
     listenHandle = llListen(opChannel, "", managerKey, "");
    llSetColor(<1,0.4,0.4>, ALL_SIDES);
     llSetTimerEvent(60);
     llSetTimerEvent(60);
     llDialog(managerKey, "Balance: L$"+(string)balance+"\n \nChoose amaount to withdraw.", validAmounts(), opChannel);
     llDialog(managerKey, "Balance: L$"+(string)balance+"\n \nChoose amount to withdraw.", validAmounts(), opChannel);
}
}


Line 47: Line 50:
     llListenRemove(listenHandle);
     llListenRemove(listenHandle);
     llSetTimerEvent(0);
     llSetTimerEvent(0);
    llSetColor(<1,1,1>, ALL_SIDES);
}
}


Line 107: Line 109:
     }
     }
}
}
</lsl>
</source>
{{LSLC|Library}}
{{LSLC|Library}}

Latest revision as of 01:27, 22 January 2015

I made this script to allow me to store my Lindens in another account, in order to stop me from spending them so carelessly. Others may find it useful.

// ATM Machine script, Jessikiti Nikitin 2010
//
// Brief instructions for use:
//
// Give this script to your alt, ensuring their balance is L$0 (or setting the balance in the variable below),
// put it in an object and then allow debit permissions when the object requests them.
//
// You can then manage your alt's balance using the object, without the alt having to be logged in.
// To deposit lindens, pay the object. To withdraw lindens, touch the object for a menu.

key managerKey = "00000000-0000-0000-0000-000000000000"; // change this to your main avatar's key

list dialogAmounts = ["50", "100", "250", "500", "1000", "5000", "10000", "50000", "All"];
integer balance = 0;

integer opChannel;
integer listenHandle;

presentDialog()
{
    opChannel = llFloor((llFrand(1000000) * -1)-1000000);   // creates random operation channel to
                                                            // prevent spying on withdrawal amounts
    listenHandle = llListen(opChannel, "", managerKey, "");
    llSetTimerEvent(60);
    llDialog(managerKey, "Balance: L$"+(string)balance+"\n \nChoose amount to withdraw.", validAmounts(), opChannel);
}

list validAmounts()
{
    // this function prevents the script offering money that isn't available,
    // which would result in a silent failure
    list va;
    integer i;
    for(;i<llGetListLength(dialogAmounts);++i)
    {
        if((integer)llList2String(dialogAmounts,i)<=balance)
        {
            va+=llList2String(dialogAmounts,i);
        }
    }
    return va;
}

removeListens()
{
    llListenRemove(listenHandle);
    llSetTimerEvent(0);
}

default
{
    on_rez(integer omitted){ llResetScript(); }
    
    state_entry()
    {
        opChannel = llFloor((llFrand(1000000) * -1)-1000000);
        llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
    }
    
    touch_start(integer number_detected)
    {
        integer n;
        for(;n<number_detected;++n)
        {
            if(llDetectedKey(n)==managerKey)
            {
                if(balance==0)llDialog(managerKey, "Balance: L$0", [], opChannel);
                else
                {
                    presentDialog();
                }
            }
        }
    }
    
    listen( integer channel, string name, key id, string message )
    {
        removeListens();
        integer amountToGive = (integer)message;
        if(message == "All")amountToGive = balance;
        llGiveMoney(managerKey, amountToGive);
        balance -= amountToGive;
        llInstantMessage(managerKey, "New balance = L$"+(string)balance);
    }
    
    money(key id, integer amount)
    {
        if(id == managerKey) // only display balance if money came from you
        {
            balance += amount;
            llInstantMessage(managerKey, "New balance = L$"+(string)balance);
        }
        else    // remove this else block if you want to allow other people
                // to put money into your safe
        {
            llGiveMoney(id, amount);
            llInstantMessage(id, "You are not the owner of this safe.");
        }
    }
    
    timer()
    {
        llInstantMessage(managerKey, "timed out");
        removeListens();
    }
}