Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Money Ball scripts?

a lost user
Join date: ?
Posts: ?
08-04-2005 07:53
Is there an example of a Money Ball script somewhere?

I'm sure it's pretty simple, but would be nice to see
an example as I'm starting to learn:

1) wait for a delay
2) scan area to see who's near
3) pick a random person
4) give money


Should be about it, yes?

thanks!
Padraig Stygian
The thin mick
Join date: 15 Aug 2004
Posts: 111
08-04-2005 10:03
It's not perfect, but it usually works. Adds people to the list, and after "time" seconds, picks a winner and gives them "cash" $L.

CODE

//Raffle Ball
//based on "Event Lottery" by Ama Omega
//(http://secondlife.com/badgeo/wakka.php?wakka=LibraryEventLottery)
//Modified by Padraig Stygian

//Change these to suit your event
float range = 15.0; // search radius, in meters
integer time = 600; //winner select time is in seconds. (10min)
integer cash = 20; //$L the ball gives on each pass
string text = "Mahal 80's Raffle! 20L every 10 minutes!"; //float text for the ball.

//Don't mess with these.
list names;
list keys;
integer i;
integer j;
integer count;
string name;
key nkey;
float rate = 1.0; // time between searches, in seconds

integer find(string name)
{
for (i=0;i<count;i++)
if (llList2String(names,i) == name)
return i;
return -1;
}
default
{
state_entry()
{
llSay(0,"Initialising...");
llSetText(text,<0,255,0>,1);
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
llSetTimerEvent(time);
llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
count = 0;
}
sensor(integer total_number)
{
for (j=0;j<total_number;j++)
{
//if not on the list of entrants, add to the list, and tell the owner
if (find(llDetectedName(j)) == -1)
{
name = llDetectedName(j);
nkey = llDetectedKey(j);
names += name;
keys += nkey;
llInstantMessage(llGetOwnerKey(llGetKey()), name + " has been entered.");
count++;
}
}
}

timer()
{
//Find and announce winner
names = llListRandomize(names,1);
i = llFloor(llFrand(llGetListLength(names)));
string winkey = llList2Key(keys,i);
string winner = llKey2Name(winkey);
llWhisper(0,"And the Winner is " + winner +
"! There were " + (string)count + " participants.");
//Give money to winner
llGiveMoney(winkey,cash);
//start over
llResetScript();
}
on_rez(integer st)
{
llResetScript();
}
}
_____________________
(You): Aww! My pants won't rez! Does this texture look okay on me?

Incidental Radio :: Because nothing is by design
Now featuring Torley-tastic technomusic!
Moonshine Herbst
none
Join date: 19 Jun 2004
Posts: 483
08-04-2005 11:31
Scanning the area every second is kinda overkill...
DJ Under
Pyro Island Manager
Join date: 9 Jan 2005
Posts: 55
Little help?
08-04-2005 17:13
Hey, Padraig Stygian, is there a way taht you can add OBJECTS to be givin away?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-05-2005 00:26
Yes, it's easy.

Near the bottom, in the timer event are the lines:

CODE
        //Give money to winner
llGiveMoney(winkey,cash);
//start over


After, or in place of, llGiveMoney() you need to use one of llGiveInventory or llGiveInventoryList() to give multiple items.
Padraig Stygian
The thin mick
Join date: 15 Aug 2004
Posts: 111
08-05-2005 11:49
From: Moonshine Herbst
Scanning the area every second is kinda overkill...


Ugh, yeah it is... This was the second piece of LSL I ever wrote, and I haven't actually *looked* at it since last summer...I suppose it *should* scan only once per draw. I suspect, since it resets after each draw, it would be safe to set the scanner to run at time - 10. (-10 to keep it from choking if it tries to draw and read at the same time.)

Bleah. Thanks for catching that one; I sure as hell mised it.
_____________________
(You): Aww! My pants won't rez! Does this texture look okay on me?

Incidental Radio :: Because nothing is by design
Now featuring Torley-tastic technomusic!
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
04-09-2007 09:37
This looks like a nice simple script but is there a way to allow people to change the money amounts and such without having them go into the script itself? Like for instance call a configuration note card? I want to be able to allow my friend to change it but if he looks at the code he gets a bit paranoid. lol
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
04-09-2007 09:57
To save some (well, lots) of cycles, you might change the llSensor to an llVolumeDetect approach. Then the script will not constantly be responding to sensor events when nothing has changed, whereas VolumeDetect will kick an event when someone comes into the area.

Rj
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
04-09-2007 10:28
From: RJ Source
To save some (well, lots) of cycles, you might change the llSensor to an llVolumeDetect approach. Then the script will not constantly be responding to sensor events when nothing has changed, whereas VolumeDetect will kick an event when someone comes into the area.

Rj



How would that change be made?
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
04-09-2007 10:30
Set llVolumeDetect(TRUE);

Replace the sensor event with a collision_start event.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
04-09-2007 10:46
It's a little bit of a rewrite.

llSensor gives you a sensor area around your object. llVolumeDetect doesnt work quite like that. It actually signals a collision event when something collides with a prim. So besides making the code changes, you also need to make some prims that people will walk into or thru as part of the object. (volume detect makes the object phantom). Typically you'd also use llSetAlpha to make them invisible too. Or at least the prims you want to use as the collision parts.

Rj
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-09-2007 11:34
In a similar vein to RJ's suggestion make ita touch opt-in item.

As for adding notecard support an example was recently posted here
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
04-09-2007 17:39
I figured I would try out the script and for some reason if the person leaves the area all together it still pays them. like it follows them somehow
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-10-2007 00:09
From: Dioxide DeSantis
I figured I would try out the script and for some reason if the person leaves the area all together it still pays them. like it follows them somehow


The script is remembering their key. What you need to do is prior to paying them do a single sensor scan for their key, if it finds them great pay up, if not choose another winner.

Going back to your previous post concerning adding objects as a payout instead of money taek a look at the Prize Chair we made a while ago.