Laufiair Hexicola Posted June 14, 2018 Share Posted June 14, 2018 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. Link to comment Share on other sites More sharing options...
Fionalein Posted June 14, 2018 Share Posted June 14, 2018 (edited) My approach would be as follows (quick sketch - my LSL-Fu is not strong enough for coding out of the blue): create list of items with some inventory function 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) process remaining items on list (with a delete loop) Edited June 14, 2018 by Fionalein Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 15, 2018 Share Posted June 15, 2018 (edited) 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 June 15, 2018 by Rolig Loon Link to comment Share on other sites More sharing options...
Laufiair Hexicola Posted June 15, 2018 Author Share Posted June 15, 2018 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 Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 15, 2018 Share Posted June 15, 2018 I've tested it in world now, and it works. All you have to do is complete it. 1 Link to comment Share on other sites More sharing options...
ellestones Posted June 15, 2018 Share Posted June 15, 2018 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); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now