Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llGiveInventory script stops at 3???

Sydney Alexander
Registered User
Join date: 19 Feb 2005
Posts: 69
12-15-2005 09:21
Hello! I am usig the bellow script to "unwrap" a Christmas gift for my friends. I have to use something like this because some of the "gifts" are no mod/no copy. The below script for some reason gives the first 3 items and then has an error of:"Unable to give inventory: No item named ''. I don't see anything that is limiting the number and I have tried different items and even if they are all copy/mod I still can only give 3 items. Any help. Wish I could use llGiveInventory but that darn no copy rule... HELP!

Happy Holidays,

Sydney

CODE

// Copyright 2004, Trimming Hedges. Released to the public domain.

// This is a simple script that gives everything in a box to the person who clicked.
// By default, it will only give items to the owner of the box.

// I wrote this because of all the texture bundles that are given out. It's really a PAIN
// to move a lot of textures or other contents out of a box. This speeds that up.

// This is NOT a vending script. You can use this script to give everything in a box to someone, by changing 'owneronly' to be 0. BUT:
//
// I suggest not using this script in an area where several people are going to touch it at once, because giving inventory is slow.
// Version 2.0 of this script now detects multiple simultaneous touches: it is still slow, but it should work better at classes or events.

// THIS IS NOT A VENDING SCRIPT. It gives items away, it does NOT SELL THEM. (You don't need a script for most vending anyway.)
// This script doesn't give itself away. If you want it to, put it in the box, and set it to not running.
// Then rename a copy and put that in the box too. The renamed copy should be the running one.
// Rename it FIRST, I had weird issues with renaming it when it was already in
// the box. (version 1.2.12 of SL.)

integer owneronly = 0;
key owner;

default
{
state_entry()
{
owner = llGetOwner();
}

touch_start(integer total_number)
{
integer i;
for (i=0;i<total_number;i++)
{
key target = llDetectedKey(i);

if ( (target != owner) && (owneronly == 1) ) // person clicking isn't owner and owneronly is set;
{
llInstantMessage(target,"Sorry, only the owner is allowed to get my contents.");
return;
}
list inventory_types = [INVENTORY_BODYPART,INVENTORY_CLOTHING,INVENTORY_LA NDMARK,INVENTORY_NOTECARD,INVENTORY_OBJECT,INVENTO RY_SCRIPT,INVENTORY_SOUND,INVENTORY_TEXTURE];
integer inventory_count = llGetListLength(inventory_types);
integer j;
integer k;
integer type;
integer typecount;
string myname = llGetScriptName();
string objectname;

for (j=0; j<inventory_count;j++)
{
type = llList2Integer(inventory_types,j); // get the next inventory type from the list
typecount = llGetInventoryNumber(type); // how many of that kind of inventory is in the box?
if (typecount > 0)
{
for (k=0; k<typecount;k++)
{
objectname = llGetInventoryName(type,k);
if (objectname != myname) // don't give self out so the user doesn't get fifty thousand copies.
{
llGiveInventory(target,objectname);
}
}
}
}
}
}
}
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
12-15-2005 11:37
I know why it's stopping: as your giving the items out, the number in the contents is going down, so the typecount is invalid after the first item is given. Another thing I noticed is that it sets the owner key on state_entry, but does not reset if it's given to someone else, meaning that it still thinks it's owned the the previous person, so the owneronly option won't work. Here's a script that does the same thing, but without those two little issues:
CODE
//Gives everything in contents to whoever touches, with an owneronly option.
//Slow, but works with nocopy objects.


integer OwnerOnly = 0; //Set to 1 so only the owner can unpack

default
{
touch_start(integer total_number)
{
integer x;
for(x = 0; x < total_number; ++x)
{
key toucher = llDetectedKey(x);
if((toucher == llGetOwner()) || (OwnerOnly == 0))
{
string InvenName;
integer InvenNumber = llGetInventoryNumber(INVENTORY_ALL);
list InvenList = [];
integer y;
string ScriptName = llGetScriptName();
for(y = 0; y < InvenNumber; ++y)
{
InvenName = llGetInventoryName(INVENTORY_ALL, y);
if(InvenName != ScriptName) InvenList += [InvenName];
}
for(y = 0; y < (InvenNumber - 1); ++y)//reduce number by one since the script is not in the list
{
llGiveInventory(toucher, llList2String(InvenList,y));
}
}
}
}
}
_____________________
Sydney Alexander
Registered User
Join date: 19 Feb 2005
Posts: 69
12-16-2005 06:34
Thanks Kayla, works great! The only question/problem I am having... I am putting a little...

llOwnerSay("Happy Holidays "+name+"." Hope you have a very Merry Christmas and a Happy New Year!";);

... After the llGiveInventory(toucher, llList2String(InvenList,y)); but what is happening is that it is "looping" I think in that it gives an item from the inventory and then makes the test then gives an item and then repeats the text again. I only want the text at the end and said only once the items have all been unwrapped. I tried a few things, but I am not having much luck or time to fiddle with it, gotta love the Holidays. Anyway any help you could provide would be wonderful.

Thanks,

Sydney



From: Kayla Stonecutter
I know why it's stopping: as your giving the items out, the number in the contents is going down, so the typecount is invalid after the first item is given. Another thing I noticed is that it sets the owner key on state_entry, but does not reset if it's given to someone else, meaning that it still thinks it's owned the the previous person, so the owneronly option won't work. Here's a script that does the same thing, but without those two little issues:
CODE
//Gives everything in contents to whoever touches, with an owneronly option.
//Slow, but works with nocopy objects.


integer OwnerOnly = 0; //Set to 1 so only the owner can unpack

default
{
touch_start(integer total_number)
{
integer x;
for(x = 0; x < total_number; ++x)
{
key toucher = llDetectedKey(x);
if((toucher == llGetOwner()) || (OwnerOnly == 0))
{
string InvenName;
integer InvenNumber = llGetInventoryNumber(INVENTORY_ALL);
list InvenList = [];
integer y;
string ScriptName = llGetScriptName();
for(y = 0; y < InvenNumber; ++y)
{
InvenName = llGetInventoryName(INVENTORY_ALL, y);
if(InvenName != ScriptName) InvenList += [InvenName];
}
for(y = 0; y < (InvenNumber - 1); ++y)//reduce number by one since the script is not in the list
{
llGiveInventory(toucher, llList2String(InvenList,y));
}
}
}
}
}
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
12-16-2005 06:45
From: Sydney Alexander
Thanks Kayla, works great! The only question/problem I am having... I am putting a little...

llOwnerSay("Happy Holidays "+name+"." Hope you have a very Merry Christmas and a Happy New Year!";);

... After the llGiveInventory(toucher, llList2String(InvenList,y)); but what is happening is that it is "looping" I think in that it gives an item from the inventory and then makes the test then gives an item and then repeats the text again.


Instead of inserting this line directly after the llGiveInventory(), insert it after the following close brace symbol, so that it is not part of the for loop.
Sydney Alexander
Registered User
Join date: 19 Feb 2005
Posts: 69
12-16-2005 18:37
Opps! I could havesworn I tried that, but of course you are correct. Thank you...

Another question if I may... What about a way to make a script "sleep" until a certain date or date and time. The example would be a Christmas present that will give the owner the "gifts", but only if it is Dec. 23rd or later... Possibly a really long timer before the touch_start? Maybe it would start with an on_rez?

Thanks!

From: Yumi Murakami
Instead of inserting this line directly after the llGiveInventory(), insert it after the following close brace symbol, so that it is not part of the for loop.