Laufiair Hexicola

Random Item picker w/delete

Recommended Posts

Evening everyone, curious if it's possible to have a script pick X amount of items out of a set of items, remember them, then remove the rest of the items? If so, how would it be done? I'm not a scipter or I would've figured this out already. Was thinking of using the random item vendor as a base but not sure where to go after that.

Share this post


Link to post
Share on other sites

My approach would be as follows (quick sketch -  my LSL-Fu is not strong enough for coding out of the blue):

  1. create list of items with some inventory function
  2. pick random items from that list with removing (maybe add them to a second list depending on what you want to do in the future)
  3. process remaining items on list (with a delete loop)
Edited by Fionalein

Share this post


Link to post
Share on other sites

Off the top of my head and not optimized (but should work):

touch_start(integer num)
{
    lSelected = [];
    integer All_items = llGetInventoryNumber(INVENTORY_OBJECT);
    integer Choose_among = All_items / 2;   // Quite arbitrary, so that the selected number is smaller than the total
    integer i;
    while ( i < Choose_among)
    {
        @UpHere;
        integer New_number = (integer)llFrand(All_items);
        if (!~llListFindList(lSelected, [New_number]) )
        {
            lSelected += [New_number];
            ++i;
        }
        else
        {
            jump UpHere;
        }
    }
    llSay(0,"The selected items are objects " + llList2CSV(lSelected) );
    // then use the ListXnotY function to get a list of the "unselected" ones and do something with both lists
}

You'd need to define the global list lSelected and build the rest of a script to put this in. 

EDIT:  ListXnotY is at http://wiki.secondlife.com/wiki/ListXnotY          

Edited by Rolig Loon

Share this post


Link to post
Share on other sites
2 hours ago, Rolig Loon said:

Off the top of my head and not optimized (but should work):


touch_start(integer num)
{
    lSelected = [];
    integer All_items = llGetInventoryNumber(INVENTORY_OBJECT);
    integer Choose_among = All_items / 2;   // Quite arbitrary, so that the selected number is smaller than the total
    integer i;
    while ( i < Choose_among)
    {
        @UpHere;
        integer New_number = (integer)llFrand(All_items);
        if (!~llListFindList(lSelected, [New_number]) )
        {
            lSelected += [New_number];
            ++i;
        }
        else
        {
            jump UpHere;
        }
    }
    llSay(0,"The selected items are objects " + llList2CSV(lSelected) );
    // then use the ListXnotY function to get a list of the "unselected" ones and do something with both lists
}

You'd need to define the global list lSelected and build the rest of a script to put this in. 

EDIT:  ListXnotY is at http://wiki.secondlife.com/wiki/ListXnotY          

That is a start, because all it has to do is randomly select an amount of items, then remove the unselected items plus the script itself

Share this post


Link to post
Share on other sites

another way can be to shuffle

list all;

integer n = llGetInventoryNumber(INVENTORY_OBJECT);
integer i;
for (i = 0; i < n; i++)
{
    all += [i];
}

all = llListRandomize(all, 1);

// get 'some'
integer c = n / 2;  // or some other c < n;
list some = llDeleteSubList(all, c, n-1);

// the remainder of 'all' - 'some' is
list remainder = llDeleteSubList(all, 0, c-1);

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now