Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Random prize give script?

Belle Loll
Registered User
Join date: 7 Dec 2006
Posts: 260
02-08-2010 15:39
I have been asked to make a King Cake for a Mardi Gras party and while I have a slice of cake giver ...I cannot figure out how I can give the baby that is inside the cake every once in a while. Anyone have any ideas?

I'm going to miss this scripting forum sooooo much!!!! :(
_____________________
All people smile in the same language
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-08-2010 15:55
Try this .... (untested, but plausible) :)

CODE

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

timer()
{
llSensor("","",AGENT,20.0,PI); //Scan for avs within 20m
llSetTimerEvent(llFrand(240) + 60); //Pick a random time between 1 and 5 minutes
}

sensor(integer num)
{
key Av = llDetectedKey((integer)llFrand(num)); //Pick a random av within sensor range
llGiveInventory(Av,(llGetInventoryName(INVENTORY_OBJECT,0)));
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
02-08-2010 16:10
CODE

default{
touch_start(integer n){
if ((integer)llFrand(3) == TRUE){
//There is a 1 in 3 chance you will give a baby in this example.
llOwnerSay("Give the baby");
}
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-08-2010 16:28
OK, here's a fancier version of the one I posted earlier. When the sensor fires at a random time (between 1 and 5 minute) it checks to see whether the randomly detected person has received the prize before. If not, it awards the prize. If so, it quickly scans again to find a valid awardee. To keep things interesting, once the prize has been awarded ten times, the script randomly removes one of the previous winners from the list.

CODE

list awarded = [];

integer isNameOnList( list list_name, string name )
{
integer len = llGetListLength( list_name );
integer i;
for( i = 0; i < len; i++ )
{
if( llList2String(list_name, i) == name )
{
return TRUE;
}
}
return FALSE;
}

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

timer()
{
llSensor("","",AGENT,20.0,PI); //Scan for avs within 20m
}

sensor(integer num)
{
integer count = (integer)llFrand((float)num);
key Av = llDetectedKey(count); //Pick a random av within sensor range
if(isNameOnList(awarded,Av) == FALSE) //Check to se if selected av has won before
{
llGiveInventory(Av,(llGetInventoryName(INVENTORY_OBJECT,0)));
awarded += Av;
if (llGetListLength(awarded) >= 10) //If 10 prizes have been awarded...
{
integer temp = (integer)llFrand(10);
awarded = llDeleteSubList(awarded,temp,temp); //Remove a random name from the list of previous winners.
llSetTimerEvent(llFrand(300) - 60); //Pick a random time between 1 and 5 minutes
}
}
else
{
llSetTimerEvent(5); //Scan again
}
}
}


/me watches the countdown to forum demise. I feel like Nero fiddling while Rome burns.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Belle Loll
Registered User
Join date: 7 Dec 2006
Posts: 260
02-08-2010 17:36
YOu guys are the BOMB!!! I will try both of them...

THANK YOU!!!
_____________________
All people smile in the same language
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-09-2010 06:32
::expands Jesse's Idea just a bit for fun::

CODE

list gLstItem = ["baby", "cake"];

default{
touch_end( integer vIntTch ){
do{
llGiveInventory( llDetectedKey( --vIntTch ),
llList2String( gLstItem, -((integer)llFrand( 8 )) >> 31 ) );
}while (vIntTch);
}
}


(integer)llFrand( 8 ) == random number from 0 to 7

-(#) >> 31 == "0" 1 of 8 times, "-1", 7 of 8 times

another way, with only one baby in the cake....

CODE

integer gIntCnt;

default{
touch_end( vIntTch ){
do{
llGiveInventory( llDetectedKey( --vIntTch ), "cake" );
if (8 == ++gIntCnt){ //-- 8th piece gives baby
//-- remove previous line and uncomment the next line for a different action
// if (!((integer)llFRand(++gIntCnt))){ //-- more babies to start, less frequent later on
llGiveInventory( llDetectedKey( vIntTch ), "baby" );
}
}while (vIntTch);
}
}


or


CODE

integer gIntCnt = 100;

default{
touch_end( vIntTch ){
do{
llGiveInventory( llDetectedKey( --vIntTch ), "cake" );
//-- more chances of babies as the night goes on untill 100 pieces given
if ((integer)llFRand( -(gIntCnt < 1) | --gIntCnt )){
llGiveInventory( llDetectedKey( vIntTch ), "baby" );
}
}while (vIntTch);
}
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-09-2010 08:23
Or, for a truly random experience, combine methods to check for a random av within range of the sensor at a random time between 1 and 5 minutes and offer a prize which, using one of your algorithms, will usually be a slice of cake but MIGHT be a baby. The mind fairly boggles, as Bertie Wooster would have said. ;)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at