Dr_Cox1911 Posted December 5, 2013 Share Posted December 5, 2013 Greetings, kinda lost right now Can´t figure out to programmatically select an amount of items within in the active inventory.Searched the class ItemContainer in the javadoc but found nothing useful there. Link to comment Share on other sites More sharing options...
RoboMat Posted December 6, 2013 Share Posted December 6, 2013 Loop through the inventory and store each item in a table and then sort the ones out you need? At least if I understood you correctly I think I did something similar in my unpack bags mod...Greetings from Thailand Link to comment Share on other sites More sharing options...
Dr_Cox1911 Posted December 6, 2013 Author Share Posted December 6, 2013 Actually I ment a selection like the user manually does with Shift+left mouse button. Link to comment Share on other sites More sharing options...
RoboMat Posted January 17, 2014 Share Posted January 17, 2014 Still not sure if I understand correctly, but if you want to access the items the player has selected you'll need to do something like this: ----- Creates a context menu entry when the player selects-- an inventory container (e.g. hiking bag).-- @param _player - The player who clicked the menu.-- @param _context - The context menu to add a new option to.-- @param _items - A table containing the clicked items / stack.--local function createMenu(_player, _context, _items) local itemTable = _items; -- The table containing the clicked items. local context = _context; local player = getSpecificPlayer(_player); -- We iterate through the table of clicked items. We have -- to seperate between single items, stacks and expanded -- stacks. for i1 = 1, #itemTable do local item = itemTable[i1]; if instanceof(item, "InventoryItem") and instanceof(item, "InventoryContainer") then doAwesomeStuff() elseif type(itemTable[i1]) == "table" then -- We start to iterate at the second index to jump over the dummy -- item that is contained in the item-table. for i2 = 2, #itemTable[i1].items do local item = itemTable[i1].items[i2]; if instanceof(item, "InventoryItem") and instanceof(item, "InventoryContainer") then doAwesomeStuff() end end end endend-- -------------------------------------------------- Game Hooks-- ------------------------------------------------Events.OnPreFillInventoryObjectContextMenu.Add(createMenu);It is a bit complicated, but this is every possible situation for the item selection (afaik):local function table() -- One item local clickedItems = { [1] = Inventory.Item; } -- Stack (folded) local clickedItems = { table = { [1] = DummyItem; [2] = Inventory.Item; [3] = Inventory.Item; [4] = Inventory.Item; [5] = "..." } } -- Stack (unfolded) local clickedItems = { [1] = DummyItem; [2] = Inventory.Item; [3] = Inventory.Item; [4] = Inventory.Item; [5] = "..."; } -- Multiple Stacks selected local clickedItems = { table1 = { [1] = DummyItem; [2] = Inventory.Item; [3] = Inventory.Item; [4] = Inventory.Item; [5] = "..." }, table2 = { [1] = DummyItem; [2] = Inventory.Item; [3] = Inventory.Item; [4] = Inventory.Item; [5] = "..." }, table3 = { "..." }, "..." }end Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now