Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Give all Contents script is giving out 4 copies of everything

ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
07-15-2007 13:03
This script is from a box of freebies, it is supposed to give the box owner all of the contents of the box, but its is giving out 4 copies of everything. I can't see what the problem is. Any suggestions??


CODE


list give_in_folder;
list give_individually;
integer item_no;
string name;
integer folder_give = FALSE;
integer item_give = FALSE;

get_inv_details()
{
name = llGetInventoryName( INVENTORY_ALL, item_no );
if ( name != llGetScriptName() )
{
integer mask = llGetInventoryPermMask(name, MASK_OWNER);
if ( (mask & PERM_COPY) )
{
give_in_folder = give_in_folder + [ name ];
folder_give = TRUE;
}
else
{
give_individually = give_individually + [ name ];
item_give = TRUE;
}
}
}
init()
{
llSetText( "Touch for contents",<1,1,1>,1);
llSetTouchText("gimme");
llOwnerSay (" Touch to receive contents");
}
default
{
state_entry()
{
init();
}
on_rez( integer param)
{
init();
}
touch_start( integer num )
{
//////////////////////////////////////////////////////////////////
if ( llDetectedKey(0) != llGetOwner() ) //remove these lines
{ //to allow anyone to
llOwnerSay ("only the owner can empty this box"); //get the contents
return; // of the
} //box
////////////////////////////////////////////////////////////////
item_no = 0;
for ( item_no= 0 ; item_no < llGetInventoryNumber( INVENTORY_ALL ) ;item_no++ )
{
get_inv_details();
}
if ( folder_give )
{
llGiveInventoryList ( llDetectedKey(0), llGetObjectName(), give_in_folder );
}
if ( item_give )
{
integer i;
for ( i=0 ; i<llGetListLength( give_individually ) ; i++ )
{
llGiveInventory( llDetectedKey(0),llList2String( give_individually, i ));
}
}
}
}
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
07-15-2007 13:25
I guess, this is because the lists with the items never gets initialized. Thus, everytime you run the script, the lists with the items add up...


change the init()-function from this:

init()
{
llSetText( "Touch for contents",<1,1,1>,1);
llSetTouchText("gimme";);
llOwnerSay (" Touch to receive contents";);
}


to this:

init()
{
llSetText( "Touch for contents",<1,1,1>,1);
llSetTouchText("gimme";);
llOwnerSay (" Touch to receive contents";);
give_in_folder = []; // reset the list
give_individually = []; // reset the list
}