Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Give all contents script

MadamG Zagato
means business
Join date: 17 Sep 2005
Posts: 1,402
02-12-2006 14:43
Something is terribly wrong with this script. It gave one of my customers 20 copies of the same item!! :eek: A free item, but how annoying. It did not give them the other free items in the prim, just 20 copies of the same thing. Can someone pleez help me decipher what is wrong with the code?

Thank ya

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 to get free gifts!",<1,1,1>,1);
llSetTouchText("Gimme");
llOwnerSay ("Touch to get free gifts!");
}
default
{
state_entry()
{
init();
}
on_rez( integer param)
{
init();
}
touch_start( integer num )
{
//////////////////////////////////////////////////////////////////
//remove these lines
// if ( llDetectedKey(0) != llGetOwner() )
// { //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 ));
}
}
}
}
_____________________
Patch Lamington
Blumfield SLuburban
Join date: 2 Nov 2005
Posts: 188
02-12-2006 15:25
Not tried in world, but from a quick scan it looks like the function get_inv_details() is run every time the item is touched, and every time it adds items to the give lists - but these lists are never cleared.

The first person to touch will get one of each item, the second two of each, then three of each, etc etc.

You could make the script a little more efficient by only calling get_inv_details when the inventory changes and when the vendor is rezzed/script initialised.
- and make get_inv_details clear the lists before it fills them!


From: MadamG Zagato

CODE

...
get_inv_details()
{
...
if ( (mask & PERM_COPY) )
{
give_in_folder = give_in_folder + [ name ]; // adds to list which is never cleared!
folder_give = TRUE;
}
else
{
give_individually = give_individually + [ name ];
item_give = TRUE;
}
}
}
_____________________
Blumfield - a regular everyday kind of 'burb in an irregular world.
This notice brought to you by the Blumfield Visitors and Residents Bureau.