Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

a "smart" money ball....

Zaid Vox
Registered User
Join date: 9 Apr 2005
Posts: 66
05-21-2005 12:52
OK I would like to make a money ball that gives away money when some one clicks on it. But only once per person.... Ex. Mary Vox clicks on the ball and the money ball gives her L$30 and says "Hi Mary Vox heres your L$30...go have fun!" ....Mary Vox stands there for a moment and clicks on the money ball again, but this time the ball says "Sorry, Mary Vox I can't give you any more money, come back tomorrow."
See the Money ball would be like a door greeter but keeping track of who received money and new people that have not received money....is this possible?
Kali Dougall
Purple and Spikey
Join date: 5 Feb 2005
Posts: 98
05-21-2005 15:54
Oh, sure, anything is possible with the magic of lists (unless it's something that requires an array).

Declare this:
CODE
list recipients = [];


And check for this at the start of your touch event:
CODE
if (llListFindList(recipients, [llDetectedKey(0)]) != -1) {
llSay(0, "Sorry, " + llDetectedName(0) + ", I can't give you any more money, come back tomorrow.");
return;
}


Then do this when you give out money in your touch event:
CODE
recipients = recipients + [llDetectedKey(0)];


You'll probably also want to let the owner clear the list (setting it = [] again), or you can just reset the script to clear it.
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
05-21-2005 16:30
Yes, that looks about right. Perhaps add in this code shard...

CODE

default
{
state_entry()
{
llSetTimerEvent( 60 * 60 * 24 ) ; //Reset once a day (60 seconds, 60 minutes, 24 hours)
}
timer()
{
recipients = [];
}
}


So that it resets once every 24 hours
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
05-21-2005 16:33
To finish off, here's a quick and dirty way to get it to reset itself within a few minutes of every midnight, so that you don't have to travel to the site:

1. Put this up at the top of the script, outside of any events:

CODE

string today;


2. Fire this statement in your default state's state_entry() event:

CODE

today = llGetDate();


3. In whatever state you're using to give the money out, add this to state_entry();

CODE

//
// Is reset within 5 minutes of midnight close enough? You don't want to fire
// this every 10 seconds all day long, just waiting for Reset Time...actually,
// if we took the time, we could come up with Better Citizen's Code all the way
// around on this part, but this'll work for starters:
//

llSetTimerEvent( 300.0 ); // edit to tweak # of seconds between clock-check


4. Then, add a timer event in the money-giving state:

CODE

timer() {
string date_check = llGetDate();
if ( date_check != today ) {
today = date_check;
recipients = [];
}
}


-- jj
Synergy Belvedere
Prim Reaper
Join date: 7 Jul 2004
Posts: 253
05-23-2005 10:12
And let me know where this will be so I can come buy at one minute before midnight, get $30, then wait a minute & get another $30. This pays more than my lousy weekly stipend! woot! lol :D
_____________________
----------------------------------------------------------
--The mind's eye is limited only by its focus--
Jaynius Shaftoe
Automated User
Join date: 9 Jan 2005
Posts: 29
05-23-2005 14:03
From: Synergy Belvedere
And let me know where this will be so I can come buy at one minute before midnight, get $30, then wait a minute & get another $30. This pays more than my lousy weekly stipend! woot! lol :D



So instead of coming every day for $30 you'll come every 2 days for $60.
Zaid Vox
Registered User
Join date: 9 Apr 2005
Posts: 66
05-24-2005 05:50
Sorry kids ...it will only be on for events.... :D
Luke Ramona
Registered User
Join date: 3 Apr 2005
Posts: 32
05-24-2005 10:27
Something I have been meaning to ask about the llSetTimerEvent() function and Timer() events. Is it possible to have more than one in the same script? May be I am just looking at it wrong and can't see how to do it.. I haven't even begun to work with different "states".. though I do use a lot of user defined functions. If I use different states, can I have multiple timers in the same script then? and how about having multiple timer events within the same state?

As I see it.. it doesn't seem possible:

CODE

default
{
state_entry()
{
llSetTimerEvent(10);
}

timer()
{
llSay("10 seconds have passed.");
}
}


The timer() event sits within the default (main) block. If I try to place the timer() event in a user defined function it gets a compilation error.. so even if I did use other states, I'd still have to use the timer() event in the default block, correct?
Zindorf Yossarian
Master of Disaster
Join date: 9 Mar 2004
Posts: 160
05-24-2005 13:02
You can only have one timer() event per state, but you can add multiple states. Of course, a timer event will only function for the state that you are in, so you can't have two timer events running at the same time. You can switch between states with different timers, but I can't see why you would really want to do that. you could always just change the llSetTimerEvent() instead. In fact, I'm really not sure why you would want two timer events running in parallel at all. Could you explain?
_____________________
Badass Ninja Penguin: Killing stuff it doesn't like since sometime in May 2004.
Ritz Pinkerton
Builder/Scripter
Join date: 27 Mar 2005
Posts: 22
06-05-2005 02:51
couple weeks have gone by.. but.. I'll add some...

you could have an if statement in your timer() with a variable set to true or false, and use the timer for different events inside the same state.. and if you need two at the same time.. set the timer for the shorter of the two timers, increment it however many times you need to get to the longer timer, and once it gets to a certain number, execute that timer... if that makes sense.. example below.

CODE
integer touched=FALSE;
default
{
state_entry()
{
llSetTimerEvent(10);
}
timer()
{
if (touched)
{
<execute some stuff>
}
else <execute some other stuff>
}
touch_start(integer n)
{
touched=TRUE;
}
}

and..
CODE
state_entry()
{
llSetTimerEvent(3);
}
timer()
{
x++;
if (x==10)
{
x=0;
<execute 30 second timer event>
}
else
{
<execute 3 second timer event>
}
}