miércoles, 9 de marzo de 2011

creating your Bank Script

// To deposit money into the bank, just pay the prim you put the script in.
// To withdraw money, click the prim.
 // Retrieved from Free SL Scripts on www.gendersquare.org/sl
// Since it's now super-easy to create your own alt, people all over have made alts just to carry around cash. Which make tools like the Alt Vault and the Personal ATM really really great to have, however, there is a catch. Tools like the Alt Vault and the Personal ATM cost money. After buying all of them and feeling sad about every single one of them, I decided to make my own. And now I give it to you, because I am too damn lazy to set up a vendor for this stuff.
// First, you should find out the key of your main character. To do this, click a box that contains this one liner script: default{touch_start(integer q){llSay(0,(string)llDetectedKey(0));}}
Now that you got your main key, log in as your alt, and take this script:
// A FREAKING BANK OMG; v1.1.1 by Deight Boccara
// Let's initialize some global variables! Whoohoo! Exciting!
integer cash;
key whosOn;
// This function is called whenever we want to know how much cash is left.
// By default, we just IM the user, but we can use floating text and can
// email people just by uncommenting things
howMuchLeft()
{
llInstantMessage(whosOn, "I now have L$" + (string)cash);
//llSetText("L$" + (string)cash, <0,1,0>, 1);
//llEmail("user@example.org", "SL Bank Activity: " + llGetDate(),
// "I now have L$" + (string)cash);
}
// This function is called to see if the user has permission to do stuff.
// Adding people is easy, just use a "boolean or" to check if the id equals
// the authorized people's keys. To find out your key, use
// llSay(0,(string)llGetOwner());, or check [url]http://w-hat.com/name2key[/url]
integer isAllowed(key id)
{
if (id == "7cd4e362-3df8-ed6c-f74d-994d24f14664") // replace this with your avatar key
return TRUE;
else
return FALSE;
}
// When we start, we ask the owner if we can pay people money. Again and again. Until they say yes. When they do, we switch to the "deposit" state.
default
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
}
run_time_permissions(integer perm)
{
if (perm == PERMISSION_DEBIT)
state deposit;
else
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
}
}
// The Deposit State. Here (only authorized) people can deposit money via the normal Pay function, or (if they are authorized) they can simply touch the bank to shift into withdrawl mode.
state deposit
{
money(key id, integer amt)
{
if (isAllowed(id))
{
whosOn = id;
cash += amt;
howMuchLeft();
}
else
{
llGiveMoney(id, amt);
}
}
touch_start(integer total_number)
{
if (isAllowed(llDetectedKey(0)))
{
whosOn = llDetectedKey(0);
state withdraw;
}
}
}

// The Withdrawl State. Here, whoever was authorized to click gets their own
// private (random) listener. They then have 60 seconds to say how much they
// want to withdraw on that listener (for example, "/743 5" will get you
// L$5). If they type in a weird value or take too long, we go back to the
// Deposit State.
state withdraw
{
state_entry()
{
integer randChan = (integer)(llFrand(899)+100);
llInstantMessage(whosOn, "Type how much to withdraw on" +
"channel /" + (string)randChan + "; I now have L$" +
(string)cash);
llListen(randChan, "", whosOn, "");
llSetTimerEvent(60);
}
listen(integer chan, string name, key id, string msg)
{
integer amt = llRound((integer)msg);
integer difference = cash - amt;
if (difference >= 0 && amt > 0)
{
cash -= (integer)amt;
llGiveMoney(id, amt);
howMuchLeft();
state deposit;
}
else
{
llInstantMessage(whosOn, "Try again, but with a sane value");
state deposit;
}
}
timer()
{
llInstantMessage(whosOn, "TIMES UP");
state deposit;
}
}

// SOME LEGAL STUFF:
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source
// distribution.
// To deposit money into the bank, just pay the prim you put the script in.
// To withdraw, click the prim. Now, it will tell you a random channel like /471. Type in /471, then the number of dollars you want. Like, if you want 250 dollars, that would be "/471 250".