|
gonkerplumb Flanagan
Landscape Designer
Join date: 6 Feb 2007
Posts: 20
|
02-20-2008 10:09
Hi all Well this is driving me to despair! I am sure that its a very simple fix but I just cannot get it at the moment, Its been a hectic week here. The project is to get a script that will on touch give 3 randomly selected items from the prims inventory to the toucher in a folder named 'text' as per the script. I have the random part sorted, but i cannot get it to remove duplicates from the selection. The inventory items are currently named object1 through object5. Here is the code:
default { on_rez(integer start_param) { llResetScript(); } touch_start(integer total_number) {
list inventory; string name; integer num = 3; string text = llGetObjectName(); integer i; for (i = 0; i <= num; ++i) { name = llGetInventoryName(INVENTORY_ALL, (integer)(llFrand(1) * 5)); if(llGetInventoryPermMask(name, MASK_NEXT) & PERM_COPY) inventory += name; else llOwnerSay("Cannot give asset \""+name+"\", owner lacks copy permission"); } //we don't want to give them this script i = llListFindList(inventory, [llGetScriptName()]); inventory = llDeleteSubList(inventory, i, i); if (llGetListLength(inventory) < 1) llSay(0, "No items to offer."); else { llGiveInventoryList(llGetOwner(), text, inventory); } } }
please help!!
_____________________
You will be delighted and enchanted with your garden, when you garden with Gonks!
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-20-2008 11:06
I'd suggest may either removing elements from the list before selecting the next one, or simply using llListRandomize() and then grabbing the first (or last; whatever) N items. http://www.lslwiki.net/lslwiki/wakka.php?wakka=llListRandomize
|
|
gonkerplumb Flanagan
Landscape Designer
Join date: 6 Feb 2007
Posts: 20
|
02-20-2008 13:59
Hi
Thanks for the reply. Yes I thought about removing part of the list before selecting the next item, b ut im buggared if i can work that bit out!!!
Any direct clues or solutions!!
Cheers
_____________________
You will be delighted and enchanted with your garden, when you garden with Gonks!
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-20-2008 14:49
just insert this in your give inventory list call
//-- returns a list of 3 random items from the master list llList2List( llListRandomize( master_item_list, 1 ), 0, 2 );
_____________________
| | . "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... | - 
|
|
gonkerplumb Flanagan
Landscape Designer
Join date: 6 Feb 2007
Posts: 20
|
02-20-2008 15:17
thanks for that Void!
Listen im probably just being a bit n00bish but I cant get that to work either!
Can you explain exactly where to put it (polite answers only!)
I am still getting duplicates in the folder that is given out?
Would it be easier to just use llListFindList to search for the latest entry then remove it if it matches one already in the list? If so then any clues how to do that would be great!
Thanks in advance
Gonks
_____________________
You will be delighted and enchanted with your garden, when you garden with Gonks!
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-20-2008 15:56
Try (warning: hasn't been compiled yet; might need some minor syntax fixes): integer N_TO_GIVE = 3;
integer nInventory = llGetInventoryNumber(INVENTORY_ALL); integer nToGive = N_TO_GIVE; if (nToGive >= nInventory) { nToGive = nInventory-1; // Don't include this script }
list inventory = []; integer i; string thisScript = llGetScriptName(); for (i = 0; i < nInventory; ++i) { string item = llGetInventoryName(INVENTORY_ALL, i); if (item != thisScript) { inventory=(inventory=[])+inventory+[ item ]; } }
inventory = llList2List(llListRandomize(list, 1), 0, nToGive-1);
llGiveInventory(..., inventory);
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-20-2008 16:26
if using that instead of 'inventory' in your llGiveInventoryList call gives you duplicates, then you have duplicates in the master list... the script probably shouldn't remake the list every time, and certainly shouldn't limit itself to 3 items in the list (or you'll always get the first three), randomizing the index for the first 5 (assuming there's 5 in there, not more or less) doesn't help because the random number might repeat (good likelyhood with only 5 choices) and that's where you're getting your duplicates at. you want to build the list once, and then rebuild it only if your inventory changes... list gLstInventory; string gStrFolder;
fBuildInventory(){ //-- clear list in case items are removed and so we don't duplicate items gLstInventory = []; string vStrName; //-- get all possible items in the prims inventory integer vIntIndex = lllGetInventoryNumber( INVENTORY_ALL ); do{ vStrName = llGetInventoryName( INVENTORY_ALL, --vIntIndex ); if (llGetInventoryPermMask( vStrName, MASK_OWNER) & (PERM_COPY | PERM_TRANSFER)){ //-- only add items that can be transfered AND copied, as give inv. list requires gLstInventory += (list); }else{ llOwnerSay( "Skipping item '" + vStrName + "': must have Copy & Transfer permissions" ); } }while (vIntIndex);
//-- don't assume this script is in the list, it won't be if current owner //-- can't copy or trans it. if we assume it is, and it's not, we would remove //-- the last valid item in the list, which we don't want. only remove IF found. vIntIndex = llListFindList( gLstInventory, (list)llGetScriptName() ); if (~vIntIndex){ vLstInventory = llDeleteSubList( gLstInventory, vIntIndex, vIntIndex ); } }
default{ state_entry(){ gStrFolder = llGetObjectName(); fBuildInventory(); }
touch_start( integer vIntTouched ){ do{ --vIntTouched; if ([] == gLstInventory){ llInstantMessage( vIntTouched, "Nothing to give" ); }else{ llGiveInventoryList( llDetectedKey( vIntTouched ), gStrFolder, llList2List( llListRandomize( gLstInventory, 1 ), 0, 2 ) ); } }while (vIntTouched); }
changed( integer vBitChanged ){ if (CHANGED_INVENTORY & vBitChanged){ fBuildInventory(); } } }
I make no claims as to spelling, or missing semi colons
_____________________
| | . "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... | - 
|